示例#1
0
 def test_delete_key(self):
     m = HashTable(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))
示例#2
0
 def test_delete_key(self):
     m = HashTable(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))
示例#3
0
 def test_len_after_deletions(self):
     m = HashTable(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))
示例#4
0
 def test_len_after_deletions(self):
     m = HashTable(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))
示例#5
0
 def test_assigning_to_full_table_throws_error(self):
     m = HashTable(3)
     m.put(1, 1)
     m.put(2, 2)
     m.put(3, 3)
     with self.assertRaises(ValueError):
         m.put(4, 4)
示例#6
0
 def test_assigning_to_full_table_throws_error(self):
     m = HashTable(3)
     m.put(1, 1)
     m.put(2, 2)
     m.put(3, 3)
     with self.assertRaises(ValueError):
         m.put(4, 4)
示例#7
0
 def test_one_entry(self):
     m = HashTable(10)
     m.put(1, '1')
     self.assertEqual('1', m.get(1))
示例#8
0
from algorithms.map import HashTable

htable = HashTable()

htable.put(1, 34)
htable.put(2, 45)
htable.put(3, 65)
htable.put(4, 77)

print(htable.get(3))
"""
1 34
2 45
3 65
4 77

3 


"""
示例#9
0
 def test_add_entry_bigger_than_table_size(self):
     m = HashTable(10)
     m.put(11, '1')
     self.assertEqual('1', m.get(11))
示例#10
0
 def test_two_entries_with_same_hash(self):
     m = HashTable(10)
     m.put(1, '1')
     m.put(11, '11')
     self.assertEqual('1', m.get(1))
     self.assertEqual('11', m.get(11))
示例#11
0
 def test_delete_key_and_reassign(self):
     m = HashTable(10)
     m.put(1, 1)
     del m[1]
     m.put(1, 2)
     self.assertEqual(2, m.get(1))
示例#12
0
 def test_get_on_full_table_does_halts(self):
     # and does not search forever
     m = HashTable(10)
     for i in range(10, 20):
         m.put(i, i)
     self.assertEqual(None, m.get(1))
示例#13
0
 def test_two_entries_with_same_hash(self):
     m = HashTable(10)
     m.put(1, '1')
     m.put(11, '11')
     self.assertEqual('1', m.get(1))
     self.assertEqual('11', m.get(11))
示例#14
0
 def test_get_none_if_key_missing_and_hash_collision(self):
     m = HashTable(10)
     m.put(1, '1')
     self.assertEqual(None, m.get(11))
示例#15
0
 def test_add_entry_bigger_than_table_size(self):
     m = HashTable(10)
     m.put(11, '1')
     self.assertEqual('1', m.get(11))
示例#16
0
 def test_get_none_if_key_missing_and_hash_collision(self):
     m = HashTable(10)
     m.put(1, '1')
     self.assertEqual(None, m.get(11))
示例#17
0
 def test_len_trivial(self):
     m = HashTable(10)
     self.assertEqual(0, len(m))
     for i in range(10):
         m.put(i, i)
         self.assertEqual(i + 1, len(m))
示例#18
0
 def test_get_on_full_table_does_halts(self):
     # and does not search forever
     m = HashTable(10)
     for i in range(10, 20):
         m.put(i, i)
     self.assertEqual(None, m.get(1))
示例#19
0
 def test_fill_up_the_limit(self):
     m = HashTable(10)
     for i in range(10):
         m.put(i,i**2)
     for i in range(10):
         self.assertEqual(i**2,m.get(i))
示例#20
0
 def test_delete_key_and_reassign(self):
     m = HashTable(10)
     m.put(1, 1)
     del m[1]
     m.put(1, 2)
     self.assertEqual(2, m.get(1))
 def test_one_entry(self):
     m = HashTable(10)
     m.put(1, "1")
     self.assertEqual("1", m.get(1))
示例#22
0
 def test_len_trivial(self):
     m = HashTable(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 = HashTable(10)
     m.put(1, "1")
     m.put(11, "11")
     self.assertEqual("1", m.get(1))
     self.assertEqual("11", m.get(11))
示例#24
0
 def test_fill_up_the_limit(self):
     m = HashTable(10)
     for i in range(10):
         m.put(i, i**2)
     for i in range(10):
         self.assertEqual(i**2, m.get(i))
示例#25
0
 def test_one_entry(self):
     m = HashTable(10)
     m.put(1, '1')
     self.assertEqual('1', m.get(1))