示例#1
0
 def test_returns_true_if_value_found(self):
     """
     Returns True if the value is found in the cache
     """
     cache = LRUCache(100)
     cache.add_value("test")
     result = cache.access_value("test")
     self.assertEqual(result, True)
示例#2
0
 def test_returns_true_if_deleted(self):
     """
     Returns True if the value has been deleted
     from the cache
     """
     cache = LRUCache(100)
     cache.add_value(1)
     result = cache.delete_value(1)
     self.assertEqual(result, True)
示例#3
0
 def test_returns_false_if_value_not_found(self):
     """
     Returns False if the value is not found in the
     cache
     """
     cache = LRUCache(100)
     cache.add_value("test")
     result = cache.access_value("this value cannot be found")
     self.assertEqual(result, False)
示例#4
0
 def test_removes_value_at_back_of_cache(self):
     """
     Removes a value at the back of the cache if the max
     size has been reached
     """
     cache = LRUCache(5)
     for i in range(0, 6):
         cache.add_value(i)
     result = cache._back.get_value()
     self.assertEqual(result, 1)
示例#5
0
 def test_delete_updates_length(self):
     """
     Updates the correct length of the cache
     """
     cache = LRUCache(10)
     cache.add_value(1)
     before_delete = cache.length()
     cache.delete_value(1)
     after_delete = cache.length()
     self.assertEqual(before_delete, 1)
     self.assertEqual(after_delete, 0)
示例#6
0
 def test_delete_sets_front_and_back_to_none(self):
     """
     Sets front and back references to None
     """
     cache = LRUCache(100)
     cache.add_value(1)
     cache.delete_value(1)
     front_value = cache._front
     back_value = cache._back
     self.assertEqual(front_value, None)
     self.assertEqual(back_value, None)
示例#7
0
 def test_adds_value_to_front_of_cache(self):
     """
     Adds a new value to the front of the cache
     """
     cache = LRUCache(100)
     cache.add_value(1)
     cache.add_value(2)
     front_value = cache._front.get_value()
     back_value = cache._back.get_value()
     self.assertEqual(front_value, 2)
     self.assertEqual(back_value, 1)
示例#8
0
 def test_returns_correct_length(self):
     """
     Returns the correct length of the cache if
     values have been added
     """
     cache = LRUCache(1234)
     cache.add_value("1")
     cache.add_value("2")
     cache.add_value("3")
     result = cache.length()
     self.assertEqual(result, 3)
示例#9
0
 def test_sets_new_front_correctly(self):
     """
     Sets the new front of the cache correctly
     when deleting the front value
     """
     cache = LRUCache(10)
     cache.add_value(1)
     cache.add_value(2)
     cache.add_value(3)
     cache.delete_value(3)
     result = cache._front.get_value()
     self.assertEqual(result, 2)
示例#10
0
 def test_sets_new_back_correctly(self):
     """
     Sets the new back of the cache correctly
     when deleting the back value
     """
     cache = LRUCache(10)
     cache.add_value(1)
     cache.add_value(2)
     cache.add_value(3)
     cache.delete_value(1)
     result = cache._back.get_value()
     self.assertEqual(result, 2)
示例#11
0
 def test_accesses_value_and_moves_to_front(self):
     """
     Moves a value to the front of the cache if it's
     accessed
     """
     cache = LRUCache(10, "first")
     cache.add_value("second")
     cache.add_value("third")
     cache.access_value("first")
     front_value = cache._front.get_value()
     back_value = cache._back.get_value()
     self.assertEqual(front_value, "first")
     self.assertEqual(back_value, "second")