def test_Int():
    rg = hp_module.Int("rg", min_value=5, max_value=9, step=1, default=6)
    rg = hp_module.Int.from_config(rg.get_config())
    assert rg.default == 6
    assert 5 <= rg.random_sample() <= 9
    assert isinstance(rg.random_sample(), int)
    assert rg.random_sample(123) == rg.random_sample(123)
    # No default
    rg = hp_module.Int("rg", min_value=5, max_value=9, step=1)
    assert rg.default == 5
def test_sampling_arg():
    f = hp_module.Float("f", 1e-20, 1e10, sampling="log")
    f = hp_module.Float.from_config(f.get_config())
    assert f.sampling == "log"

    i = hp_module.Int("i", 0, 10, sampling="linear")
    i = hp_module.Int.from_config(i.get_config())
    assert i.sampling == "linear"

    with pytest.raises(ValueError, match="`sampling` must be one of"):
        hp_module.Int("j", 0, 10, sampling="invalid")

    with pytest.raises(
            ValueError,
            match="`sampling` `min_value` 1 is greater than the `max_value` 0",
    ):
        hp_module.Int("k", 1, 0, sampling="linear")

    with pytest.raises(
            ValueError,
            match="`sampling` `min_value` 1 is greater than the `max_value` 0",
    ):
        hp_module.Int("k", 1, 0, sampling="linear")
def test_int_proto():
    hp = hp_module.Int("a", 1, 100, sampling="log")
    proto = hp.to_proto()
    assert proto.name == "a"
    assert proto.min_value == 1
    assert proto.max_value == 100
    assert proto.sampling == keras_tuner_pb2.Sampling.LOG
    # Proto stores the implicit default.
    assert proto.default == 1
    assert proto.step == 1

    new_hp = hp_module.Int.from_proto(proto)
    assert new_hp._default == 1
    # Pop the implicit default for comparison purposes.
    new_hp._default = None
    assert new_hp.get_config() == hp.get_config()