def test_add(self):
        set = HashSet()
        set.add('After the darkness')
        assert set.size == 1  # added one element

        set.add('Dertogada')
        assert set.size == 2  # added a second element

        set.add('Ramatohara')
        assert set.size == 3  # added a thrid element

        set.add('Ramatohara')
        assert set.size == 3  # element already exist, no size change
예제 #2
0
 def test_add(self):
     elements = ['J', 'K']
     set = HashSet(elements)
     set.add('P')
     set.add('E')
     with self.assertRaises(KeyError):
         set.add('K')  # Element already exists
     with self.assertRaises(KeyError):
         set.add('E')  # Element already exists
     assert set.size is 4
     assert set.contains('P') is True
     assert set.contains('E') is True
예제 #3
0
	def test_remove(self):
		h = HashSet()
		h.add("Egg")
		h.add("Tuna")
		h.remove("Egg")
		assert h.size == 1
예제 #4
0
	def test_contains(self):
		h = HashSet()
		h.add("Mondale")
		assert h.contains("Mondale") == True
		assert h.contains("Alfred") == False
예제 #5
0
	def test_add(self):
		h = HashSet()
		assert h.size == 0
		h.add("Mondale")
		assert h.size == 1