def test_no_prior(self): """Test that giving a null prior defaults prior_name to `None`.""" dim = Dimension('yolo', None) print(dim._prior_name) assert dim.prior is None assert dim._prior_name is 'None'
def test_init_with_default_value(self): """Make sure the __contains__ method does not work""" with pytest.raises(NotImplementedError): Dimension('yolo', 'uniform', -3, 4, default_value=4)
def test_no_default_value(self): """Test that no giving a default value assigns None""" dim = Dimension('yolo', 'uniform', -3, 4) assert dim.default_value is None
def test_contains_shape(self): """Test __contains__ for shape check.""" dim = Dimension(None, 'uniform', -3, 4, shape=(4, 4)) with pytest.raises(NotImplementedError): assert dists.uniform.rvs(-3, 4, size=(4, 4)) in dim
def test_set_bad_name(self): """Try setting a name other than str or None.""" dim = Dimension('yolo', 'uniform', -3, 4, shape=(4, 4)) with pytest.raises(TypeError): dim.name = 4
def test_interval(self): """Test that bounds on variable.""" dim = Dimension('yolo', 'uniform', -3, 4) assert dim.interval(1.0) == ( -3.0, 1.0) # reminder that `scale` is not upper bound
def test_contains_bounds(self): """Test __contains__ for bounds.""" dim = Dimension('yolo', 'uniform', -3, 4) with pytest.raises(NotImplementedError): assert -3 in dim
def test_ban_discrete_kwarg(self): """Do not allow use for 'discrete' kwarg, because now there's `_Discrete`.""" with pytest.raises(ValueError) as exc: Dimension('yolo', 'uniform', -3, 4, shape=(4, 4), discrete=True) assert "pure `_Discrete`" in str(exc.value)
def test_many_samples(self, seed): """More than 1.""" dim = Dimension('yolo', 'uniform', -3, 4, shape=(4, 4)) samples = dim.sample(n_samples=4, seed=seed) assert len(samples) == 4 assert_eq(dists.uniform.rvs(-3, 4, size=(4, 4)), samples[0])
def test_ban_rng_kwarg(self): """Should not be able to use 'random_state' kwarg.""" with pytest.raises(ValueError): Dimension('yolo', 'norm', 0.9, random_state=8)
def test_with_predefined_dist(self, seed): """Use an already defined distribution object as prior arg.""" dim = Dimension('yolo', dists.norm, 0.9) samples = dim.sample(seed=seed) assert len(samples) == 1 assert dists.norm.rvs(0.9) == samples[0]
def test_ban_seed_kwarg(self): """Should not be able to use 'seed' kwarg.""" with pytest.raises(ValueError): Dimension('yolo', 'norm', 0.9, seed=8)
def test_ban_size_kwarg(self): """Should not be able to use 'size' kwarg.""" with pytest.raises(ValueError): Dimension('yolo', 'norm', 0.9, size=(3, 2))
def test_get_prior_string_loguniform(self): """Test that special loguniform prior name is replaced properly.""" dim = Dimension("yolo", "reciprocal", 1e-10, 1) assert dim.get_prior_string() == "loguniform(1e-10, 1)"
def test_get_prior_string_shape(self): """Test that shape is included.""" dim = Dimension("yolo", "alpha", 1, 2, shape=(2, 3)) assert dim.get_prior_string() == "alpha(1, 2, shape=(2, 3))"
def test_get_prior_string_uniform(self): """Test special uniform args are handled properly.""" dim = Dimension("yolo", "uniform", 1, 2) assert dim.get_prior_string() == "uniform(1, 3)"