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))
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
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
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