1
0
Fork 0
Old engine for Continuous Time Bayesian Networks. Superseded by reCTBN. 🐍 https://github.com/madlabunimib/PyCTBN
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PyCTBN/tests/utility/test_cache.py

61 lines
2.1 KiB

4 years ago
# License: MIT License
4 years ago
import unittest
import numpy as np
3 years ago
from pyctbn.legacy.utility.cache import Cache
from pyctbn.legacy.structure_graph.set_of_cims import SetOfCims
4 years ago
class TestCache(unittest.TestCase):
def test_init(self):
c1 = Cache()
self.assertFalse(c1._list_of_sets_of_parents)
self.assertFalse(c1._actual_cache)
def test_put(self):
c1 = Cache()
pset1 = {'X', 'Y'}
sofc1 = SetOfCims(node_id = 'Z', parents_states_number = [], node_states_number = 3, p_combs = np.array([]))
4 years ago
c1.put(pset1, sofc1)
self.assertEqual(1, len(c1._actual_cache))
self.assertEqual(1, len(c1._list_of_sets_of_parents))
self.assertEqual(sofc1, c1._actual_cache[0])
pset2 = {'X'}
sofc2 = SetOfCims(node_id = 'Z', parents_states_number = [], node_states_number = 3, p_combs = np.array([]))
4 years ago
c1.put(pset2, sofc2)
self.assertEqual(2, len(c1._actual_cache))
self.assertEqual(2, len(c1._list_of_sets_of_parents))
self.assertEqual(sofc2, c1._actual_cache[1])
def test_find(self):
c1 = Cache()
pset1 = {'X', 'Y'}
sofc1 = SetOfCims(node_id = 'Z', parents_states_number = [], node_states_number = 3, p_combs = np.array([]))
4 years ago
c1.put(pset1, sofc1)
self.assertEqual(1, len(c1._actual_cache))
self.assertEqual(1, len(c1._list_of_sets_of_parents))
self.assertIsInstance(c1.find(pset1), SetOfCims)
self.assertEqual(sofc1, c1.find(pset1))
self.assertIsInstance(c1.find({'Y', 'X'}), SetOfCims)
self.assertEqual(sofc1, c1.find({'Y', 'X'}))
self.assertIsNone(c1.find({'X'}))
def test_clear(self):
c1 = Cache()
pset1 = {'X', 'Y'}
sofc1 = SetOfCims('Z', [], 3, np.array([]))
c1.put(pset1, sofc1)
self.assertEqual(1, len(c1._actual_cache))
self.assertEqual(1, len(c1._list_of_sets_of_parents))
c1.clear()
self.assertFalse(c1._list_of_sets_of_parents)
self.assertFalse(c1._actual_cache)
if __name__ == '__main__':
unittest.main()