コード例 #1
0
 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())
コード例 #2
0
 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())
コード例 #3
0
 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())
コード例 #4
0
ファイル: lruCache.py プロジェクト: shaikhh2/LRUcache
 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
コード例 #5
0
 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'))
コード例 #6
0
 def test_hasValueTrue(self):
     testNode = NpNode('key1', 'test1')
     self.assertTrue(testNode.has_value('test1'))
コード例 #7
0
 def test_hasValueFalse(self):
     testNode = NpNode('key1', 'test1')
     self.assertFalse(testNode.has_value('test2'))