예제 #1
0
    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
예제 #2
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
예제 #3
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
예제 #4
0
    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
예제 #5
0
 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
예제 #6
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')
예제 #7
0
 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]