Example #1
0
    def test_perturb_real_factor(self, factor):
        explore = PerturbExplore(factor=factor)

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

        assert explore.perturb_real(rng, 1.0, (0.1, 2.0)) == factor

        rng.random = lambda: 0.0

        assert explore.perturb_real(rng, 1.0, (0.1, 2.0)) == 1.0 / factor
Example #2
0
    def test_perturb_real_above_interval_cap(self):
        explore = PerturbExplore(factor=1.0, volatility=0)

        rng = RNGStub()
        rng.random = lambda: 1.0
        rng.normal = lambda mean, variance: variance

        assert explore.perturb_real(rng, 3.0, (1.0, 2.0)) == 2.0

        explore.volatility = 1000

        assert explore.perturb_real(rng, 3.0, (1.0, 2.0)) == 1.0
Example #3
0
    def test_perturb_real_volatility_above(self, volatility):
        explore = PerturbExplore(factor=1.0, volatility=volatility)

        rng = RNGStub()
        rng.random = lambda: 1.0
        rng.normal = lambda mean, variance: variance

        assert explore.perturb_real(rng, 3.0, (1.0, 2.0)) == 2.0 - volatility