Beispiel #1
0
 def test_intersection(self):
     s1 = HashSet(['J', 'E', 'R', 'I'])
     s2 = HashSet(['H', 'T', 'E', 'R'])
     s3 = s1.intersection(s2)
     assert s3.contains('E') == True
     assert s3.contains('R') == True
     assert s3.size() == 2
Beispiel #2
0
    def test_difference(self):
        s1 = HashSet(['J', 'I', 'E', 'R'])
        s2 = HashSet(['H', 'N', 'E', 'R'])
        s3 = s1.difference(s2)

        assert s3.contains('N') == True
        assert s3.contains('H') == True
        assert s3.size() == 2
Beispiel #3
0
 def test_union(self):
     s1 = HashSet(['J', 'E', 'R', 'I'])
     s2 = HashSet(['H', 'U', 'N', 'T'])
     s3 = s1.union(s2)
     assert s3.contains('J') == True
     assert s3.contains('E') == True
     assert s3.contains('R') == True
     assert s3.contains('I') == True
     assert s3.contains('H') == True
     assert s3.contains('U') == True
     assert s3.contains('N') == True
     assert s3.contains('T') == True
     assert s3.size() == 8
    def test_remove(self):
        hs = HashSet([1, 2, 3])
        assert hs.items() == [1, 2, 3]
        assert hs.contains(3) == True
        assert hs.size == 3

        # remove item
        hs.remove(3)
        assert hs.items() == [1, 2]
        assert hs.contains(3) == False
        assert hs.size == 2

        with self.assertRaises(KeyError):
            hs.remove(3)
    def test_is_subset(self):
        hs1 = HashSet([1, 2, 3, 4, 5])
        hs2 = HashSet([2, 3, 4])

        assert hs1.is_subset(hs2) == True
        hs2.add(6)
        assert hs1.is_subset(hs2) == False
    def test_add(self):
        hs = HashSet([1, 2, 3])
        assert hs.items() == [1, 2, 3]
        # normal add
        hs.add(4)
        assert hs.items() == [1, 2, 3, 4]
        assert hs.size == 4

        # try to add duplicate
        hs.add(4)
        assert hs.items() == [1, 2, 3, 4]
        assert hs.size == 4
Beispiel #7
0
    def test_contains(self):
        s = HashSet()

        s.add('S')
        assert s.contains('S') == True
        assert s.contains('H') == False

        s.add('H')
        assert s.contains('H') == True
        assert s.contains('S') == True
Beispiel #8
0
    def test_add(self):
        s = HashSet()
        assert s.add('S') == True
        assert s.add('H') == True
        assert s.add('A') == True
        assert s.size() == 3

        assert s.add('A') == False
        assert s.add('H') == False
        assert s.add('S') == False

        assert s.size() == 3
Beispiel #9
0
    def test_is_subset(self):
        s1 = HashSet(['J', 'I', 'H'])
        s2 = HashSet(['J', 'I'])
        s3 = HashSet(['J', 'H'])
        s4 = HashSet(['H', 'F'])

        assert s1.is_subset(s2) == True
        assert s1.is_subset(s3) == True
        assert s1.is_subset(s4) == False
 def test_size(self):
     hs = HashSet([1, 2, 3])
     assert hs.ht.size == 3
     assert hs.size == 3
     assert len(hs) == 3
     hs.add(4)
     assert hs.ht.size == 4
     assert hs.size == 4
     assert len(hs) == 4
     hs.remove(2)
     assert hs.ht.size == 3
     assert hs.size == 3
     assert len(hs) == 3
 def test_contains(self):
     hs = HashSet([1, 2, 3])
     assert hs.contains(2) == True
     assert hs.contains(4) == False
    def test_difference(self):
        hs1 = HashSet([1, 2, 3, 4])
        hs2 = HashSet([3, 4, 5])

        difference = hs1.difference(hs2)
        assert difference.items() == [1, 2]
 def test_items(self):
     hs = HashSet([1, 2, 3])
     assert hs.items() == [1, 2, 3]
     hs.add(4)
     assert hs.items() == [1, 2, 3, 4]
 def test_init(self):
     hs = HashSet([1, 2, 3])
     assert hs.ht is not None
     assert hs.ht.size == 3
     assert hs is not None
Beispiel #15
0
 def test_init(self):
     elements = ['S', 'H', 'A', 'U', 'N', 'E', 'L', 'L']
     s = HashSet(elements)
     assert s.ht.length() == 7
     assert s.size() == 7
    def test_union(self):
        hs1 = HashSet([1, 2, 3, 4])
        hs2 = HashSet([2, 3, 4, 5])

        union = hs1.union(hs2)
        assert union.items() == [1, 2, 3, 4, 5]
Beispiel #17
0
    def test_remove(self):
        s = HashSet()
        s.add('S')
        s.add('H')
        s.add('A')

        s.remove('A')
        assert s.size() == 2

        s.remove('H')
        assert s.size() == 1

        s.remove('S')
        assert s.size() == 0

        with self.assertRaises(KeyError):
            s.remove('S')
    def test_intersection(self):
        hs1 = HashSet([1, 2, 3, 4])
        hs2 = HashSet([2, 3, 4, 5])

        intersection = hs1.intersection(hs2)
        assert intersection.items() == [2, 3, 4]
 def test_get(self):
     hs = HashSet([1, 2, 3])
     assert hs.get(2) == 2
     with self.assertRaises(KeyError):
         hs.get(4)