Пример #1
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
Пример #2
0
    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)
Пример #3
0
 def test_contains(self):
     hs = HashSet([1, 2, 3])
     assert hs.contains(2) == True
     assert hs.contains(4) == False