Loading binarycpython/tests/test_c_bindings.py +4 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ from binarycpython.utils.functions import ( verbose_print, extract_ensemble_json_from_string, is_capsule, Capturing Capturing, ) # https://docs.python.org/3/library/unittest.html Loading Loading @@ -65,6 +65,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" return argstring ####################################################################################################################################################### ### General run_system test ####################################################################################################################################################### Loading Loading @@ -117,6 +118,7 @@ class test_run_system(unittest.TestCase): # TODO: Make some assertion tests in c class test_return_store_memaddr(unittest.TestCase): """ Unit test for return_store_memaddr Loading binarycpython/tests/test_distributions.py +59 −19 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from binarycpython.utils.distribution_functions import * from binarycpython.utils.useful_funcs import calc_sep_from_period from binarycpython.utils.functions import Capturing class TestDistributions(unittest.TestCase): """ Unittest class Loading Loading @@ -121,7 +122,9 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance) # extra test for k = -1 Loading Loading @@ -155,8 +158,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra test: # M < M0 Loading Loading @@ -191,8 +198,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra tests: self.assertEqual( Loading Loading @@ -226,8 +237,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # extra test: self.assertEqual( Loading Loading @@ -345,8 +360,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for logper: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for logper: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra test: self.assertTrue( Loading Loading @@ -380,8 +399,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_raghavan2010_binary_fraction(self): with Capturing() as output: Loading @@ -402,8 +425,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_Izzard2012_period_distribution(self): with Capturing() as output: Loading Loading @@ -463,8 +490,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_flatsections(self): with Capturing() as output: Loading Loading @@ -494,8 +525,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for q: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for q: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_sana12(self): with Capturing() as output: Loading Loading @@ -746,8 +781,13 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) if __name__ == "__main__": unittest.main() binarycpython/tests/test_functions.py +0 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ class test_verbose_print(unittest.TestCase): Unittests for verbose_print """ def test_print(self): with Capturing() as output: self._test_print() Loading Loading @@ -383,7 +382,6 @@ class test_get_arg_keys(unittest.TestCase): Unittests for function get_arg_keys """ def test_1(self): with Capturing() as output: self._test_1() Loading binarycpython/tests/test_grid.py +9 −6 Original line number Diff line number Diff line Loading @@ -887,12 +887,12 @@ class test_grid_evolve(unittest.TestCase): analytics = test_pop.evolve() self.assertTrue(isinstance(test_pop.grid_ensemble_results['ensemble'], dict)) self.assertNotEqual(test_pop.grid_ensemble_results['ensemble'], {}) self.assertTrue(isinstance(test_pop.grid_ensemble_results["ensemble"], dict)) self.assertNotEqual(test_pop.grid_ensemble_results["ensemble"], {}) self.assertIn("number_counts", test_pop.grid_ensemble_results['ensemble']) self.assertIn("number_counts", test_pop.grid_ensemble_results["ensemble"]) self.assertNotEqual( test_pop.grid_ensemble_results['ensemble']["number_counts"], {} test_pop.grid_ensemble_results["ensemble"]["number_counts"], {} ) def test_grid_evolve_2_threads_with_ensemble_comparing_two_methods(self): Loading Loading @@ -1004,17 +1004,20 @@ class test_grid_evolve(unittest.TestCase): ensemble_output_2 = merge_dicts(ensemble_output_2, ensemble_json) for key in ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"]: for key in ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"]: self.assertIn(key, ensemble_output_2["number_counts"]["stellar_type"]["0"]) # compare values self.assertLess( np.abs( ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"][key] ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"][ key ] - ensemble_output_2["number_counts"]["stellar_type"]["0"][key] ), 1e-8, ) if __name__ == "__main__": unittest.main() binarycpython/tests/test_plot_functions.py +1 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ from binarycpython.utils.functions import Capturing # def test_1(self): # pass class test_color_by_index(unittest.TestCase): """ Unittests for function color_by_index Loading Loading
binarycpython/tests/test_c_bindings.py +4 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ from binarycpython.utils.functions import ( verbose_print, extract_ensemble_json_from_string, is_capsule, Capturing Capturing, ) # https://docs.python.org/3/library/unittest.html Loading Loading @@ -65,6 +65,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" return argstring ####################################################################################################################################################### ### General run_system test ####################################################################################################################################################### Loading Loading @@ -117,6 +118,7 @@ class test_run_system(unittest.TestCase): # TODO: Make some assertion tests in c class test_return_store_memaddr(unittest.TestCase): """ Unit test for return_store_memaddr Loading
binarycpython/tests/test_distributions.py +59 −19 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ from binarycpython.utils.distribution_functions import * from binarycpython.utils.useful_funcs import calc_sep_from_period from binarycpython.utils.functions import Capturing class TestDistributions(unittest.TestCase): """ Unittest class Loading Loading @@ -121,7 +122,9 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance) # extra test for k = -1 Loading Loading @@ -155,8 +158,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra test: # M < M0 Loading Loading @@ -191,8 +198,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra tests: self.assertEqual( Loading Loading @@ -226,8 +237,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # extra test: self.assertEqual( Loading Loading @@ -345,8 +360,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for logper: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for logper: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) # Extra test: self.assertTrue( Loading Loading @@ -380,8 +399,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_raghavan2010_binary_fraction(self): with Capturing() as output: Loading @@ -402,8 +425,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_Izzard2012_period_distribution(self): with Capturing() as output: Loading Loading @@ -463,8 +490,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_flatsections(self): with Capturing() as output: Loading Loading @@ -494,8 +525,12 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for q: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for q: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) def test_sana12(self): with Capturing() as output: Loading Loading @@ -746,8 +781,13 @@ class TestDistributions(unittest.TestCase): # GO over the results and check whether they are equal (within tolerance) for i in range(len(python_results)): msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format(python_results[i], perl_results[i], str(input_lists[i])) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format( python_results[i], perl_results[i], str(input_lists[i]) ) self.assertLess( np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg ) if __name__ == "__main__": unittest.main()
binarycpython/tests/test_functions.py +0 −2 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ class test_verbose_print(unittest.TestCase): Unittests for verbose_print """ def test_print(self): with Capturing() as output: self._test_print() Loading Loading @@ -383,7 +382,6 @@ class test_get_arg_keys(unittest.TestCase): Unittests for function get_arg_keys """ def test_1(self): with Capturing() as output: self._test_1() Loading
binarycpython/tests/test_grid.py +9 −6 Original line number Diff line number Diff line Loading @@ -887,12 +887,12 @@ class test_grid_evolve(unittest.TestCase): analytics = test_pop.evolve() self.assertTrue(isinstance(test_pop.grid_ensemble_results['ensemble'], dict)) self.assertNotEqual(test_pop.grid_ensemble_results['ensemble'], {}) self.assertTrue(isinstance(test_pop.grid_ensemble_results["ensemble"], dict)) self.assertNotEqual(test_pop.grid_ensemble_results["ensemble"], {}) self.assertIn("number_counts", test_pop.grid_ensemble_results['ensemble']) self.assertIn("number_counts", test_pop.grid_ensemble_results["ensemble"]) self.assertNotEqual( test_pop.grid_ensemble_results['ensemble']["number_counts"], {} test_pop.grid_ensemble_results["ensemble"]["number_counts"], {} ) def test_grid_evolve_2_threads_with_ensemble_comparing_two_methods(self): Loading Loading @@ -1004,17 +1004,20 @@ class test_grid_evolve(unittest.TestCase): ensemble_output_2 = merge_dicts(ensemble_output_2, ensemble_json) for key in ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"]: for key in ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"]: self.assertIn(key, ensemble_output_2["number_counts"]["stellar_type"]["0"]) # compare values self.assertLess( np.abs( ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"][key] ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"][ key ] - ensemble_output_2["number_counts"]["stellar_type"]["0"][key] ), 1e-8, ) if __name__ == "__main__": unittest.main()
binarycpython/tests/test_plot_functions.py +1 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ from binarycpython.utils.functions import Capturing # def test_1(self): # pass class test_color_by_index(unittest.TestCase): """ Unittests for function color_by_index Loading