def test_integer(): a = Integer(1, 10) for i in range(50): r = a.rvs(random_state=i) assert 1 <= r assert 11 >= r assert r in a random_values = a.rvs(random_state=0, n_samples=10) assert_array_equal(random_values.shape, (10)) assert_array_equal(a.transform(random_values), random_values) assert_array_equal(a.inverse_transform(random_values), random_values)
def test_normalize_integer(): a = Integer(2, 30, transform="normalize") for i in range(50): check_limits(a.rvs(random_state=i), 2, 30) assert_array_equal(a.transformed_bounds, (0, 1)) rng = np.random.RandomState(0) X = rng.randint(2, 31, dtype=np.int64) # Check transformed values are in [0, 1] assert np.all(a.transform(X) <= np.ones_like(X)) assert np.all(np.zeros_like(X) <= a.transform(X)) # Check inverse transform X_orig = a.inverse_transform(a.transform(X)) assert isinstance(X_orig, np.int64) assert_array_equal(X_orig, X) a = Integer(2, 30, transform="normalize", dtype=int) X = rng.randint(2, 31, dtype=int) # Check inverse transform X_orig = a.inverse_transform(a.transform(X)) assert isinstance(X_orig, int) a = Integer(2, 30, transform="normalize", dtype="int") X = rng.randint(2, 31, dtype=int) # Check inverse transform X_orig = a.inverse_transform(a.transform(X)) assert isinstance(X_orig, int) a = Integer(2, 30, prior="log-uniform", base=2, transform="normalize", dtype=int) for i in range(50): check_limits(a.rvs(random_state=i), 2, 30) assert_array_equal(a.transformed_bounds, (0, 1)) X = rng.randint(2, 31, dtype=int) # Check transformed values are in [0, 1] assert np.all(a.transform(X) <= np.ones_like(X)) assert np.all(np.zeros_like(X) <= a.transform(X)) # Check inverse transform X_orig = a.inverse_transform(a.transform(X)) assert isinstance(X_orig, int) assert_array_equal(X_orig, X)