Skip to content

Instantly share code, notes, and snippets.

@thiagopnts
Created March 14, 2012 15:13
Show Gist options
  • Save thiagopnts/2037146 to your computer and use it in GitHub Desktop.
Save thiagopnts/2037146 to your computer and use it in GitHub Desktop.
import unittest
from hash import HashMap
class HashMapTest(unittest.TestCase):
def setUp(self):
self.hash = HashMap()
def test(self):
self.hash.put('Test1', "Value from Test1")
self.hash.put('Test2', "Value from Test2")
self.assertEquals('Value from Test1', self.hash.get('Test1'))
self.assertEquals('Value from Test2', self.hash.get('Test2'))
self.assertEquals(['Value from Test1', 'Value from Test2'], self.hash.values())
self.assertEquals(['Test1', 'Test2'], self.hash.keys())
self.hash['Test3'] = 'Value from Test3'
self.assertEquals('Value from Test3', self.hash.get('Test3'))
self.assertEquals(['Value from Test1', 'Value from Test2', 'Value from Test3'], self.hash.values())
self.assertEquals(['Test1', 'Test2', 'Test3'], self.hash.keys())
self.hash.put('1tesT', "Collision")
self.assertEquals('Collision', self.hash.get('1tesT'))
self.assertEquals(['Test1', '1tesT', 'Test2', 'Test3'], self.hash.keys())
self.hash.clear()
self.assertEquals([], self.hash.keys())
self.assertEquals([], self.hash.values())
try:
self.assertRaises(Exception, self.hash.get('fail'))
except Exception as e:
self.assertEquals('key dont exists', e.message)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment