Commit c590f136 authored by moritz's avatar moritz
Browse files

Moritz Huebner: Added tests for the Parameter class and moved them into a separate file

parent dd09802b
Pipeline #15877 passed with stages
in 3 minutes and 5 seconds
import peyote
import unittest
import numpy as np
class TestParameterInstantiationWithoutOptionalParameters(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(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))
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)
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))
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)
......@@ -64,122 +64,3 @@ if __name__ == '__main__':
unittest.main()
class TestParameterInstantiationWithoutOptionalParameters(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(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))
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)
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))
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment