Esempio n. 1
0
 def test_incorrect_weights(self):
     # Weight not summing up to 1
     array = [cache.LruCache(2) for _ in range(2)]
     with pytest.raises(ValueError):
         cache.ArrayCache(array, weights=[0.8, 0.1])
         cache.ArrayCache(array, weights=[0.8, 0.3])
         # Number of weights not matching with number of nodes
         cache.ArrayCache(array, weights=[1.0])
         cache.ArrayCache(array, weights=[0.8, 0.1, 0.1])
Esempio n. 2
0
 def test_put_get(self):
     c = cache.ArrayCache([cache.LruCache(2) for _ in range(2)])
     self.assertFalse(c.get(1))
     c.put(1)
     c_0, c_1 = [(1 in i) for i in c.dump(serialized=False)]
     # Assert that item is in leaf 0 XOR leaf 1
     self.assertTrue((c_0 and not c_1) or (not c_0 and c_1))
     if not c.get(1):
         c.put(1)
         self.assertEqual(c.dump(serialized=False), [[1], [1]])
Esempio n. 3
0
 def test_put_get(self):
     c = cache.ArrayCache([cache.LruCache(2) for _ in range(2)])
     assert not c.get(1)
     c.put(1)
     c_0, c_1 = [(1 in i) for i in c.dump(serialized=False)]
     # Assert that item is in leaf 0 XOR leaf 1
     assert (c_0 and not c_1) or (not c_0 and c_1)
     if not c.get(1):
         c.put(1)
         assert c.dump(serialized=False) == [[1], [1]]
Esempio n. 4
0
 def test_no_read_through(self):
     c = cache.ArrayCache([cache.LruCache(2) for _ in range(2)])
     self.assertRaises(ValueError, c.put, 1)
Esempio n. 5
0
 def test_no_read_through(self):
     c = cache.ArrayCache([cache.LruCache(2) for _ in range(2)])
     with pytest.raises(ValueError):
         c.put(1)