1
0
Fork 0

Improve tests coverages

parallel_struct_est
philpMartin 4 years ago
parent 1bdc8a7231
commit 98ba2bef24
  1. 2
      main_package/tests/test_cache.py
  2. 6
      main_package/tests/test_cim.py
  3. 31
      main_package/tests/test_json_importer.py
  4. 4
      main_package/tests/test_networkgraph.py
  5. 2
      main_package/tests/test_parameters_estimator.py
  6. 2
      main_package/tests/test_sample_path.py
  7. 2
      main_package/tests/test_setofcims.py
  8. 9
      main_package/tests/test_structure.py
  9. 7
      main_package/tests/test_structure_estimator.py
  10. 7
      main_package/tests/test_trajectory.py

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np
@ -36,6 +38,10 @@ class TestConditionalIntensityMatrix(unittest.TestCase):
for j in range(0, len(self.state_res_times)):
self.assertTrue(np.isclose(c1.cim[i, j], c2[i, j], 1e-02, 1e-01))
def test_repr(self):
c1 = cim.ConditionalIntensityMatrix(self.state_res_times, self.state_transition_matrix)
print(c1)
if __name__ == '__main__':
unittest.main()

@ -9,10 +9,10 @@ import json_importer as ji
from line_profiler import LineProfiler
import os
import json
class TestJsonImporter(unittest.TestCase):
@classmethod
@ -98,6 +98,12 @@ class TestJsonImporter(unittest.TestCase):
for df in j1.df_samples_list:
self.assertTrue(df.empty)
def test_clear_concatenated_frame(self):
j1 = ji.JsonImporter(self.read_files[0], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
j1.import_data()
j1.clear_concatenated_frame()
self.assertTrue(j1.concatenated_samples.empty)
def test_build_list_of_samples_array(self):
data_set = {"key1": [1, 2, 3], "key2": [4.1, 5.2, 6.3]}
with open('data.json', 'w') as f:
@ -122,13 +128,28 @@ class TestJsonImporter(unittest.TestCase):
j1.import_variables(raw_data, sorter)
self.assertEqual(list(j1.variables[j1.variables_key]), sorter)
def test_import_structure(self):
j1 = ji.JsonImporter(self.read_files[0], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
raw_data = [{"dyn.str":[{"From":"X","To":"Z"},{"From":"Y","To":"Z"},{"From":"Z","To":"Y"}]}]
j1.import_structure(raw_data)
#print(raw_data[0]['dyn.str'][0].items())
self.assertIsInstance(j1.structure, pd.DataFrame)
def test_import_sampled_cims(self):
j1 = ji.JsonImporter(self.read_files[0], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
raw_data = j1.read_json_file()
cims = j1.import_sampled_cims(raw_data, 0, 'dyn.cims')
j1.import_variables(raw_data, ['X','Y','Z'])
self.assertEqual(list(cims.keys()), j1.variables['Name'].tolist())
def test_import_data(self):
j1 = ji.JsonImporter(self.read_files[0], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
lp = LineProfiler()
j1.import_data()
#lp = LineProfiler()
lp_wrapper = lp(j1.import_data)
lp_wrapper()
lp.print_stats()
#lp_wrapper = lp(j1.import_data)
#lp_wrapper()
#lp.print_stats()
#j1.import_data()
self.assertEqual(list(j1.variables[j1.variables_key]),
list(j1.concatenated_samples.columns.values[1:len(j1.variables[j1.variables_key]) + 1]))

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import glob
import os
@ -147,7 +149,7 @@ class TestNetworkGraph(unittest.TestCase):
#print(fancy_indx)
for node_id, p_indxs, p_labels, p_v in zip(g1.graph_struct.nodes_labels, fancy_indx, p_labels, p_vals):
self.aux_build_time_scalar_indexing_structure_for_a_node(g1, node_id, p_indxs, p_labels, p_v)
#TODO Sei arrivato QUI
def test_build_time_columns_filtering_structure(self):
g1 = ng.NetworkGraph(self.s1.structure)
g1.add_nodes(self.s1.structure.nodes_labels)

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np
import glob

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import glob
import os

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np
import itertools

@ -68,6 +68,15 @@ class TestStructure(unittest.TestCase):
for val, node in zip(v2, l2):
self.assertEqual(val, s1.get_states_number(node))
def test_equality(self):
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
s2 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
self.assertEqual(s1, s2)
def test_repr(self):
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
print(s1)
if __name__ == '__main__':
unittest.main()

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np
import networkx as nx
@ -74,9 +76,6 @@ class TestStructureEstimator(unittest.TestCase):
lp_wrapper()
lp.print_stats()
print(se1.complete_graph.edges)
<<<<<<< HEAD
print(self.s1.structure.list_of_edges())
=======
print(self.s1.structure.edges)
for ed in self.s1.structure.edges:
self.assertIn(tuple(ed), se1.complete_graph.edges)
@ -85,8 +84,6 @@ class TestStructureEstimator(unittest.TestCase):
for ed in se1.complete_graph.edges:
if not(ed in tuples_edges):
spurious_edges.append(ed)
>>>>>>> 6ced913c442e75d14d07c379635b2afdead1d9ea
print("Spurious Edges:",spurious_edges)
se1.save_results()

@ -1,3 +1,5 @@
import sys
sys.path.append("/Users/Zalum/Desktop/Tesi/CTBN_Project/main_package/classes/")
import unittest
import numpy as np
@ -35,6 +37,11 @@ class TestTrajectory(unittest.TestCase):
t1 = tr.Trajectory(cols_list, len(cols_list) - 2)
self.assertTrue(np.array_equal(cols_list[0], t1.times))
def test_repr(self):
cols_list = [np.array([1.2, 1.3, .14]), np.arange(1, 4), np.arange(4, 7)]
t1 = tr.Trajectory(cols_list, len(cols_list) - 2)
print(t1)
if __name__ == '__main__':
unittest.main()