From e00096785217d3566a323195e538a7962c9a4c68 Mon Sep 17 00:00:00 2001 From: Pietro Date: Thu, 25 Mar 2021 18:12:31 +0100 Subject: [PATCH] Test --- .../structure_graph/trajectory_generator.py | 1 - .../test_trajectorygenerator.py | 11 +++++++ test_trajectorygenerator.py | 33 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 PyCTBN/tests/structure_graph/test_trajectorygenerator.py create mode 100644 test_trajectorygenerator.py diff --git a/PyCTBN/PyCTBN/structure_graph/trajectory_generator.py b/PyCTBN/PyCTBN/structure_graph/trajectory_generator.py index cd47510..898ffa8 100644 --- a/PyCTBN/PyCTBN/structure_graph/trajectory_generator.py +++ b/PyCTBN/PyCTBN/structure_graph/trajectory_generator.py @@ -33,7 +33,6 @@ class TrajectoryGenerator(object): self._cims[v] = sof def CTBN_Sample(self, t_end): - #Replace v_values with sigma (pandas dataframe) t = 0 sigma = pd.DataFrame(columns = (["Time"] + self._vnames)) sigma.loc[len(sigma)] = [0] + [0 for v in self._vnames] diff --git a/PyCTBN/tests/structure_graph/test_trajectorygenerator.py b/PyCTBN/tests/structure_graph/test_trajectorygenerator.py new file mode 100644 index 0000000..171e152 --- /dev/null +++ b/PyCTBN/tests/structure_graph/test_trajectorygenerator.py @@ -0,0 +1,11 @@ +import unittest + +from ...PyCTBN.structure_graph.trajectory_generator import TrajectoryGenerator + +class TestTrajectoryGenerator(unittest.TestCase) + @classmethod + def setUpClass(cls) -> None: + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/test_trajectorygenerator.py b/test_trajectorygenerator.py new file mode 100644 index 0000000..4534a9c --- /dev/null +++ b/test_trajectorygenerator.py @@ -0,0 +1,33 @@ +import unittest +import random + +from PyCTBN.PyCTBN.structure_graph.trajectory_generator import TrajectoryGenerator +from PyCTBN.PyCTBN.utility.json_importer import JsonImporter + +class TestTrajectoryGenerator(unittest.TestCase): + @classmethod + def setUpClass(cls) -> None: + cls.j1 = JsonImporter("./PyCTBN/test_data/networks_and_trajectories_binary_data_01_3.json", "samples", "dyn.str", "variables", "Time", "Name") + + def test_init(self): + tg = TrajectoryGenerator(self.j1) + self.assertEqual(len(tg._vnames), len(self.j1.variables)) + self.assertIsInstance(tg._vnames, list) + self.assertIsInstance(tg._parents, dict) + self.assertIsInstance(tg._cims, dict) + self.assertListEqual(list(tg._parents.keys()), tg._vnames) + self.assertListEqual(list(tg._cims.keys()), tg._vnames) + + def test_generated_trajectory(self): + tg = TrajectoryGenerator(self.j1) + end_time = random.randint(5, 100) + sigma = tg.CTBN_Sample(end_time) + self.assertLessEqual(sigma.loc[len(sigma) - 1].at["Time"], end_time) + for index, row in sigma.iterrows(): + if index > 0: + self.assertLess(sigma.loc[index - 1].at["Time"], row.at["Time"]) + diff = abs(sum(sigma.loc[index - 1, sigma.columns != "Time"]) - + sum(sigma.loc[index, sigma.columns != "Time"])) + self.assertEqual(diff, 1) + +unittest.main() \ No newline at end of file