Ejemplo n.º 1
0
    def test_random_distance_positions_three_by_five(self):
        m = MusicMaze(7, 5, 3, 1)

        m_str = "O - O   O - O - O\n" \
                "|       |       |\n" \
                "O - O   O - X   O\n" \
                "    |   |       |\n" \
                "O - O - O - O   O"
        self.assertEqual(m_str, str(m))

        # solution path should all be zero
        self.assertEqual(0, m.distance_from_path(1, 3))
        self.assertEqual(0, m.distance_from_path(1, 2))
        self.assertEqual(0, m.distance_from_path(0, 2))
        self.assertEqual(0, m.distance_from_path(0, 3))
        self.assertEqual(0, m.distance_from_path(0, 4))
        self.assertEqual(0, m.distance_from_path(1, 4))
        self.assertEqual(0, m.distance_from_path(2, 4))

        self.assertEqual(1, m.distance_from_path(2, 2))

        self.assertEqual(2, m.distance_from_path(2, 3))
        self.assertEqual(2, m.distance_from_path(2, 1))

        self.assertEqual(3, m.distance_from_path(2, 0))
        self.assertEqual(3, m.distance_from_path(1, 1))

        self.assertEqual(4, m.distance_from_path(1, 0))

        self.assertEqual(5, m.distance_from_path(0, 0))

        self.assertEqual(6, m.distance_from_path(0, 1))
Ejemplo n.º 2
0
    def test_out_of_bounds_col_distance_check(self):
        m = MusicMaze(7, 5, 3)

        try:
            m.distance_from_path(0, 6)
            self.fail("Should not be able to check out of bounds distances")
        except ValueError as e:
            self.assertEqual("Given invalid position", str(e))
Ejemplo n.º 3
0
    def test_negative_col_distance_check(self):
        m = MusicMaze(3, 2, 2)

        try:
            m.distance_from_path(0, -1)
            self.fail("Should not be able to check negative distances")
        except ValueError as e:
            self.assertEqual("Given invalid position", str(e))
Ejemplo n.º 4
0
    def test_random_distance_positions_four_by_four(self):
        m = MusicMaze(7, 4, 4, 1)

        m_str = "X - O   O - O\n" \
                "|       |    \n" \
                "O - O - O   O\n" \
                "|       |   |\n" \
                "O   O   O - O\n" \
                "    |   |   |\n" \
                "O - O - O   O"
        self.assertEqual(m_str, str(m))

        # solution path should all be zero
        self.assertEqual(0, m.distance_from_path(0, 0))
        self.assertEqual(0, m.distance_from_path(1, 0))
        self.assertEqual(0, m.distance_from_path(1, 1))
        self.assertEqual(0, m.distance_from_path(1, 2))
        self.assertEqual(0, m.distance_from_path(2, 2))
        self.assertEqual(0, m.distance_from_path(2, 3))
        self.assertEqual(0, m.distance_from_path(3, 3))

        self.assertEqual(1, m.distance_from_path(0, 1))
        self.assertEqual(1, m.distance_from_path(2, 0))
        self.assertEqual(1, m.distance_from_path(0, 2))
        self.assertEqual(1, m.distance_from_path(3, 2))
        self.assertEqual(1, m.distance_from_path(1, 3))

        self.assertEqual(2, m.distance_from_path(0, 3))
        self.assertEqual(2, m.distance_from_path(3, 1))

        self.assertEqual(3, m.distance_from_path(3, 0))
        self.assertEqual(3, m.distance_from_path(2, 1))