示例#1
0
    def should_return_correct_value_when_used_as_a_callable(self):
        # given
        bounds = BoundingBox([(-2, 3)])
        x = 2.5

        # when
        utility_function = NegativeQuadraticUtilityFunction(bounds=bounds)

        # then
        assert utility_function.evaluate(x) == utility_function(x)
示例#2
0
    def should_return_negative_square_inside_of_domain(self):
        # given
        bounds = BoundingBox([(-2, 3)])
        x = 2.5

        # when
        utility_function = NegativeQuadraticUtilityFunction(bounds=bounds)

        # then
        assert utility_function.evaluate(x) == -(x * x)
示例#3
0
    def should_raise_exception_outside_of_domain(self):
        # given
        bounds = BoundingBox([(-2, 3)])
        x = 5

        # when
        utility_function = NegativeQuadraticUtilityFunction(bounds=bounds)

        # then
        with pytest.raises(ValueError):
            utility_function.evaluate(x)
示例#4
0
    def should_raise_exception_in_higher_dimensions(self):
        # given
        bounds = BoundingBox([(-2, 3), (3, 4)])

        # when, then
        with pytest.raises(ValueError):
            NegativeQuadraticUtilityFunction(bounds=bounds)
示例#5
0
    def should_return_correct_bounds_in_one_dimension(self):
        # given
        bounds = BoundingBox([(-2, 3)])

        # when
        utility_function = NegativeQuadraticUtilityFunction(bounds=bounds)

        # then
        assert utility_function.bounds == bounds
示例#6
0
    def should_return_correct_argmax_on_positive_interval_excluding_zero(self):
        # given
        bounds = BoundingBox([(2, 7)])
        utility_function = NegativeQuadraticUtilityFunction(bounds=bounds)

        # when
        argmax = utility_function.argmax

        # then
        assert argmax == 2