def test_GoBehind(self): # TODO: faire davantage de cas de test distance_behind = 500 # test avec une droite quelconque self.go_behind = GoBehind(self.game_state, self.player_id, Position(1.5, 2.3), Position(18.3, 27.8), distance_behind) aicmd_obtenu = GoBehind.exec(self.go_behind) aicmd_cible = AICommand(Pose(Position(-273, -415), 0.9882), 0) self.assertEqual(aicmd_obtenu, aicmd_cible) # test avec une droite verticale self.go_behind = GoBehind(self.game_state, self.player_id, Position(1000, 250.3), Position(1000, 725.8), distance_behind) aicmd_obtenu = GoBehind.exec(self.go_behind) aicmd_cible = AICommand(Pose(Position(1000, -249), 1.5707), 0) self.assertEqual(aicmd_obtenu, aicmd_cible) # test avec une droite horizontale self.go_behind = GoBehind(self.game_state, self.player_id, Position(175.8, -200.34), Position(-276.8, -200.34), distance_behind) aicmd_obtenu = GoBehind.exec(self.go_behind) aicmd_cible = AICommand(Pose(Position(675, -200), -3.1415), 0) self.assertEqual(aicmd_obtenu, aicmd_cible)
def test_MoveWithBall(self): self.move_with_ball = MoveWithBall(self.game_state, self.player_id, Position(100, 0)) self.game_state._update_ball_position(Position(5, 0)) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand(Pose(Position(100, 0), 0), 0) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state._update_ball_position(Position(5, 2)) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand(Pose(Position(100, 0), atan(2 / 5)), 0) self.assertEqual(ai_cmd, ai_cmd_expected)
def test_exec(self): self.node1.add_vertex(self.vertex1) self.node1.add_vertex(self.vertex2) next_ai_command, next_node = self.node1.exec() self.assertEqual(next_node, 0) expected_aicmd = AICommand(Pose(Position(-4000, 0), 0), 0) self.assertEqual(next_ai_command, expected_aicmd) self.node2.add_vertex(self.vertex2) expected_aicmd = AICommand(None, 0) next_ai_command, next_node = self.node2.exec() self.assertEqual(next_ai_command, expected_aicmd) self.assertEqual(next_node, -1)
def test_GrabBall(self): self.grab_ball = GrabBall(self.game_state, self.player_id) self.game_state._update_ball_position(Position(5, 0)) ai_cmd = self.grab_ball.exec() ai_cmd_expected = AICommand(Pose(Position(5, 0)), 0) print(self.game_state.get_player_pose(self.player_id)) print(ai_cmd) print(ai_cmd_expected) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state._update_ball_position(Position(-5, 5)) ai_cmd = self.grab_ball.exec() ai_cmd_expected = AICommand(Pose(Position(-5, 5), 3 * pi / 4), 0) self.assertEqual(ai_cmd, ai_cmd_expected)
def test_exec(self): next_ai_command = self.graph1.exec() expected_ai_command = AICommand(None, 0) self.assertEqual(self.graph1.current_node, 1) self.assertEqual(next_ai_command, expected_ai_command) self.assertRaises(EmptyGraphException, self.empty_graph.exec) self.empty_graph.add_node(self.node2) self.empty_graph.add_node(self.node1) self.empty_graph.add_vertex(0, 1, foo2) next_ai_command = self.empty_graph.exec() expected_ai_command = AICommand(None, 0) self.assertEqual(self.empty_graph.current_node, 0) self.assertEqual(next_ai_command, expected_ai_command) next_ai_command = self.empty_graph.exec() expected_ai_command = AICommand(Pose(Position(500, 0), 0), 0) self.assertEqual(self.empty_graph.current_node, 0) self.assertEqual(next_ai_command, expected_ai_command)
def test_ProtectGoal(self): # test de base self.game_state._update_player(0, Pose(Position(4450, 10), 0)) self.game_state._update_ball_position(Position(0, 0)) self.protectGoal = ProtectGoal(self.game_state, 0) aicmd_obtenu = self.protectGoal.exec() aicmd_cible = AICommand(Pose(Position(4000, 0), -pi), 0) self.assertEqual(aicmd_obtenu, aicmd_cible) # test distance max < distance min self.assertRaises(AssertionError, ProtectGoal, self.game_state, 0, True, 50, 40)
def test_GoBetween(self): # test avec une droite verticale self.go_between = GoBetween(self.game_state, self.player_id, Position(100, 100), Position(100, -100), Position(200, 0)) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(100, 0), 0), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test avec une droite horizontale self.go_between = GoBetween(self.game_state, self.player_id, Position(100, 100), Position(-100, 100), Position(0, 200)) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(0, 100), pi / 2), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test avec une droite quelconque self.go_between = GoBetween(self.game_state, self.player_id, Position(0, 500), Position(500, 0), Position(-300, -300)) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(250, 250), -3 * pi / 4), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test destination calculée derrière position1 self.go_between = GoBetween(self.game_state, self.player_id, Position(1000, 75), Position(1500, -250), Position(0, 0), 180) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(1150, -23), 3.1215), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test destination calculée derrière position2 self.go_between = GoBetween(self.game_state, self.player_id, Position(-100, 50), Position(-50, 50), Position(-60.0 + sqrt(3), 51.0), 10) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(-60, 50), 0.5235), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test correction pour respecter la distance minimale self.go_between = GoBetween(self.game_state, self.player_id, Position(-500, 25), Position(1, 25), Position(-179, 0), 180) ai_cmd = self.go_between.exec() ai_cmd_expected = AICommand(Pose(Position(-179, 25), -pi / 2), 0) self.assertEqual(ai_cmd, ai_cmd_expected) # test distance entre les positions insuffisantes self.assertRaises(AssertionError, GoBetween, self.game_state, self.player_id, Position(1, 1), Position(-1, -1), 50)