def test_sample_no_duplicates_more_than_one_loop(self): """Test that the method ``_sample`` returns ``np.ndarray`` when not using duplicates and perfroms more than one iteration. """ # setup instance = MagicMock() instance.tunable = MagicMock(spec_set=Tunable) instance._trials_set = set({(1, ), (2, )}) side_effect = [ np.array([[3]]), np.array([[1]]), np.array([[1]]), np.array([[4]]) ] instance.tunable.sample.side_effect = side_effect # run result = BaseTuner._sample(instance, 2, False) # assert assert instance.tunable.sample.call_args_list == [ call(2), call(2), call(2), call(2) ] np.testing.assert_array_equal(result, np.array([[3], [4]]))
def test__sample_allow_duplicates(self): """Test the method ``_sample``when using duplicates.""" # setup instance = MagicMock() instance.tunable.sample.return_value = 1 # run result = BaseTuner._sample(instance, 1, True) # assert instance.tunable.sample.assert_called_once_with(1) assert result == 1
def test__sample_not_allow_duplicates(self): """Test that the method ``_sample`` returns ``np.ndarray`` when not using duplicates.""" # setup instance = MagicMock() instance._trials_set = set() instance.tunable.sample.return_value = np.array([[3]]) # run result = BaseTuner._sample(instance, 1, False) # assert instance.tunable.sample.assert_called_once_with(1) np.testing.assert_array_equal(result, np.array([[3]]))