diff --git a/tests/test_core.py b/tests/test_core.py index ddf08ea..95aeab4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2,6 +2,7 @@ from numpy.testing import assert_raises +from jax_cosmo import Configuration from jax_cosmo import Cosmology @@ -21,6 +22,13 @@ def test_Cosmology_immutability(): cosmo.h = 0.74 # Hubble doesn't budge on the tension +def test_Conguration_immutability(): + config = Configuration() + + with assert_raises(FrozenInstanceError): + config.log10_a_max = 0.0 + + def test_cache(): cosmo = Cosmology( Omega_c=0.25, @@ -33,21 +41,22 @@ def test_cache(): wa=0.0, ) + def assert_pure(c1, c2): + assert c1 is not c2 and c1 == c2 and c1._cache != c2._cache + cosmo = cosmo.cache_set("a", 1) cosmo = cosmo.cache_set("c", 3) + assert cosmo.is_cached("a") assert not cosmo.is_cached("b") assert cosmo.cache_get("c") == 3 - cosmo = cosmo.cache_set("b", 2) - cosmo_no_c = cosmo.cache_del("c") - assert cosmo.is_cached("b") - assert not cosmo_no_c.is_cached("c") - assert ( - cosmo_no_c is not cosmo - and cosmo_no_c == cosmo - and cosmo_no_c._cache != cosmo._cache - ) + cosmo_add_b = cosmo.cache_set("b", 2) + cosmo_del_c = cosmo.cache_del("c") + cosmo_clean = cosmo.cache_clear() - cosmo = cosmo.cache_clear() - assert len(cosmo._cache) == 0 + assert not cosmo_del_c.is_cached("c") + assert_pure(cosmo_add_b, cosmo) # test set purity + assert_pure(cosmo_del_c, cosmo) # test del purity + assert_pure(cosmo_clean, cosmo) # test clear purity + assert len(cosmo_clean._cache) == 0