def test_record_raise_error(self): """Test that the method record raises a ``ValueError`` when ``len(trials)`` is different to ``len(scores)``. """ # setup instance = MagicMock() instance.tunable.transform.return_value = np.array([[1, 0]]) # run / assert with self.assertRaises(ValueError): BaseTuner.record(instance, 1, [1, 2])
def test_record_scalar_values(self): """Test that the method record performs an update to ``trials`` and ``scores`` when called with a scalar value. """ # setup instance = MagicMock() instance.trials = np.empty((0, 2), dtype=np.float) instance.raw_scores = np.empty((0, 1), dtype=np.float) instance._trials_set = set() instance.tunable.transform.return_value = np.array([[1, 0]]) # run BaseTuner.record(instance, 1, 0.1) # assert instance.tunable.transform.assert_called_once_with(1) np.testing.assert_array_equal(instance.trials, np.array([[1, 0]])) assert instance._trials_set == set({(1, 0)}) np.testing.assert_array_equal(instance.raw_scores, np.array([0.1])) np.testing.assert_array_equal(instance.scores, np.array([0.1]))
def test_record_list_maximize_false(self): """Test that the method record updates the ``trials`` and ``scores``.""" # setup instance = MagicMock() instance.tunable.transform.return_value = np.array([[1, 0]]) instance.trials = np.empty((0, 2), dtype=np.float) instance._trials_set = set() instance.scores = None instance.maximize = False instance.raw_scores = np.empty((0, 1), dtype=np.float) # run BaseTuner.record(instance, [1], [0.1]) # assert instance.tunable.transform.assert_called_once_with([1]) np.testing.assert_array_equal(instance.trials, np.array([[1, 0]])) assert instance._trials_set == set({(1, 0)}) np.testing.assert_array_equal(instance.raw_scores, np.array([0.1])) np.testing.assert_array_equal(instance.scores, np.array([-0.1]))