def test_griewank(self): """Test the griewank benchmark.""" griewank = Utility().get_benchmark('griewank') fun = griewank.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array), 0.0)
def test_rastrigin(self): """Test the rastrigin benchmark.""" rastrigin = Utility().get_benchmark('rastrigin') fun = rastrigin.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array), 0.0)
def test_rosenbrock(self): """Test the rosenbrock benchmark.""" rosenbrock = Utility().get_benchmark('rosenbrock') fun = rosenbrock.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array2), 0.0)
def test_step3(self): """Test the step3 benchmark.""" step3 = Utility().get_benchmark('step3') fun = step3.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array), 0.0)
def test_stepint(self): """Test the stepint benchmark.""" stepint = Utility().get_benchmark('stepint') fun = stepint.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array9), 25.0 - 6 * self.D)
def test_sumSquares(self): """Test the sum squares benchmark.""" sumSquares = Utility().get_benchmark('sumSquares') fun = sumSquares.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array), 0.0)
def test_styblinskiTang(self): """Test the styblinski tang benchmark.""" styblinskiTang = Utility().get_benchmark('styblinskiTang') fun = styblinskiTang.function() self.assertTrue(callable(fun)) self.assertAlmostEqual(fun(2, self.array4), -78.332, places=3)
def test_whitley(self): """Test the whitley benchmark.""" whitley = Utility().get_benchmark('whitley') fun = whitley.function() self.assertTrue(callable(fun)) self.assertEqual(fun(self.D, self.array2), 0.0)
class UtilityTestCase(TestCase): def setUp(self): self.u = Utility() def test_get_bad_benchmark_fine(self): self.assertRaises(TypeError, lambda: self.u.get_benchmark('hihihihihihihihihi')) self.assertRaises(TypeError, lambda: self.u.get_benchmark(MyBenchmark)) self.assertRaises(TypeError, lambda: self.u.get_benchmark(NoLimits))
def assertBounds(self, bench, lower, upper): """Checking the bounds. Arguments: bench [Benchmark]: Benchmark to test. lower [float]: Lower bound. upper [type]: Upper bound. Returns: [fun]: Returns benchmarks evaluation function. """ b = Utility().get_benchmark(bench) self.assertEqual(b.Lower, lower) self.assertEqual(b.Upper, upper) return b.function()
def setUp(self): self.u = Utility()