Exemplo n.º 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])"
Exemplo n.º 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')])"
Exemplo n.º 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([])"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 10
0
 def setUp(self):
     self.set = Set(["hello"])
Exemplo n.º 11
0
 def setUp(self):
     self.set = Set(["zero", 0, None])
Exemplo n.º 12
0
 def test_discard_absent(self):
     self.set.discard("d")
     self.assertEqual(self.set, Set("abc"))
Exemplo n.º 13
0
 def setUp(self):
     self.set = Set()
Exemplo n.º 14
0
class TestSubsetEqualEmpty(TestSubsets):
    left  = Set()
    right = Set()
    name  = "both empty"
    cases = "==", "<=", ">="
Exemplo n.º 15
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = 'abc'
     self.otherIsIterable = True
Exemplo n.º 16
0
 def test_update_empty_tuple(self):
     self.set.union_update(())
     self.assertEqual(self.set, Set(self.values))
Exemplo n.º 17
0
 def setUp(self):
     self.a = Set('abracadabra')
     self.b = Set('alacazam')
Exemplo n.º 18
0
class TestSubsetNonOverlap(TestSubsets):
    left  = Set([1])
    right = Set([2])
    name  = "neither empty, neither contains"
    cases = "!="
Exemplo n.º 19
0
 def test_update_unit_tuple_overlap(self):
     self.set.union_update(("a",))
     self.assertEqual(self.set, Set(self.values))
Exemplo n.º 20
0
class TestSubsetPartial(TestSubsets):
    left  = Set([1])
    right = Set([1, 2])
    name  = "one a non-empty proper subset of other"
    cases = "!=", "<", "<="
Exemplo n.º 21
0
class TestSubsetEmptyNonEmpty(TestSubsets):
    left  = Set()
    right = Set([1, 2])
    name  = "one empty, one non-empty"
    cases = "!=", "<", "<="
Exemplo n.º 22
0
class TestSubsetEqualNonEmpty(TestSubsets):
    left  = Set([1, 2])
    right = Set([1, 2])
    name  = "equal pair"
    cases = "==", "<=", ">="
Exemplo n.º 23
0
 def setUp(self):
     self.set = Set([(1, 2)])
Exemplo n.º 24
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = operator.add
     self.otherIsIterable = False
Exemplo n.º 25
0
 def setUp(self):
     self.set = Set([((1, 2), (3, 4))])
Exemplo n.º 26
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = (2, 4, 6)
     self.otherIsIterable = True
Exemplo n.º 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)
Exemplo n.º 28
0
 def test_update_unit_tuple_non_overlap(self):
     self.set.union_update(("a", "z"))
     self.assertEqual(self.set, Set(self.values + ["z"]))
Exemplo n.º 29
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = 19
     self.otherIsIterable = False
Exemplo n.º 30
0
 def setUp(self):
     self.set   = Set((1, 2, 3))
     self.other = {1:2, 3:4}
     self.otherIsIterable = True