diff --git a/tests.py b/tests.py index 2d6d6874bda5bcbd1441589d48d47b6295988b5c..088fa0323a2760049647339686fb9b11c2d487c4 100644 --- a/tests.py +++ b/tests.py @@ -64,30 +64,122 @@ if __name__ == '__main__': unittest.main() -class TestParameterInstantiation(unittest.TestCase): +class TestParameterInstantiationWithoutOptionalParameters(unittest.TestCase): + def setUp(self): - self.parameter = None + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) def tearDown(self): del self.parameter - def test_instantiation_without_optional_parameters(self): - test_name = 'test_name' - self.parameter = peyote.parameter.Parameter(test_name) - self.assertEqual(self.parameter.name, test_name) + def test_name(self): + self.assertEqual(self.parameter.name, self.test_name) + + def test_prior(self): self.assertIsNone(self.parameter.prior) + + def test_value(self): self.assertTrue(np.isnan(self.parameter.value)) - self.assertEqual(self.parameter.latex_label, test_name) + + def test_latex_label(self): + self.assertEqual(self.parameter.latex_label, self.test_name) + + def test_is_fixed(self): self.assertFalse(self.parameter.is_fixed) - def test_instantiation_with_defined_prior(self): - test_name = 'test_name' - prior = peyote.prior.Uniform(0, 100) - self.parameter = peyote.parameter.Parameter(test_name, prior) - self.assertEqual(self.parameter.name, test_name) - self.assertIsNone(self.parameter.prior) + +class TestParameterName(unittest.TestCase): + + def setUp(self): + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) + + def tearDown(self): + del self.parameter + + def test_name_assignment(self): + self.parameter.name = "other_name" + self.assertEqual(self.parameter.name, "other_name") + + +class TestParameterPrior(unittest.TestCase): + + def setUp(self): + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) + + def tearDown(self): + del self.parameter + + def test_prior_assignment(self): + test_prior = peyote.prior.Uniform(0, 100) + self.parameter.prior = test_prior + self.assertDictEqual(test_prior.__dict__, self.parameter.prior.__dict__) + + def test_default_assignment(self): + test_prior = peyote.prior.PowerLaw(alpha=0, bounds=(5, 100)) + self.parameter.name = 'mchirp' + self.parameter.prior = None + self.assertDictEqual(test_prior.__dict__, self.parameter.prior.__dict__) + + +class TestParameterValue(unittest.TestCase): + def setUp(self): + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) + + def tearDown(self): + del self.parameter + + def test_prior_assignment(self): + test_value = 15 + self.parameter.value = test_value + self.assertEqual(test_value, self.parameter.value) + + def test_default_value_assignment(self): + self.parameter.name = 'a1' + self.parameter.value = None + self.assertEqual(self.parameter.value, 0) + + def test_default_value_assignment_default(self): + self.parameter.value = None self.assertTrue(np.isnan(self.parameter.value)) - self.assertEqual(self.parameter.latex_label, test_name) - self.assertFalse(self.parameter.is_fixed) +class TestParameterLatexLabel(unittest.TestCase): + def setUp(self): + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) + + def tearDown(self): + del self.parameter + + def test_label_assignment(self): + test_label = 'test_label' + self.parameter.latex_label = 'test_label' + self.assertEqual(test_label, self.parameter.latex_label) + + def test_default_label_assignment(self): + self.parameter.name = 'mchirp' + self.parameter.latex_label = None + self.assertEqual(self.parameter.latex_label, '$\mathcal{M}$') + + def test_default_label_assignment_default(self): + self.assertTrue(self.parameter.latex_label, self.parameter.name) + + +class TestParameterIsFixed(unittest.TestCase): + def setUp(self): + self.test_name = 'test_name' + self.parameter = peyote.parameter.Parameter(self.test_name) + + def tearDown(self): + del self.parameter + + def test_is_fixed_assignment(self): + self.parameter.is_fixed = True + self.assertTrue(self.parameter.is_fixed) + + def test_default_is_fixed_assignment(self): + self.assertFalse(self.parameter.is_fixed) \ No newline at end of file