[Python-checkins] CVS: python/nondist/sandbox/sets set.py,1.1,1.2 test_set.py,1.1,1.2
Greg Wilson
gvwilson@users.sourceforge.net
Fri, 25 May 2001 08:54:28 -0700
Update of /cvsroot/python/python/nondist/sandbox/sets
In directory usw-pr-cvs1:/tmp/cvs-serv3005
Modified Files:
set.py test_set.py
Log Message:
Changed names of methods and sets to reflect preference for underscore
separated rather than camel back.
Index: set.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/sets/set.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** set.py 2001/05/22 16:55:12 1.1
--- set.py 2001/05/25 15:54:25 1.2
***************
*** 21,28 ****
#----------------------------------------
! def __init__(self, seq=None, sortRepr=0):
"""Construct a set, optionally initializing it with elements
! drawn from a sequence. If 'sortRepr' is true, the set's
elements are displayed in sorted order. This slows down
conversion, but simplifies comparison during testing. The
--- 21,28 ----
#----------------------------------------
! def __init__(self, seq=None, sort_repr=0):
"""Construct a set, optionally initializing it with elements
! drawn from a sequence. If 'sort_repr' is true, the set's
elements are displayed in sorted order. This slows down
conversion, but simplifies comparison during testing. The
***************
*** 32,36 ****
self.elements = {}
! self.sortRepr = sortRepr
if seq is not None:
for x in seq:
--- 32,36 ----
self.elements = {}
! self.sort_repr = sort_repr
if seq is not None:
for x in seq:
***************
*** 42,46 ****
"""Convert set to string."""
content = self.elements.keys()
! if self.sortRepr:
content.sort()
return 'Set(' + `content` + ')'
--- 42,46 ----
"""Convert set to string."""
content = self.elements.keys()
! if self.sort_repr:
content.sort()
return 'Set(' + `content` + ')'
***************
*** 95,99 ****
#----------------------------------------
! def isFrozen(self):
"""Report whether set is frozen or not. A frozen set is one
--- 95,99 ----
#----------------------------------------
! def is_frozen(self):
"""Report whether set is frozen or not. A frozen set is one
***************
*** 129,137 ****
#----------------------------------------
! def unionUpdate(self, other):
"""Update set with union of its own elements and the elements
in another set."""
! self._binaryOpSanityCheck(other, "updating union")
self.elements.update(other.elements)
return self
--- 129,137 ----
#----------------------------------------
! def union_update(self, other):
"""Update set with union of its own elements and the elements
in another set."""
! self._binary_sanity_check(other, "updating union")
self.elements.update(other.elements)
return self
***************
*** 142,156 ****
and another's."""
! self._binaryOpSanityCheck(other)
result = self.__copy__()
! result.unionUpdate(other)
return result
#----------------------------------------
! def intersectUpdate(self, other):
"""Update set with intersection of its own elements and the
elements in another set."""
! self._binaryOpSanityCheck(other, "updating intersection")
new_elements = {}
for elt in self.elements:
--- 142,156 ----
and another's."""
! self._binary_sanity_check(other)
result = self.__copy__()
! result.union_update(other)
return result
#----------------------------------------
! def intersect_update(self, other):
"""Update set with intersection of its own elements and the
elements in another set."""
! self._binary_sanity_check(other, "updating intersection")
new_elements = {}
for elt in self.elements:
***************
*** 165,169 ****
set's and another's."""
! self._binaryOpSanityCheck(other)
if len(self) <= len(other):
little, big = self, other
--- 165,169 ----
set's and another's."""
! self._binary_sanity_check(other)
if len(self) <= len(other):
little, big = self, other
***************
*** 177,181 ****
#----------------------------------------
! def symDifferenceUpdate(self, other):
"""Update set with symmetric difference of its own elements
and the elements in another set. A value 'x' is in the result
--- 177,181 ----
#----------------------------------------
! def sym_difference_update(self, other):
"""Update set with symmetric difference of its own elements
and the elements in another set. A value 'x' is in the result
***************
*** 183,192 ****
in both."""
! self._binaryOpSanityCheck(other, "updating symmetric difference")
! self.elements = self._rawSymDifference(self.elements, other.elements)
return self
#----------------------------------------
! def symDifference(self, other):
"""Create new set with symmetric difference of this set's own
elements and the elements in another set. A value 'x' is in
--- 183,192 ----
in both."""
! self._binary_sanity_check(other, "updating symmetric difference")
! self.elements = self._raw_sym_difference(self.elements, other.elements)
return self
#----------------------------------------
! def sym_difference(self, other):
"""Create new set with symmetric difference of this set's own
elements and the elements in another set. A value 'x' is in
***************
*** 194,207 ****
set, but not in both."""
! self._binaryOpSanityCheck(other)
result = Set()
! result.elements = self._rawSymDifference(self.elements, other.elements)
return result
#----------------------------------------
! def differenceUpdate(self, other):
"""Remove all elements of another set from this set."""
! self._binaryOpSanityCheck(other, "updating difference")
new_elements = {}
for elt in self.elements:
--- 194,207 ----
set, but not in both."""
! self._binary_sanity_check(other)
result = Set()
! result.elements = self._raw_sym_difference(self.elements, other.elements)
return result
#----------------------------------------
! def difference_update(self, other):
"""Remove all elements of another set from this set."""
! self._binary_sanity_check(other, "updating difference")
new_elements = {}
for elt in self.elements:
***************
*** 216,220 ****
present in another set."""
! self._binaryOpSanityCheck(other)
result = Set()
for elt in self.elements:
--- 216,220 ----
present in another set."""
! self._binary_sanity_check(other)
result = Set()
for elt in self.elements:
***************
*** 224,227 ****
--- 224,242 ----
#----------------------------------------
+ # Arithmetic forms of operations
+ __or__ = union
+ __ror__ = union
+ __ior__ = union_update
+ __and__ = intersect
+ __rand__ = intersect
+ __iand__ = intersect_update
+ __xor__ = sym_difference
+ __rxor__ = sym_difference
+ __ixor__ = sym_difference_update
+ __sub__ = difference
+ __rsub__ = difference
+ __isub__ = difference_update
+
+ #----------------------------------------
def add(self, item):
"""Add an item to a set. This has no effect if the item is
***************
*** 277,281 ****
#----------------------------------------
! def isSubsetOf(self, other):
"""Reports whether other set contains this set."""
if not isinstance(other, Set):
--- 292,296 ----
#----------------------------------------
! def is_subset_of(self, other):
"""Reports whether other set contains this set."""
if not isinstance(other, Set):
***************
*** 287,291 ****
#----------------------------------------
! def containsAllOf(self, other):
"""Report whether other subset is subset of this set."""
if not isinstance(other, Set):
--- 302,306 ----
#----------------------------------------
! def contains_all_of(self, other):
"""Report whether other subset is subset of this set."""
if not isinstance(other, Set):
***************
*** 297,319 ****
#----------------------------------------
- # Arithmetic forms of operations
- __or__ = union
- __ror__ = union
- __ior__ = unionUpdate
- __and__ = intersect
- __rand__ = intersect
- __iand__ = intersectUpdate
- __xor__ = symDifference
- __rxor__ = symDifference
- __ixor__ = symDifferenceUpdate
- __sub__ = difference
- __rsub__ = difference
- __isub__ = differenceUpdate
-
- #----------------------------------------
# Check that the other argument to a binary operation is also a
# set, and that this set is still mutable (if appropriate),
# raising a ValueError if either condition is not met.
! def _binaryOpSanityCheck(self, other, updating_op=''):
if updating_op and (self.hashcode is not None):
raise ValueError, Set._Frozen_Msg % updating_op
--- 312,319 ----
#----------------------------------------
# Check that the other argument to a binary operation is also a
# set, and that this set is still mutable (if appropriate),
# raising a ValueError if either condition is not met.
! def _binary_sanity_check(self, other, updating_op=''):
if updating_op and (self.hashcode is not None):
raise ValueError, Set._Frozen_Msg % updating_op
***************
*** 324,328 ****
# Calculate the symmetric difference between the keys in two
# dictionaries with don't-care values.
! def _rawSymDifference(self, left, right):
result = {}
for elt in left:
--- 324,328 ----
# Calculate the symmetric difference between the keys in two
# dictionaries with don't-care values.
! def _raw_sym_difference(self, left, right):
result = {}
for elt in left:
***************
*** 345,362 ****
# Unit set
! green = Set((0,))
assert `green` == "Set([0])", "Unit set: %s" % `green`
# 3-element set
! blue = Set([0, 1, 2])
! assert `blue` == "Set([2, 1, 0])", "3-element set: %s" % `blue`
# 2-element set with other values
! black = Set([0, 5])
! assert `black` == "Set([5, 0])", "2-element set: %s" % `black`
# All elements from all sets
! white = Set([0, 1, 2, 5])
! assert `white` == "Set([5, 2, 1, 0])", "4-element set: %s" % `white`
# Add element to empty set
--- 345,362 ----
# Unit set
! green = Set((0,), 1)
assert `green` == "Set([0])", "Unit set: %s" % `green`
# 3-element set
! blue = Set([0, 1, 2], 1)
! assert `blue` == "Set([0, 1, 2])", "3-element set: %s" % `blue`
# 2-element set with other values
! black = Set([0, 5], 1)
! assert `black` == "Set([0, 5])", "2-element set: %s" % `black`
# All elements from all sets
! white = Set([0, 1, 2, 5], 1)
! assert `white` == "Set([0, 1, 2, 5])", "4-element set: %s" % `white`
# Add element to empty set
***************
*** 372,376 ****
red.remove(0)
assert 0, "Remove element from empty set: %s" % `red`
! except KeyError:
pass
--- 372,376 ----
red.remove(0)
assert 0, "Remove element from empty set: %s" % `red`
! except LookupError:
pass
Index: test_set.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/sets/test_set.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** test_set.py 2001/05/22 16:55:12 1.1
--- test_set.py 2001/05/25 15:54:25 1.2
***************
*** 4,8 ****
import unittest, operator, copy
! EmptySet = Set()
#===============================================================================
--- 4,8 ----
import unittest, operator, copy
! empty_set = Set()
#===============================================================================
***************
*** 10,74 ****
class TestBasicOps(unittest.TestCase):
! def checkRepr(self):
if self.repr is not None:
assert `self.set` == self.repr, "Wrong representation for " + self.case
! def checkLength(self):
assert len(self.set) == self.length, "Wrong length for " + self.case
! def checkSelfEquality(self):
assert self.set == self.set, "Self-equality failed for " + self.case
! def checkEquivalentEquality(self):
assert self.set == self.dup, "Equivalent equality failed for " + self.case
! def checkCopy(self):
assert self.set.copy() == self.dup, "Copy and comparison failed for " + self.case
! def checkSelfUnion(self):
result = self.set | self.set
assert result == self.dup, "Self-union failed for " + self.case
! def checkEmptyUnion(self):
! result = self.set | EmptySet
assert result == self.dup, "Union with empty failed for " + self.case
! def checkUnionEmpty(self):
! result = EmptySet | self.set
assert result == self.dup, "Union with empty failed for " + self.case
! def checkSelfIntersection(self):
result = self.set & self.set
assert result == self.dup, "Self-intersection failed for " + self.case
! def checkEmptyIntersection(self):
! result = self.set & EmptySet
! assert result == EmptySet, "Intersection with empty failed for " + self.case
!
! def checkIntersectionEmpty(self):
! result = EmptySet & self.set
! assert result == EmptySet, "Intersection with empty failed for " + self.case
! def checkSelfSymmetricDifference(self):
result = self.set ^ self.set
! assert result == EmptySet, "Self-symdiff failed for " + self.case
! def checkEmptySymmetricDifference(self):
! result = self.set ^ EmptySet
assert result == self.set, "Symdiff with empty failed for " + self.case
! def checkSelfDifference(self):
result = self.set - self.set
! assert result == EmptySet, "Self-difference failed for " + self.case
! def checkEmptyDifference(self):
! result = self.set - EmptySet
assert result == self.dup, "Difference with empty failed for " + self.case
! def checkEmptyDifferenceRev(self):
! result = EmptySet - self.set
! assert result == EmptySet, "Difference from empty failed for " + self.case
! def checkIteration(self):
for v in self.set:
assert v in self.values, "Missing item in iteration for " + self.case
--- 10,74 ----
class TestBasicOps(unittest.TestCase):
! def test_repr(self):
if self.repr is not None:
assert `self.set` == self.repr, "Wrong representation for " + self.case
! def test_length(self):
assert len(self.set) == self.length, "Wrong length for " + self.case
! def test_self_equality(self):
assert self.set == self.set, "Self-equality failed for " + self.case
! def test_equivalent_equality(self):
assert self.set == self.dup, "Equivalent equality failed for " + self.case
! def test_copy(self):
assert self.set.copy() == self.dup, "Copy and comparison failed for " + self.case
! def test_self_union(self):
result = self.set | self.set
assert result == self.dup, "Self-union failed for " + self.case
! def test_empty_union(self):
! result = self.set | empty_set
assert result == self.dup, "Union with empty failed for " + self.case
! def test_union_empty(self):
! result = empty_set | self.set
assert result == self.dup, "Union with empty failed for " + self.case
! def test_self_intersection(self):
result = self.set & self.set
assert result == self.dup, "Self-intersection failed for " + self.case
! def test_empty_intersection(self):
! result = self.set & empty_set
! assert result == empty_set, "Intersection with empty failed for " + self.case
!
! def test_intersection_empty(self):
! result = empty_set & self.set
! assert result == empty_set, "Intersection with empty failed for " + self.case
! def test_self_symmetric_difference(self):
result = self.set ^ self.set
! assert result == empty_set, "Self-symdiff failed for " + self.case
! def checkempty_symmetric_difference(self):
! result = self.set ^ empty_set
assert result == self.set, "Symdiff with empty failed for " + self.case
! def test_self_difference(self):
result = self.set - self.set
! assert result == empty_set, "Self-difference failed for " + self.case
! def test_empty_difference(self):
! result = self.set - empty_set
assert result == self.dup, "Difference with empty failed for " + self.case
! def test_empty_difference_rev(self):
! result = empty_set - self.set
! assert result == empty_set, "Difference from empty failed for " + self.case
! def test_iteration(self):
for v in self.set:
assert v in self.values, "Missing item in iteration for " + self.case
***************
*** 96,103 ****
self.repr = "Set([3])"
! def checkIn(self):
assert 3 in self.set, "Valueship for unit set"
! def checkNotIn(self):
assert 2 not in self.set, "Non-valueship for unit set"
--- 96,103 ----
self.repr = "Set([3])"
! def test_in(self):
assert 3 in self.set, "Valueship for unit set"
! def test_not_in(self):
assert 2 not in self.set, "Non-valueship for unit set"
***************
*** 113,120 ****
self.repr = "Set([(0, 'zero')])"
! def checkIn(self):
assert (0, "zero") in self.set, "Valueship for tuple set"
! def checkNotIn(self):
assert 9 not in self.set, "Non-valueship for tuple set"
--- 113,120 ----
self.repr = "Set([(0, 'zero')])"
! def test_in(self):
assert (0, "zero") in self.set, "Valueship for tuple set"
! def test_not_in(self):
assert 9 not in self.set, "Non-valueship for tuple set"
***************
*** 136,184 ****
self.set = Set((2, 4, 6))
! def checkUnionSubset(self):
result = self.set | Set([2])
assert result == Set((2, 4, 6)), "Subset union"
! def checkUnionSuperset(self):
result = self.set | Set([2, 4, 6, 8])
assert result == Set([2, 4, 6, 8]), "Superset union"
! def checkUnionOverlap(self):
result = self.set | Set([3, 4, 5])
assert result == Set([2, 3, 4, 5, 6]), "Overlapping union"
! def checkUnionNonOverlap(self):
result = self.set | Set([8])
assert result == Set([2, 4, 6, 8]), "Non-overlapping union"
! def checkIntersectionSubset(self):
result = self.set & Set((2, 4))
assert result == Set((2, 4)), "Subset intersection"
! def checkIntersectionSuperset(self):
result = self.set & Set([2, 4, 6, 8])
assert result == Set([2, 4, 6]), "Superset intersection"
! def checkIntersectionOverlap(self):
result = self.set & Set([3, 4, 5])
assert result == Set([4]), "Overlapping intersection"
! def checkIntersectionNonOverlap(self):
result = self.set & Set([8])
! assert result == EmptySet, "Non-overlapping intersection"
! def checkSymDifferenceSubset(self):
result = self.set ^ Set((2, 4))
assert result == Set([6]), "Subset symmetric difference"
! def checkSymDifferenceSuperset(self):
result = self.set ^ Set((2, 4, 6, 8))
assert result == Set([8]), "Superset symmetric difference"
! def checkSymDifferenceOverlap(self):
result = self.set ^ Set((3, 4, 5))
assert result == Set([2, 3, 5, 6]), "Overlapping symmetric difference"
! def checkSymDifferenceNonOverlap(self):
result = self.set ^ Set([8])
assert result == Set([2, 4, 6, 8]), "Non-overlapping symmetric difference"
--- 136,184 ----
self.set = Set((2, 4, 6))
! def test_union_subset(self):
result = self.set | Set([2])
assert result == Set((2, 4, 6)), "Subset union"
! def test_union_superset(self):
result = self.set | Set([2, 4, 6, 8])
assert result == Set([2, 4, 6, 8]), "Superset union"
! def test_union_overlap(self):
result = self.set | Set([3, 4, 5])
assert result == Set([2, 3, 4, 5, 6]), "Overlapping union"
! def test_union_non_overlap(self):
result = self.set | Set([8])
assert result == Set([2, 4, 6, 8]), "Non-overlapping union"
! def test_intersection_subset(self):
result = self.set & Set((2, 4))
assert result == Set((2, 4)), "Subset intersection"
! def test_intersection_superset(self):
result = self.set & Set([2, 4, 6, 8])
assert result == Set([2, 4, 6]), "Superset intersection"
! def test_intersection_overlap(self):
result = self.set & Set([3, 4, 5])
assert result == Set([4]), "Overlapping intersection"
! def test_intersection_non_overlap(self):
result = self.set & Set([8])
! assert result == empty_set, "Non-overlapping intersection"
! def test_sym_difference_subset(self):
result = self.set ^ Set((2, 4))
assert result == Set([6]), "Subset symmetric difference"
! def test_sym_difference_superset(self):
result = self.set ^ Set((2, 4, 6, 8))
assert result == Set([8]), "Superset symmetric difference"
! def test_sym_difference_overlap(self):
result = self.set ^ Set((3, 4, 5))
assert result == Set([2, 3, 5, 6]), "Overlapping symmetric difference"
! def test_sym_difference_non_overlap(self):
result = self.set ^ Set([8])
assert result == Set([2, 4, 6, 8]), "Non-overlapping symmetric difference"
***************
*** 190,238 ****
self.set = Set((2, 4, 6))
! def checkUnionSubset(self):
self.set |= Set([2])
assert self.set == Set((2, 4, 6)), "Subset union"
! def checkUnionSuperset(self):
self.set |= Set([2, 4, 6, 8])
assert self.set == Set([2, 4, 6, 8]), "Superset union"
! def checkUnionOverlap(self):
self.set |= Set([3, 4, 5])
assert self.set == Set([2, 3, 4, 5, 6]), "Overlapping union"
! def checkUnionNonOverlap(self):
self.set |= Set([8])
assert self.set == Set([2, 4, 6, 8]), "Non-overlapping union"
! def checkIntersectionSubset(self):
self.set &= Set((2, 4))
assert self.set == Set((2, 4)), "Subset intersection"
! def checkIntersectionSuperset(self):
self.set &= Set([2, 4, 6, 8])
assert self.set == Set([2, 4, 6]), "Superset intersection"
! def checkIntersectionOverlap(self):
self.set &= Set([3, 4, 5])
assert self.set == Set([4]), "Overlapping intersection"
! def checkIntersectionNonOverlap(self):
self.set &= Set([8])
! assert self.set == EmptySet, "Non-overlapping intersection"
! def checkSymDifferenceSubset(self):
self.set ^= Set((2, 4))
assert self.set == Set([6]), "Subset symmetric difference"
! def checkSymDifferenceSuperset(self):
self.set ^= Set((2, 4, 6, 8))
assert self.set == Set([8]), "Superset symmetric difference"
! def checkSymDifferenceOverlap(self):
self.set ^= Set((3, 4, 5))
assert self.set == Set([2, 3, 5, 6]), "Overlapping symmetric difference"
! def checkSymDifferenceNonOverlap(self):
self.set ^= Set([8])
assert self.set == Set([2, 4, 6, 8]), "Non-overlapping symmetric difference"
--- 190,238 ----
self.set = Set((2, 4, 6))
! def test_union_subset(self):
self.set |= Set([2])
assert self.set == Set((2, 4, 6)), "Subset union"
! def test_union_superset(self):
self.set |= Set([2, 4, 6, 8])
assert self.set == Set([2, 4, 6, 8]), "Superset union"
! def test_union_overlap(self):
self.set |= Set([3, 4, 5])
assert self.set == Set([2, 3, 4, 5, 6]), "Overlapping union"
! def test_union_non_overlap(self):
self.set |= Set([8])
assert self.set == Set([2, 4, 6, 8]), "Non-overlapping union"
! def test_intersection_subset(self):
self.set &= Set((2, 4))
assert self.set == Set((2, 4)), "Subset intersection"
! def test_intersection_superset(self):
self.set &= Set([2, 4, 6, 8])
assert self.set == Set([2, 4, 6]), "Superset intersection"
! def test_intersection_overlap(self):
self.set &= Set([3, 4, 5])
assert self.set == Set([4]), "Overlapping intersection"
! def test_intersection_non_overlap(self):
self.set &= Set([8])
! assert self.set == empty_set, "Non-overlapping intersection"
! def test_sym_difference_subset(self):
self.set ^= Set((2, 4))
assert self.set == Set([6]), "Subset symmetric difference"
! def test_sym_difference_superset(self):
self.set ^= Set((2, 4, 6, 8))
assert self.set == Set([8]), "Superset symmetric difference"
! def test_sym_difference_overlap(self):
self.set ^= Set((3, 4, 5))
assert self.set == Set([2, 3, 5, 6]), "Overlapping symmetric difference"
! def test_sym_difference_non_overlap(self):
self.set ^= Set([8])
assert self.set == Set([2, 4, 6, 8]), "Non-overlapping symmetric difference"
***************
*** 245,270 ****
self.set = Set(self.values)
! def checkAddPresent(self):
self.set.add("c")
assert self.set == Set(("a", "b", "c")), "Adding present element"
! def checkAddAbsent(self):
self.set.add("d")
assert self.set == Set(("a", "b", "c", "d")), "Adding missing element"
! def checkAddUntilFull(self):
tmp = Set()
! expectedLen = 0
for v in self.values:
tmp.add(v)
! expectedLen += 1
! assert len(tmp) == expectedLen, "Adding values one by one to temporary"
assert tmp == self.set, "Adding values one by one"
! def checkRemovePresent(self):
self.set.remove("b")
assert self.set == Set(("a", "c")), "Removing present element"
! def checkRemoveAbsent(self):
try:
self.set.remove("d")
--- 245,270 ----
self.set = Set(self.values)
! def test_add_present(self):
self.set.add("c")
assert self.set == Set(("a", "b", "c")), "Adding present element"
! def test_add_absent(self):
self.set.add("d")
assert self.set == Set(("a", "b", "c", "d")), "Adding missing element"
! def test_add_until_full(self):
tmp = Set()
! expected_len = 0
for v in self.values:
tmp.add(v)
! expected_len += 1
! assert len(tmp) == expected_len, "Adding values one by one to temporary"
assert tmp == self.set, "Adding values one by one"
! def test_remove_present(self):
self.set.remove("b")
assert self.set == Set(("a", "c")), "Removing present element"
! def test_remove_absent(self):
try:
self.set.remove("d")
***************
*** 273,296 ****
pass
! def checkRemoveUntilEmpty(self):
! expectedLen = len(self.set)
for v in self.values:
self.set.remove(v)
! expectedLen -= 1
! assert len(self.set) == expectedLen, "Removing values one by one"
! def checkDiscardPresent(self):
self.set.discard("c")
assert self.set == Set(("a", "b")), "Discarding present element"
! def checkDiscardAbsent(self):
self.set.discard("d")
assert self.set == Set(("a", "b", "c")), "Discarding missing element"
! def checkClear(self):
self.set.clear()
assert len(self.set) == 0, "Clearing set"
! def checkPopitem(self):
popped = {}
while self.set:
--- 273,296 ----
pass
! def test_remove_until_empty(self):
! expected_len = len(self.set)
for v in self.values:
self.set.remove(v)
! expected_len -= 1
! assert len(self.set) == expected_len, "Removing values one by one"
! def test_discard_present(self):
self.set.discard("c")
assert self.set == Set(("a", "b")), "Discarding present element"
! def test_discard_absent(self):
self.set.discard("d")
assert self.set == Set(("a", "b", "c")), "Discarding missing element"
! def test_clear(self):
self.set.clear()
assert len(self.set) == 0, "Clearing set"
! def test_popitem(self):
popped = {}
while self.set:
***************
*** 300,312 ****
assert v in popped, "Popping items"
! def checkUpdateEmptyTuple(self):
self.set.update(())
assert self.set == Set(self.values), "Updating with empty tuple"
! def checkUpdateUnitTupleOverlap(self):
self.set.update(("a",))
assert self.set == Set(self.values), "Updating with overlapping unit tuple"
! def checkUpdateUnitTupleNonOverlap(self):
self.set.update(("a", "z"))
assert self.set == Set(self.values + ["z"]), "Updating with non-overlapping unit tuple"
--- 300,312 ----
assert v in popped, "Popping items"
! def test_update_empty_tuple(self):
self.set.update(())
assert self.set == Set(self.values), "Updating with empty tuple"
! def test_update_unit_tuple_overlap(self):
self.set.update(("a",))
assert self.set == Set(self.values), "Updating with overlapping unit tuple"
! def test_update_unit_tuple_non_overlap(self):
self.set.update(("a", "z"))
assert self.set == Set(self.values + ["z"]), "Updating with non-overlapping unit tuple"
***************
*** 320,327 ****
hash(self.set)
! def checkFreezeAfterHash(self):
! assert self.set.isFrozen(), "Set not frozen after hashing"
! def checkClearAfterFreeze(self):
try:
self.set.clear()
--- 320,327 ----
hash(self.set)
! def test_freeze_after_hash(self):
! assert self.set.is_frozen(), "Set not frozen after hashing"
! def test_clear_after_freeze(self):
try:
self.set.clear()
***************
*** 330,334 ****
pass
! def checkUnionAfterFreeze(self):
try:
self.set |= Set([2])
--- 330,334 ----
pass
! def test_union_after_freeze(self):
try:
self.set |= Set([2])
***************
*** 337,341 ****
pass
! def checkIntersectionAfterFreeze(self):
try:
self.set &= Set([2])
--- 337,341 ----
pass
! def test_intersection_after_freeze(self):
try:
self.set &= Set([2])
***************
*** 344,348 ****
pass
! def checkSymDifferenceAfterFreeze(self):
try:
self.set ^= Set([2])
--- 344,348 ----
pass
! def test_sym_difference_after_freeze(self):
try:
self.set ^= Set([2])
***************
*** 351,355 ****
pass
! def checkDifferenceAfterFreeze(self):
try:
self.set -= Set([2])
--- 351,355 ----
pass
! def test_difference_after_freeze(self):
try:
self.set -= Set([2])
***************
*** 358,362 ****
pass
! def checkAddAfterFreeze(self):
try:
self.set.add(4)
--- 358,362 ----
pass
! def test_add_after_freeze(self):
try:
self.set.add(4)
***************
*** 365,369 ****
pass
! def checkUpdateAfterFreeze(self):
try:
self.set.update([4, 5])
--- 365,369 ----
pass
! def test_update_after_freeze(self):
try:
self.set.update([4, 5])
***************
*** 376,381 ****
class TestSubsets(unittest.TestCase):
! def checkIsSubsetOf(self):
! result = self.left.isSubsetOf(self.right)
if "<" in self.cases:
assert result, "subset: " + self.name
--- 376,381 ----
class TestSubsets(unittest.TestCase):
! def test_is_subset_of(self):
! result = self.left.is_subset_of(self.right)
if "<" in self.cases:
assert result, "subset: " + self.name
***************
*** 383,388 ****
assert not result, "non-subset: " + self.name
! def checkContainsAllOf(self):
! result = self.left.containsAllOf(self.right)
if ">" in self.cases:
assert result, "contains all: " + self.name
--- 383,388 ----
assert not result, "non-subset: " + self.name
! def test_contains_all_of(self):
! result = self.left.contains_all_of(self.right)
if ">" in self.cases:
assert result, "contains all: " + self.name
***************
*** 439,443 ****
class TestOnlySetsInBinaryOps(unittest.TestCase):
! def checkCmp(self):
try:
self.other < self.set
--- 439,443 ----
class TestOnlySetsInBinaryOps(unittest.TestCase):
! def test_cmp(self):
try:
self.other < self.set
***************
*** 451,455 ****
pass
! def checkUnionUpdate(self):
try:
self.set |= self.other
--- 451,455 ----
pass
! def test_union_update(self):
try:
self.set |= self.other
***************
*** 458,462 ****
pass
! def checkUnion(self):
try:
self.other | self.set
--- 458,462 ----
pass
! def test_union(self):
try:
self.other | self.set
***************
*** 470,474 ****
pass
! def checkIntersectionUpdate(self):
try:
self.set &= self.other
--- 470,474 ----
pass
! def test_intersection_update(self):
try:
self.set &= self.other
***************
*** 477,481 ****
pass
! def checkIntersection(self):
try:
self.other & self.set
--- 477,481 ----
pass
! def test_intersection(self):
try:
self.other & self.set
***************
*** 489,493 ****
pass
! def checkSymDifferenceUpdate(self):
try:
self.set ^= self.other
--- 489,493 ----
pass
! def test_sym_difference_update(self):
try:
self.set ^= self.other
***************
*** 496,500 ****
pass
! def checkSymDifference(self):
try:
self.other ^ self.set
--- 496,500 ----
pass
! def test_sym_difference(self):
try:
self.other ^ self.set
***************
*** 508,512 ****
pass
! def checkDifferenceUpdate(self):
try:
self.set -= self.other
--- 508,512 ----
pass
! def test_difference_update(self):
try:
self.set -= self.other
***************
*** 515,519 ****
pass
! def checkDifference(self):
try:
self.other - self.set
--- 515,519 ----
pass
! def test_difference(self):
try:
self.other - self.set
***************
*** 552,556 ****
class TestCopying(unittest.TestCase):
! def checkCopy(self):
dup = self.set.copy()
dup_list = list(dup); dup_list.sort()
--- 552,556 ----
class TestCopying(unittest.TestCase):
! def test_copy(self):
dup = self.set.copy()
dup_list = list(dup); dup_list.sort()
***************
*** 560,564 ****
assert dup_list[i] is set_list[i], "Non-identical items after copy"
! def checkDeepCopy(self):
dup = copy.deepcopy(self.set)
dup_list = list(dup); dup_list.sort()
--- 560,564 ----
assert dup_list[i] is set_list[i], "Non-identical items after copy"
! def test_deep_copy(self):
dup = copy.deepcopy(self.set)
dup_list = list(dup); dup_list.sort()
***************
*** 602,626 ****
def makeAllTests():
suite = unittest.TestSuite()
! suite.addTest(unittest.makeSuite(TestBasicOpsEmpty, 'check'))
! suite.addTest(unittest.makeSuite(TestBasicOpsSingleton, 'check'))
! suite.addTest(unittest.makeSuite(TestBasicOpsTuple, 'check'))
! suite.addTest(unittest.makeSuite(TestBasicOpsTriple, 'check'))
! suite.addTest(unittest.makeSuite(TestBinaryOps, 'check'))
! suite.addTest(unittest.makeSuite(TestUpdateOps, 'check'))
! suite.addTest(unittest.makeSuite(TestMutate, 'check'))
! suite.addTest(unittest.makeSuite(TestFreeze, 'check'))
! suite.addTest(unittest.makeSuite(TestSubsetEqualEmpty, 'check'))
! suite.addTest(unittest.makeSuite(TestSubsetEqualNonEmpty, 'check'))
! suite.addTest(unittest.makeSuite(TestSubsetEmptyNonEmpty, 'check'))
! suite.addTest(unittest.makeSuite(TestSubsetPartial, 'check'))
! suite.addTest(unittest.makeSuite(TestSubsetNonOverlap, 'check'))
! suite.addTest(unittest.makeSuite(TestOnlySetsNumeric, 'check'))
! suite.addTest(unittest.makeSuite(TestOnlySetsDict, 'check'))
! suite.addTest(unittest.makeSuite(TestOnlySetsOperator, 'check'))
! suite.addTest(unittest.makeSuite(TestCopyingEmpty, 'check'))
! suite.addTest(unittest.makeSuite(TestCopyingSingleton, 'check'))
! suite.addTest(unittest.makeSuite(TestCopyingTriple, 'check'))
! suite.addTest(unittest.makeSuite(TestCopyingTuple, 'check'))
! suite.addTest(unittest.makeSuite(TestCopyingNested, 'check'))
return suite
--- 602,626 ----
def makeAllTests():
suite = unittest.TestSuite()
! suite.addTest(unittest.makeSuite(TestBasicOpsEmpty))
! suite.addTest(unittest.makeSuite(TestBasicOpsSingleton))
! suite.addTest(unittest.makeSuite(TestBasicOpsTuple))
! suite.addTest(unittest.makeSuite(TestBasicOpsTriple))
! suite.addTest(unittest.makeSuite(TestBinaryOps))
! suite.addTest(unittest.makeSuite(TestUpdateOps))
! suite.addTest(unittest.makeSuite(TestMutate))
! suite.addTest(unittest.makeSuite(TestFreeze))
! suite.addTest(unittest.makeSuite(TestSubsetEqualEmpty))
! suite.addTest(unittest.makeSuite(TestSubsetEqualNonEmpty))
! suite.addTest(unittest.makeSuite(TestSubsetEmptyNonEmpty))
! suite.addTest(unittest.makeSuite(TestSubsetPartial))
! suite.addTest(unittest.makeSuite(TestSubsetNonOverlap))
! suite.addTest(unittest.makeSuite(TestOnlySetsNumeric))
! suite.addTest(unittest.makeSuite(TestOnlySetsDict))
! suite.addTest(unittest.makeSuite(TestOnlySetsOperator))
! suite.addTest(unittest.makeSuite(TestCopyingEmpty))
! suite.addTest(unittest.makeSuite(TestCopyingSingleton))
! suite.addTest(unittest.makeSuite(TestCopyingTriple))
! suite.addTest(unittest.makeSuite(TestCopyingTuple))
! suite.addTest(unittest.makeSuite(TestCopyingNested))
return suite