class MutationTest(unittest.TestCase): def setUp(self): self.simplex = Simplex() def test_reflect(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) reflected = self.simplex.reflect(worst, centroid, alpha=2) self.assertTrue(np.all(reflected == np.array([4, 4]))) def test_reflect_default_alpha_is_1(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) reflected = self.simplex.reflect(worst, centroid) self.assertTrue(np.all(reflected == np.array([3, 3]))) def test_expand(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) expanded = self.simplex.expand(worst, centroid, gamma=3) self.assertTrue(np.all(expanded == np.array([5, 5]))) def test_expand_default_gamma_is_2(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) expanded = self.simplex.expand(worst, centroid) self.assertTrue(np.all(expanded == np.array([4, 4]))) def test_contract(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) contracted = self.simplex.contract(worst, centroid, rho=-0.3) self.assertTrue(np.all(contracted == np.array([1.7, 1.7]))) def test_contract_default_rho_is_negative_half(self): worst = np.array([1, 1]) centroid = np.array([2, 2]) contracted = self.simplex.contract(worst, centroid) self.assertTrue(np.all(contracted == np.array([1.5, 1.5]))) def test_reduce(self): best = np.array([1, 1]) other = np.array([2, 2]) reduced = self.simplex.reduce(best, other) self.assertTrue(np.all(reduced == np.array([1.5, 1.5]))) def test_reduce_default_sigma_is_one_half(self): best = np.array([1, 1]) other = np.array([2, 2]) reduced = self.simplex.reduce(best, other, sigma=0.3) self.assertTrue(np.all(reduced == np.array([1.3, 1.3])))