mirror of
https://github.com/jlengrand/Coding4Interviews.git
synced 2026-03-10 08:11:24 +00:00
Starts implementing the hash method. Throws an exception if the length of value is inconsistent
This commit is contained in:
@@ -11,3 +11,9 @@ class HashMap():
|
||||
def size(self):
|
||||
return self._size
|
||||
|
||||
def _hash(self, value):
|
||||
if len(value) < 1:
|
||||
raise Exception("Size of value must be greater than one")
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
@@ -12,9 +12,16 @@ import unittest
|
||||
class test_hash_map(unittest.TestCase):
|
||||
|
||||
def test_size(self):
|
||||
|
||||
hm = HashMap()
|
||||
self.assertEqual(hm.size(), 0)
|
||||
|
||||
def test__hash(self):
|
||||
hm = HashMap()
|
||||
value = "test"
|
||||
self.assertEqual(hm._hash("test"), 1)
|
||||
|
||||
value = ""
|
||||
self.assertRaises(Exception, lambda x : hm._hash(value))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user