Beispiel #1
0
    def test_no_optimum_path(self):
        """
        Tests a board which has no optimum path.
        """
        bd = Board(5, 5)
        coords = [[0, 1], [1, 0], [1, 1]]
        start = [2, 0]
        end = [0, 0]
        ideal_path = None
        weight = 0
        for coord in coords:
            bd.setWeight(coord, weight)
        path = bd.optimumPath(start, end)

        # Confirm returned path is same as ideal path from start to end (inclusive)
        self.assertEqual(ideal_path, path)
Beispiel #2
0
    def test_optimum_path_longer_by_count(self):
        """
        Tests a board which has a shortest path that is shorter than the path by optimal weight.
        Path is expected to be `ideal_path`.
        """
        bd = Board(5, 5)
        coords = [[1, 2], [1, 3], [2, 3], [3, 3], [3, 2]]
        start = [0, 2]
        end = [4, 2]
        ideal_path = [start, [1, 2], [2, 2], [3, 2], end]
        weight = 60
        for coord in coords:
            bd.setWeight(coord, weight)
        path = bd.optimumPath(start, end)

        # Confirm returned path is same as ideal path from start to end (inclusive)
        self.assertEqual(ideal_path, path)
Beispiel #3
0
    def test_optimum_path_many_coords(self):
        """
        Tests a board which has a path obviously much shorter by length, but not as highly weighted.
        Path is expected to be `ideal_path`.
        """
        bd = Board(5, 5)
        coords = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [2, 3], [2, 2], [2, 1]]
        start = [0, 0]
        end = [2, 0]
        ideal_path = [start, [1, 0], end]
        weight = 60
        for coord in coords:
            bd.setWeight(coord, weight)
        path = bd.optimumPath(start, end)

        # Confirm returned path is same as ideal path from start to end (inclusive)
        self.assertEqual(ideal_path, path)
Beispiel #4
0
    def test_optimum_path_by_weight(self):
        """
        Tests a board which has no optimal path by length, but does by weight.
        Path is expected to be `coords`.
        """
        bd = Board(5, 5)
        coords = [[0, 1], [0, 0], [1, 0], [2, 0], [3, 0]]
        start = [0, 2]
        end = [4, 0]
        ideal_path = [start] + coords + [end]
        weight = 75
        for coord in coords:
            bd.setWeight(coord, weight)
        path = bd.optimumPath(start, end)

        # Confirm returned path is same as ideal path from start to end (inclusive)
        self.assertEqual(path, ideal_path)