Commit 3fbea66f authored by David Hendriks's avatar David Hendriks
Browse files

black formatting

parent 08681f34
Loading
Loading
Loading
Loading
+49 −26
Original line number Diff line number Diff line
@@ -30,19 +30,17 @@ class TestDistributions(unittest.TestCase):
        Unittest for function set_opts
        """

        default_dict = {'m1': 2, 'm2': 3}
        default_dict = {"m1": 2, "m2": 3}
        output_dict_1 = set_opts(default_dict, {})
        self.assertTrue(output_dict_1 == default_dict)


        new_opts = {'m1': 10}
        new_opts = {"m1": 10}
        output_dict_2 = set_opts(default_dict, new_opts)
        updated_dict = default_dict.copy()
        updated_dict['m1'] = 10
        updated_dict["m1"] = 10

        self.assertTrue(output_dict_2 == updated_dict)


    def test_flat(self):
        """
        Unittest for the function flat
@@ -69,12 +67,14 @@ class TestDistributions(unittest.TestCase):
        """

        output_1 = const(min_bound=0, max_bound=2)
        self.assertEqual(output_1, 0.5, msg="Value should be 0.5, but is {}".format(output_1))

        self.assertEqual(
            output_1, 0.5, msg="Value should be 0.5, but is {}".format(output_1)
        )

        output_2 = const(min_bound=0, max_bound=2, val=3)
        self.assertEqual(output_2, 0, msg="Value should be 0, but is {}".format(output_2))

        self.assertEqual(
            output_2, 0, msg="Value should be 0, but is {}".format(output_2)
        )

    def test_powerlaw(self):
        """
@@ -127,8 +127,10 @@ class TestDistributions(unittest.TestCase):

        # Extra test:
        # M < M0
        self.assertTrue(three_part_powerlaw(0.05, 0.08, 0.1, 1, 300, -1.3, -2.3, -2.3)==0, msg="Probability should be zero as M < M0")

        self.assertTrue(
            three_part_powerlaw(0.05, 0.08, 0.1, 1, 300, -1.3, -2.3, -2.3) == 0,
            msg="Probability should be zero as M < M0",
        )

    def test_Kroupa2001(self):
        """
@@ -152,8 +154,10 @@ class TestDistributions(unittest.TestCase):
        for i in range(len(python_results)):
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance)
        # Extra tests:
        self.assertEqual(Kroupa2001(10, newopts={'mmax': 300}), three_part_powerlaw(10, 0.1, 0.5, 1, 300, -1.3, -2.3, -2.3))

        self.assertEqual(
            Kroupa2001(10, newopts={"mmax": 300}),
            three_part_powerlaw(10, 0.1, 0.5, 1, 300, -1.3, -2.3, -2.3),
        )

    def test_ktg93(self):
        """
