def test_errors(): ht = Hash() with pytest.raises(KeyError): ht.get("key") with pytest.raises(TypeError): ht.set(5, 5)
def test_get(self): h = Hash() h.add(1, "one") h.add(0, "zero") h.add(3, "three") h.add(2, "two") self.assertEqual(h.get(1), "one")
def test_add(self): h = Hash() self.assertEqual(h.add(1, 2), True) self.assertEqual(h.get(1), 2) h.add(1, 3) self.assertEqual(h.get(1), 3)
def test_get_method(self): testHash = Hash() testHash.put('foo', 'this is a thing') testGet = testHash.get('foo') self.assertTrue(testGet == 'this is a thing')
from hash import Hash hash_map = Hash() hash_map.set('A', 1) hash_map.set('B', 2) hash_map.set('C', 3) for n in range(100): hash_map.set(str(n), n) hash_map.set('100', 'one hundred') print(hash_map.count) print (hash_map.remove('A')) print(hash_map.get('A')) print(hash_map.count)