def test_should_the_solution_change_if_the_probability_is_one(self): operator = SimpleRandom(1.0) solution = FloatSolution(3, 1, 0, [-5, -5, -5], [5, 5, 5]) solution.variables = [1.0, 2.0, 3.0] mutated_solution = operator.execute(solution) self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
def test_should_the_solution_change_between_max_and_min_value(self): operator = SimpleRandom(1.0) solution = FloatSolution(4, 1, 0, [-1, 12, -3, -5], [1, 17, 3, -2]) solution.variables = [-7.0, 3.0, 12.0, 13.4] mutated_solution = operator.execute(solution) for i in range(solution.number_of_variables): self.assertGreaterEqual(mutated_solution.variables[i], solution.lower_bound[i]) self.assertLessEqual(mutated_solution.variables[i], solution.upper_bound[i])
def test_should_constructor_raise_an_exception_if_the_probability_is_lower_than_zero(self): with self.assertRaises(Exception): SimpleRandom(-12)
def test_should_constructor_raise_an_exception_if_the_probability_is_greater_than_one(self): with self.assertRaises(Exception): SimpleRandom(2)
def test_should_constructor_create_a_valid_operator(self): operator = SimpleRandom(0.5) self.assertEqual(0.5, operator.probability)
def test_should_constructor_create_a_non_null_object(self): operator = SimpleRandom(1.0) self.assertIsNotNone(operator)