def test_set_not_none(self): testNode = NpNode(None, None) testValue = 'valueNone' testKey = 'keyNone' print('current value = ', testNode.get()) testNode.set(testKey, testValue) self.assertEquals(testNode.get(), (testKey, testValue)) print('New value = ', testNode.get())
def test_set_none(self): testNode = NpNode('key', 'value') testValue = None testKey = None print('current value = ', testNode.get()) testNode.set(testKey, testValue) self.assertEquals(testNode.get(), (testKey, testValue)) print('New value = ', testNode.get())
def test_set(self): testNode = NpNode('key1', 'test1') testValue = 'test2' testKey = 'key2' print('current value = ', testNode.get()) testNode.set(testKey, testValue) self.assertEquals(testNode.get(), (testKey, testValue)) print('New value = ', testNode.get())
def put(self, key, value): if not self.dict: #check if the dictionary is empty nodeToAdd = NpNode(key, value) self.head = nodeToAdd self.tail = nodeToAdd elif key in self.dict: #change the value of the node and move it to head. nodeToChange = self.dict[key] self.moveNodeToHead(nodeToChange) self.head.set(key, value) else: if (len(self.dict) == self.maxsize): keyToRemove = self.tail.get_key() self.tail = self.tail.prev self.tail.next = None del self.dict[keyToRemove] nodeToAdd = NpNode(key, value) self.head.prev = nodeToAdd nodeToAdd.next = self.head self.head = nodeToAdd self.dict[key] = self.head return
def test_get(self): testNode = NpNode('key1','test1') self.assertIsNotNone(testNode.get(), msg='Node should have a data value already set') self.assertEquals(testNode.get(), ('key1', 'test1'))
def test_hasValueTrue(self): testNode = NpNode('key1', 'test1') self.assertTrue(testNode.has_value('test1'))
def test_hasValueFalse(self): testNode = NpNode('key1', 'test1') self.assertFalse(testNode.has_value('test2'))