-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_myhashtable.py
43 lines (30 loc) · 1.18 KB
/
test_myhashtable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
from unittest.mock import patch
from hash_class import MyHashTable
class TestMyHashTable(unittest.TestCase):
def test_insert_and_get_value(self):
hash_table = MyHashTable()
# insert
hash_table.insert("hello world", 5)
hash_table.insert("python", 10)
hash_table.insert("tensorflow", 15)
# assertions
self.assertEqual(hash_table.get_value("hello world"), 5)
self.assertEqual(hash_table.get_value("python"), 10)
self.assertEqual(hash_table.get_value("tensorflow"), 15)
def test_size(self):
# test default size
self.assertEqual(MyHashTable().size, 10)
hash_table = MyHashTable(30000)
self.assertEqual(hash_table.size, 30000)
def test_collision(self):
with patch.object(MyHashTable, '_hash', return_value=0):
hash_table = MyHashTable(10)
# insert
hash_table.insert("hello world", 5)
hash_table.insert("python", 10)
# assertions
self.assertEqual(hash_table.get_value("hello world"), 5)
self.assertEqual(hash_table.get_value("python"), 10)
if __name__ == '__main__':
unittest.main()