Skip to content

Commit

Permalink
Consistency with quotation marks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezod committed Oct 27, 2010
1 parent 9a681bb commit 34793e0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
11 changes: 5 additions & 6 deletions fuzz/fgraph.py
Expand Up @@ -57,14 +57,14 @@ def add_edge(self, edge, mu=1.0):
edge = FuzzyElement(edge, mu)
try:
if not isinstance(edge.index, GraphEdge):
raise TypeError("edge must be a GraphEdge")
raise TypeError('edge must be a GraphEdge')
except AttributeError:
Graph.add_edge(self, edge)
if not edge.index.tail in self.vertices() \
or not edge.index.head in self.vertices():
raise KeyError("tail and head must be in vertex set")
raise KeyError('tail and head must be in vertex set')
if edge.index in self.edges():
raise ValueError("edge already exists")
raise ValueError('edge already exists')
self._E.add(edge)

def vertices(self):
Expand All @@ -89,7 +89,7 @@ def edges(self, tail=None, head=None):
"""
if (tail is not None and not tail in self.vertices()) \
or (head is not None and not head in self.vertices()):
raise KeyError("specified tail/head must be in vertex set")
raise KeyError('specified tail/head must be in vertex set')
eset = set([edge.index for edge in self._E \
if (tail is None or edge.index.tail == tail) \
and (head is None or edge.index.head == head)])
Expand Down Expand Up @@ -162,8 +162,7 @@ def _binary_sanity_check(other):
@type other: L{FuzzyGraph}
"""
if not isinstance(other, FuzzyGraph):
raise TypeError("binary operation only permitted between fuzzy \
graphs")
raise TypeError('operation only permitted between fuzzy graphs')

# Unary fuzzy graph operations

Expand Down
44 changes: 21 additions & 23 deletions fuzz/fnumber.py
Expand Up @@ -23,12 +23,12 @@ def __new__(cls, arg=(0.0, 0.0)):
before returning the range object.
"""
if not len(arg) == 2:
raise ValueError("range must consist of two values")
raise ValueError('range must consist of two values')
if not isinstance(arg[0], Number) \
or not isinstance(arg[1], Number):
raise TypeError("range values must be numeric")
raise TypeError('range values must be numeric')
if arg[0] > arg[1]:
raise ValueError("range may not have negative size")
raise ValueError('range may not have negative size')
return tuple.__new__(cls, arg)

@property
Expand Down Expand Up @@ -83,7 +83,7 @@ def issubset(self, other):
@rtype: C{bool}
"""
if not isinstance(other, RealRange):
raise TypeError("argument must be a RealRange")
raise TypeError('argument must be a RealRange')
if other[0] <= self[0] and other[1] >= self[1]:
return True
return False
Expand All @@ -98,7 +98,7 @@ def issuperset(self, other):
@rtype: C{bool}
"""
if not isinstance(other, RealRange):
raise TypeError("argument must be a RealRange")
raise TypeError('argument must be a RealRange')
if self[0] <= other[0] and self[1] >= other[1]:
return True
return False
Expand Down Expand Up @@ -138,7 +138,7 @@ def __init__(self):
Constructor. Not to be instantiated directly.
"""
if self.__class__ is FuzzyNumber:
raise NotImplementedError("please use one of the subclasses")
raise NotImplementedError('please use one of the subclasses')

def __repr__(self):
"""\
Expand Down Expand Up @@ -167,14 +167,14 @@ def mu(self, value):
@param value: A value in the universal set.
@type value: C{float}
"""
raise NotImplementedError("mu method must be overridden")
raise NotImplementedError('mu method must be overridden')

def normalize(self):
"""\
Normalize this fuzzy number, so that its height is equal to 1.0.
"""
if not self.height == 1.0:
raise NotImplementedError("normalize method must be overridden")
raise NotImplementedError('normalize method must be overridden')