@@ -177,8 +181,10 @@ class TestDistributions(unittest.TestCase):
        for i in range(len(python_results)):
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance)
        # extra test:
        self.assertEqual(ktg93(10, newopts={'mmax': 300}), three_part_powerlaw(10, 0.1, 0.5, 1, 300, -1.3, -2.2, -2.7))

        self.assertEqual(
            ktg93(10, newopts={"mmax": 300}),
            three_part_powerlaw(10, 0.1, 0.5, 1, 300, -1.3, -2.2, -2.7),
        )

    def test_imf_tinsley1980(self):
        """
@@ -186,7 +192,10 @@ class TestDistributions(unittest.TestCase):
        """

        m = 1.2
        self.assertEqual(imf_tinsley1980(m), three_part_powerlaw(m, 0.1, 2.0, 10.0, 80.0, -2.0, -2.3, -3.3))
        self.assertEqual(
            imf_tinsley1980(m),
            three_part_powerlaw(m, 0.1, 2.0, 10.0, 80.0, -2.0, -2.3, -3.3),
        )

    def test_imf_scalo1986(self):
        """
@@ -194,8 +203,10 @@ class TestDistributions(unittest.TestCase):
        """

        m = 1.2
        self.assertEqual(imf_scalo1986(m), three_part_powerlaw(m, 0.1, 1.0, 2.0, 80.0, -2.35, -2.35, -2.70))

        self.assertEqual(
            imf_scalo1986(m),
            three_part_powerlaw(m, 0.1, 1.0, 2.0, 80.0, -2.35, -2.35, -2.70),
        )

    def test_imf_scalo1998(self):
        """
@@ -203,8 +214,10 @@ class TestDistributions(unittest.TestCase):
        """

        m = 1.2
        self.assertEqual(imf_scalo1998(m), three_part_powerlaw(m, 0.1, 1.0, 10.0, 80.0, -1.2, -2.7, -2.3))

        self.assertEqual(
            imf_scalo1998(m),
            three_part_powerlaw(m, 0.1, 1.0, 10.0, 80.0, -1.2, -2.7, -2.3),
        )

    def test_imf_chabrier2003(self):
        """
@@ -216,11 +229,19 @@ class TestDistributions(unittest.TestCase):

        # for m=0.5
        m = 0.5
        self.assertLess(np.abs(imf_chabrier2003(m)-0.581457346702825), self.tolerance, msg="Difference is bigger than the tolerance")
        self.assertLess(
            np.abs(imf_chabrier2003(m) - 0.581457346702825),
            self.tolerance,
            msg="Difference is bigger than the tolerance",
        )

        # For m = 2
        m = 2
        self.assertLess(np.abs(imf_chabrier2003(m)-0.581457346702825), self.tolerance, msg="Difference is bigger than the tolerance")
        self.assertLess(
            np.abs(imf_chabrier2003(m) - 0.581457346702825),
            self.tolerance,
            msg="Difference is bigger than the tolerance",
        )

    def test_duquennoy1991(self):
        """
@@ -229,7 +250,6 @@ class TestDistributions(unittest.TestCase):

        self.assertEqual(duquennoy1991(4.2), gaussian(4.2, 4.8, 2.3, -2, 12))


    def test_gaussian(self):
        """
        unittest for three_part_power_law
@@ -253,7 +273,10 @@ class TestDistributions(unittest.TestCase):
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance)

        # Extra test:
        self.assertTrue(gaussian(15, 4.8, 2.3, -2.0, 12.0)==0, msg="Probability should be 0 because the input period is out of bounds")
        self.assertTrue(
            gaussian(15, 4.8, 2.3, -2.0, 12.0) == 0,
            msg="Probability should be 0 because the input period is out of bounds",
        )

    def test_Arenou2010_binary_fraction(self):
        """
+168 −108

File changed.

Preview size limit exceeded, changes collapsed.

+316 −17

File changed.

Preview size limit exceeded, changes collapsed.

+7 −7
Original line number Diff line number Diff line
@@ -49,25 +49,25 @@ class test_grid_options_defaults(unittest.TestCase):
        self.assertTrue(isinstance(output_1, int))
        self.assertTrue(output_1 > 0)



    def test_write_grid_options_to_rst_file(self):
        """
        Unit tests for the grid_options_description_checker function
        """

        input_1 = os.path.join(binary_c_temp_dir, "test_write_grid_options_to_rst_file_1.txt")
        input_1 = os.path.join(
            binary_c_temp_dir, "test_write_grid_options_to_rst_file_1.txt"
        )
        output_1 = write_grid_options_to_rst_file(input_1)
        self.assertIsNone(output_1)


        input_2 = os.path.join(binary_c_temp_dir, "test_write_grid_options_to_rst_file_2.rst")
        input_2 = os.path.join(
            binary_c_temp_dir, "test_write_grid_options_to_rst_file_2.rst"
        )
        output_2 = write_grid_options_to_rst_file(input_2)

        self.assertTrue(os.path.isfile(input_2))



write_grid_options_to_rst_file
if __name__ == "__main__":
    unittest.main()
+39 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading