Beispiel #1
0
 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))
Beispiel #2
0
 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))
Beispiel #3
0
 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))
Beispiel #4
0
 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))
Beispiel #5
0
 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))
Beispiel #6
0
 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))
Beispiel #7
0
 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))
Beispiel #8
0
 def test_one_entry(self):
     m = SeparateChainingHashTable(10)
     m.put(1, '1')
     self.assertEqual('1', m.get(1))
Beispiel #9
0
 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))
Beispiel #10
0
 def test_one_entry(self):
     m = SeparateChainingHashTable(10)
     m.put(1, '1')
     self.assertEqual('1', m.get(1))
Beispiel #11
0
 def test_get_none_if_key_missing_and_hash_collision(self):
     m = SeparateChainingHashTable(10)
     m.put(1, '1')
     self.assertEqual(None, m.get(11))
Beispiel #12
0
 def test_add_entry_bigger_than_table_size(self):
     m = SeparateChainingHashTable(10)
     m.put(11, '1')
     self.assertEqual('1', m.get(11))
Beispiel #13
0
 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))
Beispiel #14
0
 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))
Beispiel #16
0
 def test_get_none_if_key_missing_and_hash_collision(self):
     m = SeparateChainingHashTable(10)
     m.put(1, '1')
     self.assertEqual(None, m.get(11))
Beispiel #17
0
 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))