Skip to content
Snippets Groups Projects
Commit bbbc2bb2 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Various minor improvements to the testing

parent 49ae2bc9
No related branches found
No related tags found
1 merge request!361Various minor improvements to the testing
Pipeline #49357 passed
......@@ -31,6 +31,18 @@ class TestLikelihoodBase(unittest.TestCase):
def test_base_log_likelihood_ratio(self):
self.assertTrue(np.isnan(self.likelihood.log_likelihood_ratio()))
def test_meta_data_unset(self):
self.assertEqual(self.likelihood.meta_data, None)
def test_meta_data_set_fail(self):
with self.assertRaises(ValueError):
self.likelihood.meta_data = 10
def test_meta_data(self):
meta_data = dict(x=1, y=2)
self.likelihood.meta_data = meta_data
self.assertEqual(self.likelihood.meta_data, meta_data)
class TestAnalytical1DLikelihood(unittest.TestCase):
......
......@@ -4,7 +4,7 @@ import unittest
from mock import Mock
import numpy as np
import os
import shutil
import copy
from collections import OrderedDict
......@@ -130,6 +130,7 @@ class TestPriorClasses(unittest.TestCase):
bilby.core.prior.Gaussian(name='test', unit='unit', mu=0, sigma=1),
bilby.core.prior.Normal(name='test', unit='unit', mu=0, sigma=1),
bilby.core.prior.PowerLaw(name='test', unit='unit', alpha=0, minimum=0, maximum=1),
bilby.core.prior.PowerLaw(name='test', unit='unit', alpha=-1, minimum=0.5, maximum=1),
bilby.core.prior.PowerLaw(name='test', unit='unit', alpha=2, minimum=1, maximum=1e2),
bilby.core.prior.Uniform(name='test', unit='unit', minimum=0, maximum=1),
bilby.core.prior.LogUniform(name='test', unit='unit', minimum=5e0, maximum=1e2),
......@@ -205,6 +206,28 @@ class TestPriorClasses(unittest.TestCase):
outside_domain = np.linspace(prior.minimum - 1e4, prior.minimum - 1, 1000)
self.assertTrue(all(prior.prob(outside_domain) == 0))
def test_prob_and_ln_prob(self):
for prior in self.priors:
sample = prior.sample()
self.assertAlmostEqual(np.log(prior.prob(sample)), prior.ln_prob(sample), 12)
def test_log_normal_fail(self):
with self.assertRaises(ValueError):
bilby.core.prior.LogNormal(name='test', unit='unit', mu=0, sigma=-1)
def test_studentt_fail(self):
with self.assertRaises(ValueError):
bilby.core.prior.StudentT(name='test', unit='unit', df=3, mu=0, scale=-1)
with self.assertRaises(ValueError):
bilby.core.prior.StudentT(name='test', unit='unit', df=0, mu=0, scale=1)
def test_beta_fail(self):
with self.assertRaises(ValueError):
bilby.core.prior.Beta(name='test', unit='unit', alpha=-2.0, beta=2.0),
with self.assertRaises(ValueError):
bilby.core.prior.Beta(name='test', unit='unit', alpha=2.0, beta=-2.0),
def test_probability_in_domain(self):
"""Test that the prior probability is non-negative in domain of validity and zero outside."""
for prior in self.priors:
......@@ -319,6 +342,15 @@ class TestPriorDict(unittest.TestCase):
del self.default_prior_file
del self.prior_set_from_file
def test_copy(self):
priors = bilby.core.prior.PriorDict(self.priors)
self.assertEqual(priors, priors.copy())
def test_prior_set(self):
priors_dict = bilby.core.prior.PriorDict(self.priors)
priors_set = bilby.core.prior.PriorSet(self.priors)
self.assertEqual(priors_dict, priors_set)
def test_prior_set_is_ordered_dict(self):
self.assertIsInstance(self.prior_set_from_dict, OrderedDict)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment