def test_delete_key(self): m = SeparateChainingHashTable(10) for i in range(5): m.put(i, i**2) m.del_(1) self.assertEqual(None, m.get(1)) self.assertEqual(4, m.get(2))
def test_len_after_deletions(self): m = SeparateChainingHashTable(10) m.put(1, 1) self.assertEqual(1, len(m)) m.del_(1) self.assertEqual(0, len(m)) m.put(11, 42) self.assertEqual(1, len(m))
def test_delete_key(self): m = SeparateChainingHashTable(10) for i in range(5): m.put(i, i**2) m.del_(1) self.assertEqual(None, m.get(1)) self.assertEqual(4, m.get(2))
def test_len_after_deletions(self): m = SeparateChainingHashTable(10) m.put(1, 1) self.assertEqual(1, len(m)) m.del_(1) self.assertEqual(0, len(m)) m.put(11, 42) self.assertEqual(1, len(m))
def test_delete_key_and_reassign(self): m = SeparateChainingHashTable(10) m.put(1, 1) del m[1] m.put(1, 2) self.assertEqual(2, m.get(1))
def test_len_trivial(self): m = SeparateChainingHashTable(10) self.assertEqual(0, len(m)) for i in range(10): m.put(i, i) self.assertEqual(i + 1, len(m))
def test_two_entries_with_same_hash(self): m = SeparateChainingHashTable(10) m.put(1, '1') m.put(11, '11') self.assertEqual('1', m.get(1)) self.assertEqual('11', m.get(11))
def test_one_entry(self): m = SeparateChainingHashTable(10) m.put(1, '1') self.assertEqual('1', m.get(1))
def test_len_trivial(self): m = SeparateChainingHashTable(10) self.assertEqual(0, len(m)) for i in range(10): m.put(i, i) self.assertEqual(i + 1, len(m))
def test_one_entry(self): m = SeparateChainingHashTable(10) m.put(1, '1') self.assertEqual('1', m.get(1))
def test_get_none_if_key_missing_and_hash_collision(self): m = SeparateChainingHashTable(10) m.put(1, '1') self.assertEqual(None, m.get(11))
def test_add_entry_bigger_than_table_size(self): m = SeparateChainingHashTable(10) m.put(11, '1') self.assertEqual('1', m.get(11))
def test_delete_key_and_reassign(self): m = SeparateChainingHashTable(10) m.put(1, 1) del m[1] m.put(1, 2) self.assertEqual(2, m.get(1))
def test_add_entry_bigger_than_table_size(self): m = SeparateChainingHashTable(10) m.put(11, '1') self.assertEqual('1', m.get(11))
from algorithms.map import Node, SeparateChainingHashTable node1 = Node(1, 35) node1.next = Node(2, 45) node1.next.next = Node(3, 33) schash = SeparateChainingHashTable() schash.put(4, 77) ## print(schash.get(4)) schash.del_(4) print(schash.get(4))
def test_get_none_if_key_missing_and_hash_collision(self): m = SeparateChainingHashTable(10) m.put(1, '1') self.assertEqual(None, m.get(11))
def test_two_entries_with_same_hash(self): m = SeparateChainingHashTable(10) m.put(1, '1') m.put(11, '11') self.assertEqual('1', m.get(1)) self.assertEqual('11', m.get(11))