kernel = None
support = None
Expand All @@ -193,10 +193,10 @@ def __init__(self, points):
@type points: C{list} of C{tuple}
"""
if not points[0][1] == 0.0 or not points[-1][1] == 0.0:
raise ValueError("points must start and end with mu = 0")
raise ValueError('points must start and end with mu = 0')
for i in range(1, len(points)):
if not points[i][0] >= points[i - 1][0]:
raise ValueError("points must be in increasing order")
raise ValueError('points must be in increasing order')
self.points = points
FuzzyNumber.__init__(self)

Expand All @@ -210,8 +210,8 @@ def _binary_sanity_check(other):
@type other: L{PolygonalFuzzyNumber}
"""
if not isinstance(other, PolygonalFuzzyNumber):
raise TypeError("binary operation only permitted between \
polygonal fuzzy numbers")
raise TypeError('operation only permitted between polygonal '
'fuzzy numbers')

def mu(self, value):
"""\
Expand Down Expand Up @@ -456,11 +456,11 @@ def __init__(self, kernel=(0.0, 0.0), support=(0.0, 0.0)):
"""
if not (isinstance(kernel, tuple) and len(kernel) == 2) \
or not (isinstance(support, tuple) and len(support) == 2):
raise TypeError("kernel and support must be 2-tuples")
raise TypeError('kernel and support must be 2-tuples')
self.kernel = RealRange(kernel)
self.support = RealRange(support)
if not self.kernel <= self.support:
raise ValueError("kernel range must be within support range")
raise ValueError('kernel range must be within support range')
self.height = 1.0
FuzzyNumber.__init__(self)

Expand All @@ -483,8 +483,8 @@ def _binary_sanity_check(other):
@type other: L{TrapezoidalFuzzyNumber}
"""
if not isinstance(other, TrapezoidalFuzzyNumber):
raise TypeError("binary operation only permitted between \
trapezoidal fuzzy numbers")
raise TypeError('operation only permitted between trapezoidal '
'fuzzy numbers')

def __add__(self, other):
"""\
Expand Down Expand Up @@ -572,9 +572,7 @@ def __init__(self, kernel=0.0, support=(0.0, 0.0)):
@param support: The support of the fuzzy number.
@type support: C{tuple}
"""
super(TriangularFuzzyNumber, self).__init__(
(kernel, kernel), support
)
super(TriangularFuzzyNumber, self).__init__((kernel, kernel), support)


class GaussianFuzzyNumber(FuzzyNumber):
Expand Down Expand Up @@ -605,8 +603,8 @@ def _binary_sanity_check(other):
@type other: L{GaussianFuzzyNumber}
"""
if not isinstance(other, GaussianFuzzyNumber):
raise TypeError("binary operation only permitted between \
gaussian fuzzy numbers")
raise TypeError('operation only permitted between Gaussian '
'fuzzy numbers')

def __add__(self, other):
"""\
Expand All @@ -623,7 +621,7 @@ def __add__(self, other):

def __sub__(self, other):
"""\
Substraction Operation
Subtraction operation.
@param other: The other gaussian fuzzy number.
@type other: L{GaussianFuzzyNumber}
Expand Down Expand Up @@ -691,7 +689,7 @@ def to_polygonal(self, np):
@rtype: L{PolygonalFuzzyNumber}
"""
if np < 0:
raise ValueError("number of points must be positive")
raise ValueError('number of points must be positive')
points = []
start, end = self.support
increment = (self.mean - start) / float(np + 1)
Expand Down
13 changes: 6 additions & 7 deletions fuzz/fset.py
Expand Up @@ -138,8 +138,8 @@ def __str__(self):
@return: String representation.
@rtype: C{str}
"""
return ("%s([" % self.__class__.__name__) \
+ ', '.join([str(element) for element in self]) + "])"
return ('%s([' % self.__class__.__name__) \
+ ', '.join([str(element) for element in self]) + '])'

def add(self, element, mu=1.0):
"""\
Expand Down Expand Up @@ -260,7 +260,7 @@ def union(self, other, norm=0):
@rtype: L{FuzzySet}
"""
if not norm in range(4):
raise ValueError("invalid t-conorm type")
raise ValueError('invalid t-conorm type')
self._binary_sanity_check(other)
result = self.__class__()
bothkeys = set(self.keys()) | set(other.keys())
Expand Down Expand Up @@ -337,7 +337,7 @@ def intersection(self, other, norm=0):
@rtype: L{FuzzySet}
"""
if not norm in range(4):
raise ValueError("invalid t-norm type")
raise ValueError('invalid t-norm type')
self._binary_sanity_check(other)
result = self.__class__()
[lambda: result.update([FuzzyElement(key, min(self.mu(key), \
Expand Down Expand Up @@ -489,8 +489,7 @@ def _binary_sanity_check(other):
@type other: L{FuzzySet}
"""
if not isinstance(other, FuzzySet):
raise TypeError("binary operation only permitted between fuzzy \
sets")
raise TypeError('operation only permitted between fuzzy sets')

