def test__get_rand_with_random_state_with_state(): random_state = check_random_state(123) hp = HyperRangeInt(0, 2, random_state=random_state) assert len(set([hp.get_rand() for _ in range(10)])) > 1 # different values assert len(set([_get_rand(["a", "b", "c"], random_state=random_state) for _ in range(10)])) > 1 assert len(set([_get_rand(randint(1, 3), random_state=random_state) for _ in range(10)])) > 1
def test_addition_HyperCrossProduct(): ###################################################### ### Test 1 : HyperCrossProduct + HyperCrossProduct ### ###################################################### hh1 = HyperCrossProduct({"a": [0, 1, 2], "c": HyperLogRangeFloat(0.01, 1)}) hh2 = HyperCrossProduct({ "d": ["aaaa", "bbb", None], "e": HyperRangeInt(0, 100) }) # hh12 = hh1 + hh2 assert isinstance(hh12, HyperCrossProduct) res = [hh12.get_rand() for _ in range(10)] for r in res: assert isinstance(r, dict) assert set(r.keys()) == set(("a", "c", "d", "e")) assert r["a"] in (0, 1, 2) assert r["d"] in ("aaaa", "bbb", None) ######################################### ### Test 2 : HyperCrossProduct + dict ### ######################################### hh1 = HyperCrossProduct({"a": [0, 1, 2], "c": HyperLogRangeFloat(0.01, 1)}) hh2 = {"d": ["aaaa", "bbb", None], "e": HyperRangeInt(0, 100)} hh12 = hh1 + hh2 assert isinstance(hh12, HyperCrossProduct) res = [hh12.get_rand() for _ in range(10)] for r in res: assert isinstance(r, dict) assert set(r.keys()) == set(("a", "c", "d", "e")) assert r["a"] in (0, 1, 2) assert r["d"] in ("aaaa", "bbb", None) ######################################### ### Test 3 : HyperCrossProduct update ### ######################################### hh1 = HyperCrossProduct({"a": [0, 1, 2], "c": HyperLogRangeFloat(0.01, 1)}) hh2 = {"a": [10, 11, 12], "e": HyperRangeInt(0, 100)} # 'a' will be updated hh12 = hh1 + hh2 assert isinstance(hh12, HyperCrossProduct) res = [hh12.get_rand() for _ in range(10)] for r in res: assert isinstance(r, dict) assert set(r.keys()) == set(("a", "c", "e")) assert r["a"] in (10, 11, 12) assert r["a"] not in (0, 1, 2)
def test_HyperRangeBetaInt(): hp = HyperRangeInt(10, 100, random_state=123) all_x = [] for _ in range(100): x = hp.get_rand() assert isinstance(x, int) assert x >= 10 assert x <= 100 all_x.append(x) assert len(set(all_x)) > 1
def test_HyperRangeInt(): hp = HyperRangeInt(10, 100, step=10, random_state=123) possible_choices = set([10 * (i + 1) for i in range(10)]) all_x = [] for _ in range(100): x = hp.get_rand() assert isinstance(x, int) assert x >= 10 assert x <= 100 assert x in possible_choices all_x.append(x) assert len(set(all_x)) > 1 # I don't want always the same value
def test__get_rand_with_random_state_with_seed(): hp = HyperRangeInt(0, 2) # Verif returns always the same in the case where random_state is fixed assert len(set([_get_rand(hp, random_state=123) for _ in range(10)])) == 1 assert len(set([_get_rand(["a", "b", "c"], random_state=123) for _ in range(10)])) == 1 assert len(set([_get_rand(randint(1, 3), random_state=123) for _ in range(10)])) == 1
def klass(random_state): return HyperCrossProduct( { "int_value": HyperRangeInt(0, 10), "float_value": HyperRangeFloat(0, 1) }, random_state=random_state)
def test__get_rand(): hp = HyperRangeInt(0, 2, random_state=123) assert _get_rand(hp) in (0, 1, 2) assert _get_rand(["a", "b", "c"]) in ("a", "b", "c") assert _get_rand(1) == 1 assert _get_rand(randint(1, 3)) in (1, 2)
def klass(random_state): return HyperCrossProduct([HyperRangeInt(0, 10), HyperRangeFloat(0, 1)], random_state=random_state)
def klass(random_state): return HyperComposition( [(0.9, HyperRangeInt(0, 100)), (0.1, HyperRangeInt(200, 1000))], random_state=random_state )
def klass(random_state): return HyperComposition([HyperRangeInt(0, 100), HyperRangeInt(200, 1000)], random_state=random_state)
def klass(random_state): return HyperListOfDifferentSizes( nb_distrib=HyperRangeInt(1, 5), value_distrib=HyperRangeInt(50, 150), random_state=random_state )