def test_solution2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") edges_index = [1, 2, 3, 4, 5, 6] edges = [[0, 1], [1, 2], [2, 3], [3, 0], [0, 5], [5, 1], [2, 6], [3, 6]] distances = [1, 1, 1, 1, 1, 1] solution = [1, 2, 3, 4, 5, 6] try: distance_solution(edges_index, edges, distances, solution) except SolutionException as e: assert "Are you sure?" in str(e) solution = [1, 2, 3, 4, 5, 6, 1, 2] d = distance_solution(edges_index, edges, distances, solution) self.assertEqual(d, len(solution))
def test_eulerian2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") edges_index = [1, 2, 3, 4, 5, 6] edges = [[0, 1], [1, 2], [2, 3], [3, 0], [0, 5], [5, 1], [2, 6], [3, 6]] distances = [1, 1, 1, 1, 1, 1] solution = [1, 2, 3, 4, 5, 6, 1, 2] try: distance_solution(edges_index, edges, distances, solution) except SolutionException as e: if "Some vertices have an odd degree" not in str(e): raise e solution = [1, 2, 3, 4, 5, 6, 1, 2, 2] d = distance_solution(edges_index, edges, distances, solution) path = euler_path(edges_index, edges, solution) self.assertEqual(len(path), d) self.assertEqual(list(sorted(path)), [1, 1, 2, 2, 2, 3, 4, 5, 6])
def test_eulerian(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") edges_index = [1, 2, 3, 4] edges = [[0, 1], [1, 2], [2, 3], [3, 0]] distances = [1, 1, 1, 1] solution = [1, 2, 3, 4] d = distance_solution(edges_index, edges, distances, solution) path = euler_path(edges_index, edges, solution) self.assertEqual(len(path), d) self.assertEqual(list(sorted((path))), [1, 2, 3, 4])
def test_solution1(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") edges_index = [1, 2, 3, 4] edges = [[0, 1], [1, 2], [2, 3], [3, 0]] distances = [1, 1, 1, 1] solution = [1, 2, 3, 4] try: distance_solution(edges_index, edges, distances, [1, 2]) except SolutionException as e: assert "Did you cover" in str(e) try: distance_solution(edges_index, edges, distances, [1, 2, 2, 2]) except SolutionException as e: assert "Did you cover" in str(e) try: distance_solution(edges_index, edges, distances, [1, 2, 3, 0]) except SolutionException as e: assert "is not in edges_index" in str(e) d = distance_solution(edges_index, edges, distances, solution) self.assertEqual(d, 4)