Created
March 14, 2012 15:43
-
-
Save thiagopnts/2037364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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['Test1'] = 'changed' | |
self.assertEquals(['changed', 'Collision', 'Value from Test2', 'Value from Test3'], self.hash.values()) | |
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