# Unary fuzzy set operations

Expand All @@ -504,7 +503,7 @@ def complement(self, comp=0, **kwargs):
@rtype: L{FuzzySet}
"""
if not comp in range(2):
raise ValueError("invalid complement type")
raise ValueError('invalid complement type')
result = self.__class__()
[lambda: result.update([FuzzyElement(key, 1 - self.mu(key)) \
for key in self.keys()]),
Expand Down
18 changes: 9 additions & 9 deletions fuzz/graph.py
Expand Up @@ -18,10 +18,10 @@ def __new__(cls, arg):
argument before returning the graph edge object.
"""
if not len(arg) == 2:
raise ValueError("edge must consist of two vertex objects")
raise ValueError('edge must consist of two vertex objects')
if not hasattr(type(arg[0]), '__hash__') \
or not hasattr(type(arg[1]), '__hash__'):
raise ValueError("vertices must be immutable")
raise ValueError('vertices must be immutable')
return tuple.__new__(cls, arg)

@property
Expand Down Expand Up @@ -133,7 +133,7 @@ def add_vertex(self, vertex):
try:
hash(vertex)
except TypeError:
raise TypeError("vertex must be a hashable object")
raise TypeError('vertex must be a hashable object')
self._V.add(vertex)

def remove_vertex(self, vertex):
Expand All @@ -158,11 +158,11 @@ def add_edge(self, edge):
@type edge: L{GraphEdge}
"""
if not isinstance(edge, GraphEdge):
raise TypeError("edge must be a GraphEdge")
raise TypeError('edge must be a GraphEdge')
if not edge.tail in self.vertices() or not edge.head in self.vertices():
raise KeyError("tail and head must be in vertex set")
raise KeyError('tail and head must be in vertex set')
if edge in self.edges():
raise ValueError("edge already exists")
raise ValueError('edge already exists')
self._E.add(edge)

def remove_edge(self, tail, head):
Expand Down Expand Up @@ -198,7 +198,7 @@ def edges(self, tail=None, head=None):
"""
if (tail is not None and not tail in self.vertices()) \
or (head is not None and not head in self.vertices()):
raise KeyError("specified tail/head must be in vertex set")
raise KeyError('specified tail/head must be in vertex set')
eset = set([edge for edge in self._E \
if (tail is None or edge.tail == tail) \
and (head is None or edge.head == head)])
Expand Down Expand Up @@ -355,7 +355,7 @@ def _binary_sanity_check(other):
@type other: L{Graph}
"""
if not isinstance(other, Graph):
raise TypeError("binary operation only permitted between graphs")
raise TypeError('operation only permitted between graphs')

# Connectivity-related functions

Expand Down Expand Up @@ -499,7 +499,7 @@ def minimum_spanning_tree(self):
@rtype: L{Graph}
"""
if self.directed:
raise TypeError("Kruskal's algorithm is for undirected graphs only")
raise TypeError('Kruskal\'s algorithm is for undirected graphs only')
# create a list of edges sorted by weight
Q = self.edges_by_weight()
# initialize the minimum spanning tree
Expand Down
4 changes: 2 additions & 2 deletions fuzz/iset.py
Expand Up @@ -27,7 +27,7 @@ def __init__(self, index):
"""
if not hasattr(type(index), '__hash__') \
or not hasattr(type(index), '__eq__'):
raise TypeError("index object must be immutable")
raise TypeError('index object must be immutable')
self._index = index

@property
Expand Down Expand Up @@ -129,7 +129,7 @@ def __setitem__(self, key, item):
@type item: C{object}
"""
if not item.index == key:
raise ValueError("key does not match item index attribute")
raise ValueError('key does not match item index attribute')
if key in self:
self.remove(key)
set.add(self, item)
Expand Down

0 comments on commit 34793e0

Please sign in to comment.