def test_set_worstfactor(self): fit = FitnessLinearRanking(self.fitness_list, .6) self.assertAlmostEqual(0.6, fit._worstfactor) fit.set_worstfactor(.7) self.assertAlmostEqual(.7, fit._worstfactor) self.assertRaises(ValueError, fit.set_worstfactor, -.1) self.assertRaises(ValueError, fit.set_worstfactor, 2.1)
def test_set_worstfactor(self): fit = FitnessLinearRanking(self.fitness_list, 0.6) self.assertAlmostEqual(0.6, fit._worstfactor) fit.set_worstfactor(0.7) self.assertAlmostEqual(0.7, fit._worstfactor) self.assertRaises(ValueError, fit.set_worstfactor, -0.1) self.assertRaises(ValueError, fit.set_worstfactor, 2.1)
def test_linear_ranking(self): pass fit = FitnessLinearRanking(self.fitness_list, .6) prob_list = fit._linear_ranking(3, .6) self.assertAlmostEqual(0.199999999, prob_list[0]) self.assertAlmostEqual(0.333333333, prob_list[1]) self.assertAlmostEqual(0.466666666, prob_list[2]) self.assertLessEqual(prob_list[0], prob_list[1]) self.assertLessEqual(prob_list[1], prob_list[2]) self.assertAlmostEqual(1.0, sum(prob_list)) prob_list = fit._linear_ranking(3, .2) self.assertAlmostEqual(0.06666667, prob_list[0]) self.assertAlmostEqual(0.33333333, prob_list[1]) self.assertAlmostEqual(0.6, prob_list[2]) self.assertLessEqual(prob_list[0], prob_list[1]) self.assertLessEqual(prob_list[1], prob_list[2]) self.assertAlmostEqual(1.0, sum(prob_list))
def test_linear_ranking(self): pass fit = FitnessLinearRanking(self.fitness_list, 0.6) prob_list = fit._linear_ranking(3, 0.6) self.assertAlmostEqual(0.199999999, prob_list[0]) self.assertAlmostEqual(0.333333333, prob_list[1]) self.assertAlmostEqual(0.466666666, prob_list[2]) self.assertLessEqual(prob_list[0], prob_list[1]) self.assertLessEqual(prob_list[1], prob_list[2]) self.assertAlmostEqual(1.0, sum(prob_list)) prob_list = fit._linear_ranking(3, 0.2) self.assertAlmostEqual(0.06666667, prob_list[0]) self.assertAlmostEqual(0.33333333, prob_list[1]) self.assertAlmostEqual(0.6, prob_list[2]) self.assertLessEqual(prob_list[0], prob_list[1]) self.assertLessEqual(prob_list[1], prob_list[2]) self.assertAlmostEqual(1.0, sum(prob_list))
def test_select(self): fit = FitnessLinearRanking(self.fitness_list, .6) count = len([i for i in fit.select()]) self.assertEqual(3, count)
def test_classinit_(self): fit = FitnessLinearRanking(self.fitness_list, .6) self.assertAlmostEqual(0.6, fit._worstfactor)
def test_select(self): fit = FitnessLinearRanking(self.fitness_list, 0.6) count = len([i for i in fit.select()]) self.assertEqual(3, count)