Beispiel #1
0
 def setUp(self):
     self.case   = "unit set (number)"
     self.values = [3]
     self.set    = Set(self.values)
     self.dup    = Set(self.values)
     self.length = 1
     self.repr   = "Set([3])"
Beispiel #2
0
 def setUp(self):
     self.case   = "unit set (tuple)"
     self.values = [(0, "zero")]
     self.set    = Set(self.values)
     self.dup    = Set(self.values)
     self.length = 1
     self.repr   = "Set([(0, 'zero')])"
Beispiel #3
0
 def setUp(self):
     self.case   = "empty set"
     self.values = []
     self.set    = Set(self.values)
     self.dup    = Set(self.values)
     self.length = 0
     self.repr   = "Set([])"
Beispiel #4
0
 def setUp(self):
     self.case   = "triple set"
     self.values = [0, "zero", operator.add]
     self.set    = Set(self.values)
     self.dup    = Set(self.values)
     self.length = 3
     self.repr   = None
Beispiel #5
0
 def test_constructor2(self):
     inner = ImmutableSet([1])
     outer = Set([inner])
     element = list(outer).pop()
     outer.remove(inner)
     self.assertEqual(type(element), ImmutableSet)
     outer.add(inner)        # Rebuild set of sets with .add method
     outer.remove(inner)
     self.assertEqual(outer, Set())   # Verify that remove worked
     outer.discard(inner)    # Absence of KeyError indicates working fine
Beispiel #6
0
    def test_cmp(self):
        a, b = Set('a'), Set('b')
        self.assertRaises(TypeError, cmp, a, b)

        # You can view this as a buglet:  cmp(a, a) does not raise TypeError,
        # because __eq__ is tried before __cmp__, and a.__eq__(a) returns True,
        # which Python thinks is good enough to synthesize a cmp() result
        # without calling __cmp__.
        self.assertEqual(cmp(a, a), 0)

        self.assertRaises(TypeError, cmp, a, 12)
        self.assertRaises(TypeError, cmp, "abc", a)
Beispiel #7
0
 def setUp(self):
     def gen():
         for i in xrange(0, 10, 2):
             yield i
     self.set   = Set((1, 2, 3))
     self.other = gen()
     self.otherIsIterable = True
Beispiel #8
0
 def test_add_until_full(self):
     tmp = Set()
     expected_len = 0
     for v in self.values:
         tmp.add(v)
         expected_len += 1
         self.assertEqual(len(tmp), expected_len)
     self.assertEqual(tmp, self.set)
Beispiel #9
0
 def test_instancesWithoutException(self):
     # All of these iterables should load without exception.
     Set([1,2,3])
     Set((1,2,3))
     Set({'one':1, 'two':2, 'three':3})
     Set(xrange(3))
     Set('abc')
     Set(gooditer())
Beispiel #10
0
 def setUp(self):
     self.set = Set(["hello"])
Beispiel #11
0
 def setUp(self):
     self.set = Set(["zero", 0, None])
Beispiel #12
0
 def test_discard_absent(self):
     self.set.discard("d")
     self.assertEqual(self.set, Set("abc"))
Beispiel #13
0
 def setUp(self):
     self.set = Set()
Beispiel #14
0
class TestSubsetEqualEmpty(TestSubsets):
    left  = Set()
    right = Set()
    name  = "both empty"
    cases = "==", "<=", ">="
Beispiel #15
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = 'abc'
     self.otherIsIterable = True
Beispiel #16
0
 def test_update_empty_tuple(self):
     self.set.union_update(())
     self.assertEqual(self.set, Set(self.values))
Beispiel #17
0
 def setUp(self):
     self.a = Set('abracadabra')
     self.b = Set('alacazam')
Beispiel #18
0
class TestSubsetNonOverlap(TestSubsets):
    left  = Set([1])
    right = Set([2])
    name  = "neither empty, neither contains"
    cases = "!="
Beispiel #19
0
 def test_update_unit_tuple_overlap(self):
     self.set.union_update(("a",))
     self.assertEqual(self.set, Set(self.values))
Beispiel #20
0
class TestSubsetPartial(TestSubsets):
    left  = Set([1])
    right = Set([1, 2])
    name  = "one a non-empty proper subset of other"
    cases = "!=", "<", "<="
Beispiel #21
0
class TestSubsetEmptyNonEmpty(TestSubsets):
    left  = Set()
    right = Set([1, 2])
    name  = "one empty, one non-empty"
    cases = "!=", "<", "<="
Beispiel #22
0
class TestSubsetEqualNonEmpty(TestSubsets):
    left  = Set([1, 2])
    right = Set([1, 2])
    name  = "equal pair"
    cases = "==", "<=", ">="
Beispiel #23
0
 def setUp(self):
     self.set = Set([(1, 2)])
Beispiel #24
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = operator.add
     self.otherIsIterable = False
Beispiel #25
0
 def setUp(self):
     self.set = Set([((1, 2), (3, 4))])
Beispiel #26
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = (2, 4, 6)
     self.otherIsIterable = True
Beispiel #27
0
 def test_exclusion(self):
     # check that inverse operations show non-overlap
     a, b, zero = self.a, self.b, Set()
     self.assertEqual((a-b)&b, zero)
     self.assertEqual((b-a)&a, zero)
     self.assertEqual((a&b)&(a^b), zero)
Beispiel #28
0
 def test_update_unit_tuple_non_overlap(self):
     self.set.union_update(("a", "z"))
     self.assertEqual(self.set, Set(self.values + ["z"]))
Beispiel #29
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = 19
     self.otherIsIterable = False
Beispiel #30
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = {1:2, 3:4}
     self.otherIsIterable = True