From 20bda975f02bdf906e924f176c27fd95df8c8424 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Tue, 12 Mar 2019 21:33:24 -0500 Subject: 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)] --- tests/hash_chainsTest.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/hash_chainsTest.py (limited to 'tests') 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() -- cgit v1.2.3