def test_sort_by_total(self): sol_list = [vv.Solution([1, 0, 1, 1, 0], []), vv.Solution([2, 0, 0, 0, 0], []), vv.Solution([0, 1, 0, 0, 5], [])] ss = vv.Solution_Set(sol_list) ss.sort_by_total() sums = [sum(s.recipes_achieved) for s in ss] self.assertEqual(sums, [6, 3, 2])
def test_add_solution_to_set(self): sol_list = [vv.Solution([1, 0, 0, 0, 0], []), vv.Solution([2, 0, 0, 0, 0], []), vv.Solution([0, 1, 0, 0, 0], [])] ss = vv.Solution_Set(sol_list) ss.add_solution_to_set(vv.Solution([0, 1, 0, 0, 0], [])) ss.add_solution_to_set(vv.Solution([2, 1, 0, 0, 0], [])) ss.add_solution_to_set(vv.Solution([0, 0, 1, 0, 0], [])) self.assertTrue(len(ss.solutions) == 2)
def test_add_move(self): s = vv.Solution() s.add_move((4, 3)) s.add_move((4, 2), 0) self.assertTrue(s.recipes_achieved[0] == 1) self.assertTrue(len(s.moves) == 2)
def test_constructor(self): s = vv.Solution() s = vv.Solution([], [(4, 3)])
def test_exclude_dominated_solutions(self): sol_list = [vv.Solution([1, 0, 0, 0, 0], []), vv.Solution([2, 0, 0, 0, 0], []), vv.Solution([0, 1, 0, 0, 0], [])] ss = vv.Solution_Set(sol_list) self.assertTrue(len(ss.solutions) == 2)
def test_copy(self): s = vv.Solution([], [(1, 2)]) s2 = s.copy() s2.add_move((2, 2)) self.assertTrue(len(s.moves) == 1) self.assertTrue(len(s2.moves) == 2)
def test_theo_solve_puzzle(self): p = vv.Puzzle( np.array([[1, 0, 5, 0, 0], [5, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]), [1, 0, 0, 0, 0]) solutions = vv.theo_solve_puzzle(p, vv.Solution(), vv.Solution_Set()) self.assertTrue(solutions[0].recipes_achieved == [1, 0, 0, 0, 0])