Exemplo n.º 1
0
    def test_perturb_int_factor(self, factor):
        explore = PerturbExplore(factor=factor)

        rng = RNGStub()
        rng.random = lambda: 1.0

        assert explore.perturb_int(rng, 5,
                                   (0, 10)) == int(numpy.round(5 * factor))

        rng.random = lambda: 0.0

        assert explore.perturb_int(rng, 5,
                                   (0, 10)) == int(numpy.round(5 / factor))
Exemplo n.º 2
0
    def test_perturb_int_no_out_of_bounds(self):
        explore = PerturbExplore(factor=0.75, volatility=0)

        rng = RNGStub()

        rng.random = lambda: 1.0
        rng.normal = lambda mean, variance: variance

        assert explore.perturb_int(rng, 0, (0, 10)) == 0

        rng.random = lambda: 0.0
        rng.normal = lambda mean, variance: variance

        assert explore.perturb_int(rng, 10, (0, 10)) == 10
Exemplo n.º 3
0
    def test_perturb_int_no_duplicate_below(self):
        explore = PerturbExplore(factor=0.75)

        rng = RNGStub()
        rng.random = lambda: 1.0

        assert explore.perturb_int(rng, 1, (0, 10)) == 0
Exemplo n.º 4
0
    def test_perturb_int_duplicate_equal(self):
        explore = PerturbExplore(factor=1.0)

        rng = RNGStub()
        rng.random = lambda: 1.0

        assert explore.perturb_int(rng, 1, (0, 10)) == 1