summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHaidong Ji2019-03-12 21:33:24 -0500
committerHaidong Ji2019-03-12 21:33:24 -0500
commit20bda975f02bdf906e924f176c27fd95df8c8424 (patch)
tree35a9cc2c3570aecc0ce0b55b283c6be8652e47c6 /tests
parent0c0755cd6087679207063d2d31fed9a2cda23f31 (diff)
Hashing with chains done!
I was tricked by how to create a list of empty list. This line solved the problem: self.elems = [[] for i in range(n)]
Diffstat (limited to 'tests')
-rw-r--r--tests/hash_chainsTest.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/hash_chainsTest.py b/tests/hash_chainsTest.py
new file mode 100644
index 0000000..5bdac8f
--- /dev/null
+++ b/tests/hash_chainsTest.py
@@ -0,0 +1,35 @@
+import unittest
+
+from sources.hash_chains import QueryProcessor, Query
+
+class MyTestCase(unittest.TestCase):
+ def test_something(self):
+ proc = QueryProcessor(5)
+ self.assertEqual(4, proc.hash_func('world'))
+ self.assertEqual(4, proc.hash_func('HellO'))
+ self.assertEqual(2, proc.hash_func('GooD'))
+ self.assertEqual(2, proc.hash_func('luck'))
+
+ def test_something1(self):
+ proc = QueryProcessor(3)
+ self.assertEqual(1, proc.hash_func('add'))
+ self.assertEqual(1, proc.hash_func('help'))
+ self.assertEqual(2, proc.hash_func('del'))
+
+ proc.elems = [[] for i in range(12)]
+ proc.process_query(Query(['check', 0]))
+ proc.process_query(Query(['find', 'help']))
+ proc.process_query(Query(['add', 'help']))
+ proc.process_query(Query(['add', 'del']))
+ proc.process_query(Query(['add', 'add']))
+ proc.process_query(Query(['find', 'add']))
+ proc.process_query(Query(['find', 'del']))
+ proc.process_query(Query(['del', 'del']))
+ proc.process_query(Query(['find', 'del']))
+ proc.process_query(Query(['check', 0]))
+ proc.process_query(Query(['check', 1]))
+ proc.process_query(Query(['check', 2]))
+
+
+if __name__ == '__main__':
+ unittest.main()