def test_three_by_three_player_position(self): model_maze = MusicMaze(5, 3, 3, 1) m_str = "X - O O\n" \ "| |\n" \ "O - O - O\n" \ " | |\n" \ "O - O O" self.assertEqual(m_str, str(model_maze)) m = MazeState(model_maze) model_maze.move_player(1, 0) self.assertEqual((1, 0), m.get_player_position()) model_maze.move_player(1, 1) self.assertEqual((1, 1), m.get_player_position()) model_maze.move_player(1, 2) self.assertEqual((1, 2), m.get_player_position()) model_maze.move_player(1, 1) model_maze.move_player(1, 0) model_maze.move_player(0, 0) self.assertEqual((0, 0), m.get_player_position())
def test_restart_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)) m.restart() self.assertEqual(m_str, str(m)) m.move_player(1, 2) m.move_player(2, 2) m.move_player(2, 1) m.move_player(2, 0) m_str_four_move = "O - O O - O - O\n" \ "| | |\n" \ "O - O O - O O\n" \ " | | |\n" \ "X - O - O - O O" self.assertEqual(m_str_four_move, str(m)) m.restart() self.assertEqual(m_str, str(m))
def test_illegal_move_out_of_bounds_up(self): m = MusicMaze(3, 2, 2, 1) m_str = "X - O\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(m)) try: m.move_player(0, -1) self.fail("Cannot move out of bounds up") except ValueError as e: self.assertEqual("Cannot move to given location", str(e))
def test_two_by_two_movement(self): m = MusicMaze(3, 2, 2, 1) m_str = "X - O\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(m)) m.move_player(1, 0) m_str = "O - O\n" \ "| |\n" \ "X O" self.assertEqual(m_str, str(m)) m.move_player(0, 0) m_str = "X - O\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(m)) m.move_player(0, 1) m_str = "O - X\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(m)) m.move_player(1, 1) m_str = "O - O\n" \ "| |\n" \ "O X" self.assertEqual(m_str, str(m))
def test_illegal_move_cannot_jump_across_gap(self): m = MusicMaze(3, 2, 2, 1) m_str = "X - O\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(m)) m.move_player(1, 0) try: m.move_player(1, 1) self.fail("Cannot jump across gap") except ValueError as e: self.assertEqual("Cannot move to given location", str(e))
def test_illegal_move_cannot_teleport_to_end(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)) try: m.move_player(3, 3) self.fail("Cannot teleport to the end") except ValueError as e: self.assertEqual("Cannot move to given location", str(e))
def test_illegal_move_cannot_jump_past_other_nodes(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)) try: m.move_player(2, 0) self.fail("Cannot jump past other nodes") except ValueError as e: self.assertEqual("Cannot move to given location", str(e))
def test_three_by_three_game_over(self): model_maze = MusicMaze(5, 3, 3, 1) m_str = "X - O O\n" \ "| |\n" \ "O - O - O\n" \ " | |\n" \ "O - O O" self.assertEqual(m_str, str(model_maze)) m = MazeState(model_maze) self.assertFalse(m.game_over()) model_maze.move_player(1, 0) self.assertFalse(m.game_over()) model_maze.move_player(1, 1) self.assertFalse(m.game_over()) model_maze.move_player(1, 2) self.assertFalse(m.game_over()) model_maze.move_player(2, 2) self.assertTrue(m.game_over())
def test_get_player_pos(self): m = MusicMaze(7, 3, 5, 1) m_str = "O - O O\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O O\n" \ "| | |\n" \ "O X O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(m)) self.assertEqual("(3, 1)", str(m.get_player_position())) m.move_player(2, 1) self.assertEqual("(2, 1)", str(m.get_player_position())) m.move_player(2, 0) self.assertEqual("(2, 0)", str(m.get_player_position())) m.move_player(2, 1) self.assertEqual("(2, 1)", str(m.get_player_position())) m.move_player(3, 1) self.assertEqual("(3, 1)", str(m.get_player_position()))
def test_two_by_two_closest_cell(self): model_maze = MusicMaze(3, 2, 2, 1) m_str = "X - O\n" \ "| |\n" \ "O O" self.assertEqual(m_str, str(model_maze)) m = MazeState(model_maze) self.assertEqual((0, 0), m.get_closest_cell_for_player()) model_maze.move_player(1, 0) self.assertEqual((0, 0), m.get_closest_cell_for_player()) model_maze.move_player(0, 0) model_maze.move_player(0, 1) self.assertEqual((0, 1), m.get_closest_cell_for_player()) model_maze.move_player(1, 1) self.assertEqual((1, 1), m.get_closest_cell_for_player())
def test_five_by_three_closest_distance_and_cell(self): model_maze = MusicMaze(7, 3, 5, 1) m = MazeState(model_maze) m_str = "O - O O\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O O\n" \ "| | |\n" \ "O X O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(model_maze)) self.assertEqual((3, 1), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(2, 1) self.assertEqual((2, 1), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(2, 0) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(1, 0) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(1, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 0) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(2, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 1) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(3, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 0) model_maze.move_player(1, 0) model_maze.move_player(1, 1) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(2, m.get_closest_cell_distance_for_player()) model_maze.move_player(1, 2) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(3, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 2) self.assertEqual((2, 0), m.get_closest_cell_for_player()) self.assertEqual(4, m.get_closest_cell_distance_for_player())
def test_three_by_three_closest_cell_and_distance(self): model_maze = MusicMaze(5, 3, 3, 1) m_str = "X - O O\n" \ "| |\n" \ "O - O - O\n" \ " | |\n" \ "O - O O" self.assertEqual(m_str, str(model_maze)) m = MazeState(model_maze) self.assertEqual((0, 0), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 1) self.assertEqual((0, 0), m.get_closest_cell_for_player()) self.assertEqual(1, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 0) model_maze.move_player(1, 0) self.assertEqual((1, 0), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(1, 1) self.assertEqual((1, 1), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(2, 1) self.assertEqual((1, 1), m.get_closest_cell_for_player()) self.assertEqual(1, m.get_closest_cell_distance_for_player()) model_maze.move_player(2, 0) self.assertEqual((1, 1), m.get_closest_cell_for_player()) self.assertEqual(2, m.get_closest_cell_distance_for_player()) model_maze.move_player(2, 1) model_maze.move_player(1, 1) model_maze.move_player(1, 2) self.assertEqual((1, 2), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player()) model_maze.move_player(0, 2) self.assertEqual((1, 2), m.get_closest_cell_for_player()) self.assertEqual(1, m.get_closest_cell_distance_for_player()) model_maze.move_player(1, 2) model_maze.move_player(2, 2) self.assertEqual((2, 2), m.get_closest_cell_for_player()) self.assertEqual(0, m.get_closest_cell_distance_for_player())
def test_game_over(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)) self.assertFalse(m.game_over()) m.move_player(1, 2) self.assertFalse(m.game_over()) m.move_player(0, 2) self.assertFalse(m.game_over()) m.move_player(0, 3) self.assertFalse(m.game_over()) m.move_player(0, 4) self.assertFalse(m.game_over()) m.move_player(1, 4) self.assertFalse(m.game_over()) m.move_player(2, 4) self.assertTrue(m.game_over()) m.move_player(1, 4) self.assertFalse(m.game_over())
def test_five_by_three_movement(self): """Kept at a bare minimum to avoid having to detect different starting positions""" m = MusicMaze(7, 3, 5, 1) m_str = "O - O O\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O O\n" \ "| | |\n" \ "O X O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(m)) m.move_player(2, 1) m.move_player(2, 0) m.move_player(1, 0) m.move_player(0, 0) m.move_player(0, 1) m_str = "O - X O\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O O\n" \ "| | |\n" \ "O O O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(m)) m.move_player(0, 0) m.move_player(1, 0) m.move_player(1, 1) m.move_player(1, 2) m.move_player(0, 2) m_str = "O - O X\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O O\n" \ "| | |\n" \ "O O O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(m)) m.move_player(1, 2) m.move_player(1, 1) m.move_player(1, 0) m.move_player(2, 0) m.move_player(3, 0) m.move_player(4, 0) m.move_player(4, 1) m.move_player(4, 2) m.move_player(3, 2) m.move_player(2, 2) m_str = "O - O O\n" \ "| |\n" \ "O - O - O\n" \ "| \n" \ "O - O X\n" \ "| | |\n" \ "O O O\n" \ "| |\n" \ "O - O - O" self.assertEqual(m_str, str(m))
def test_three_by_five_movement(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)) m.move_player(1, 2) m.move_player(2, 2) m.move_player(2, 1) m.move_player(2, 0) m_str = "O - O O - O - O\n" \ "| | |\n" \ "O - O O - O O\n" \ " | | |\n" \ "X - O - O - O O" self.assertEqual(m_str, str(m)) m.move_player(2, 1) m.move_player(1, 1) m.move_player(1, 0) m.move_player(0, 0) m.move_player(0, 1) m_str = "O - X O - O - O\n" \ "| | |\n" \ "O - O O - O O\n" \ " | | |\n" \ "O - O - O - O O" self.assertEqual(m_str, str(m)) m.move_player(0, 0) m.move_player(1, 0) m.move_player(1, 1) m.move_player(2, 1) m.move_player(2, 2) m.move_player(1, 2) m.move_player(0, 2) m.move_player(0, 3) m.move_player(0, 4) m.move_player(1, 4) m.move_player(2, 4) m_str = "O - O O - O - O\n" \ "| | |\n" \ "O - O O - O O\n" \ " | | |\n" \ "O - O - O - O X" self.assertEqual(m_str, str(m))
def test_four_by_four_movement(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)) m.move_player(0, 1) m_str = "O - X 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)) m.move_player(0, 0) 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)) m.move_player(1, 0) m_str = "O - O O - O\n" \ "| | \n" \ "X - O - O O\n" \ "| | |\n" \ "O O O - O\n" \ " | | |\n" \ "O - O - O O" self.assertEqual(m_str, str(m)) m.move_player(2, 0) m_str = "O - O O - O\n" \ "| | \n" \ "O - O - O O\n" \ "| | |\n" \ "X O O - O\n" \ " | | |\n" \ "O - O - O O" self.assertEqual(m_str, str(m)) # skipping to interesting points m.move_player(1, 0) m.move_player(1, 1) m.move_player(1, 2) m.move_player(0, 2) m.move_player(0, 3) m_str = "O - O O - X\n" \ "| | \n" \ "O - O - O O\n" \ "| | |\n" \ "O O O - O\n" \ " | | |\n" \ "O - O - O O" self.assertEqual(m_str, str(m)) m.move_player(0, 2) m.move_player(1, 2) m.move_player(2, 2) m.move_player(2, 3) m.move_player(3, 3) m_str = "O - O O - O\n" \ "| | \n" \ "O - O - O O\n" \ "| | |\n" \ "O O O - O\n" \ " | | |\n" \ "O - O - O X" self.assertEqual(m_str, str(m)) m.move_player(2, 3) m.move_player(2, 2) m.move_player(3, 2) m.move_player(3, 1) m.move_player(3, 0) m_str = "O - O O - O\n" \ "| | \n" \ "O - O - O O\n" \ "| | |\n" \ "O O O - O\n" \ " | | |\n" \ "X - O - O O" self.assertEqual(m_str, str(m))