Starts implementing the hash method. Throws an exception if the length of value is inconsistent

This commit is contained in:
Julien Lengrand-Lambert
2013-11-21 10:36:12 +01:00
parent 494f57d699
commit 03ca739a08
2 changed files with 14 additions and 1 deletions

View File

@@ -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

View File

@@ -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()