def test_sample_constant(self): """If constant_value is set, all the sample have the same value.""" # Setup instance = KDEUnivariate() instance.fitted = True instance.constant_value = 3 instance._replace_constant_methods() expected_result = np.array([3, 3, 3, 3, 3]) # Run result = instance.sample(5) # Check compare_nested_iterables(result, expected_result)
def test_sample_random_state(self): """If random_state is set, samples will generate the exact same values.""" # Setup instance = KDEUnivariate(random_seed=0) X = np.array([1, 2, 3, 4, 5]) instance.fit(X) expected_result_random_state = np.array( [[5.02156389, 5.45857107, 6.12161148, 4.56801267, 6.14017901]]) # Run result = instance.sample(5) # Check compare_nested_iterables(result, expected_result_random_state)
def test_sample(self, kde_mock): """When fitted, we are able to use the model to get samples.""" # Setup model_mock = kde_mock.return_value model_mock.resample.return_value = np.array([0, 1, 0, 1, 0]) instance = KDEUnivariate() X = np.array([1, 2, 3, 4, 5]) instance.fit(X) expected_result = np.array([0, 1, 0, 1, 0]) # Run result = instance.sample(5) # Check compare_nested_iterables(result, expected_result) assert instance.model == model_mock kde_mock.assert_called_once_with(X) model_mock.resample.assert_called_once_with(5)