class TestActions(unittest.TestCase): def setUp(self): # ToDo : Use mock instead of actual objects self.game_state = GameState() self.game = Game() self.game.set_referee(Referee()) self.game.ball = Ball() game_world = GameWorld(self.game) game_world.set_team_color_svc(TeamColorService(TeamColor.YELLOW_TEAM)) self.game.set_our_team_color(TeamColor.YELLOW_TEAM) self.game_state.set_reference(game_world) self.player_id = 1 # random integer @unittest.skip("I don't know whuy the f**k it is broken here.") def test_move_to(self): self.pose = Pose(Position(0, 0, 0), orientation=0.0) self.move = MoveToPosition(self.game_state, self.player_id, self.pose) self.assertEqual(self.move.exec(), AICommand(1, AICommandType.MOVE, **{"pose_goal": self.pose})) self.pose = Pose(Position(0.5, 0.3, 0.2), orientation=3.2) self.move = MoveToPosition(self.game_state, self.player_id, self.pose) self.assertEqual(MoveToPosition.exec(self.move), AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": self.pose})) @unittest.skip("I don't know whuy the f**k it is broken here.") def test_idle(self): self.idle = Idle(self.game_state, self.player_id) current_pose = None current_pose_string = AICommand(self.player_id, AICommandType.STOP) self.assertEqual(Idle.exec(self.idle), current_pose_string) @unittest.skip("I don't know what the f**k is happening here.") def test_GrabBall(self): self.grab_ball = GetBall(self.game_state, self.player_id) self.game_state.game.ball.set_position(Position(5, 0), 0) ai_cmd = self.grab_ball.exec() ball_position = self.game_state.get_ball_position() destination_orientation = get_angle(self.game_state.get_player_pose(self.player_id).position, ball_position) destination_pose = {"pose_goal": Pose(ball_position, destination_orientation)} ai_cmd_expected = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": destination_pose}) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state.game.ball.set_position(Position(-5, 5), 0) 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) @unittest.skip("LAZY ME OH HELL") def test_MoveWithBall(self): self.move_with_ball = MoveToDribblingBall(self.game_state, self.player_id, Position(100, 0)) self.game_state.game.ball.set_position(Position(5, 0), 0) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 0), 0)}) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state.game.ball.set_position(Position(5, 2), 0) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 0), atan(2/5))}) self.assertEqual(ai_cmd, ai_cmd_expected) @unittest.skip("I don't know whuy the f**k it is broken here.") 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(0, 100), pi/2)}) 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(250, 250), -3*pi/4)}) 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(1150, -23), 3.1215)}) 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-60, 50), 0.5235)}) 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-179, 25), -pi/2)}) 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) @unittest.skip("I don't know whuy the f**k it is broken here.") 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-273, -415), 0.9882)}) # 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(1000, -249), 1.5707)}) # 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(675, -200), -3.1415)}) self.assertEqual(aicmd_obtenu, aicmd_cible) @unittest.skip("I don't know whuy the f**k it is broken here.") def test_kick(self): # test avec la valeur 0 (nulle) self.kick = Kick(self.game_state, self.player_id, 0) current_pose = self.game_state.get_player_pose(self.player_id) current_pose_string = AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose}) self.assertEqual(Kick.exec(self.kick), current_pose_string) # test avec la valeur 1 (force maximale) self.kick = Kick(self.game_state, self.player_id, 1) current_pose = self.game_state.get_player_pose(self.player_id) self.assertEqual(Kick.exec(self.kick), AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose})) # test avec la valeur 0.3 (force intermediaire) self.kick = Kick(self.game_state, self.player_id, 0.3) current_pose = self.game_state.get_player_pose(self.player_id) self.assertEqual(Kick.exec(self.kick), AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose})) @unittest.skip("I got lazy, didn't want to review all of the protectgoal.") def test_ProtectGoal(self): # test de base self.game_state.game.friends.players[0].update(Pose(Position(4450, 10))) self.game_state.game.ball.set_position(Position(0, 0), 0) self.protectGoal = ProtectGoal(self.game_state, 0) aicmd_obtenu = self.protectGoal.exec() aicmd_cible = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(4000, 0), -pi)}) self.assertEqual(aicmd_obtenu, aicmd_cible) # test distance max < distance min self.assertRaises(AssertionError, ProtectGoal, self.game_state, 0, True, 50, 40)
class TestActions(unittest.TestCase): def setUp(self): # ToDo : Use mock instead of actual objects self.game_state = GameState() self.player_id = 1 # random integer self.game_state._update_player(self.player_id, Pose()) self.game_state._update_ball_position(Position(5, 0)) def test_move_to(self): self.pose = Pose(Position(0, 0, 0), orientation=0.0) self.move = MoveTo(self.game_state, self.player_id, self.pose) self.assertEqual( str(MoveTo.exec(self.move)), "AICommand(move_destination=[(x=0.0, y=0.0, z=0.0), theta=0.0], kick_strength=0)" ) self.pose = Pose(Position(0.5, 0.3, 0.2), orientation=3.2) self.move = MoveTo(self.game_state, self.player_id, self.pose) self.assertEqual( str(MoveTo.exec(self.move)), "AICommand(move_destination=[(x=0.5, y=0.3, z=0.2), theta=" + "-3.083185307179586], kick_strength=0)") def test_idle(self): self.idle = Idle(self.game_state, self.player_id) current_pose = None current_pose_string = "AICommand(move_destination=" + str( current_pose) + ", kick_strength=0)" self.assertEqual(str(Idle.exec(self.idle)), current_pose_string) 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_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_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) 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_kick(self): # test avec la valeur 0 (nulle) self.kick = Kick(self.game_state, self.player_id, 0) current_pose = self.game_state.get_player_pose(self.player_id) current_pose_string = "AICommand(move_destination=" + str( current_pose) + ", kick_strength=0)" self.assertEqual(str(Kick.exec(self.kick)), current_pose_string) # test avec la valeur 1 (force maximale) self.kick = Kick(self.game_state, self.player_id, 1) current_pose = self.game_state.get_player_pose(self.player_id) current_pose_string = "AICommand(move_destination=" + str( current_pose) + ", kick_strength=1)" self.assertEqual(str(Kick.exec(self.kick)), current_pose_string) # test avec la valeur 0.3 (force intermediaire) self.kick = Kick(self.game_state, self.player_id, 0.3) current_pose = self.game_state.get_player_pose(self.player_id) current_pose_string = "AICommand(move_destination=" + str( current_pose) + ", kick_strength=0.3)" self.assertEqual(str(Kick.exec(self.kick)), current_pose_string) 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)
class TestGameStateManager(unittest.TestCase): """ Teste les différentes fonctionnalités du GameStateManager """ def setUp(self): self.game = Game() self.referee = Referee self.game.set_referee(self.referee) self.tcsvc = TeamColorService(TeamColor.YELLOW_TEAM) self.game.set_our_team_color(self.tcsvc.OUR_TEAM_COLOR) self.game_world_OK = GameWorld(self.game) self.game_world_OK.set_team_color_svc(self.tcsvc) self.GameStateManager1 = GameState() self.GameStateManager2 = GameState() self.GameStateManager1.set_reference(self.game_world_OK) def test_singleton(self): """ Teste si le Manager est un singleton, i.e. s'il ne peut y avoir qu'une seule instance du manager """ self.assertTrue(self.GameStateManager1 is self.GameStateManager2) self.assertIs(self.GameStateManager1, self.GameStateManager2) def test_set_reference(self): self.GameStateManager1.set_reference(self.game_world_OK) self.assertIs(self.GameStateManager1.game.referee, self.game_world_OK.game.referee) self.assertIs(self.GameStateManager1.field, self.game_world_OK.game.field) self.assertIs(self.GameStateManager2.our_team_color, self.game.our_team_color) game_state_manager = GameState() self.assertRaises(AssertionError, game_state_manager.set_reference, None) game = Game() game_world_nok = GameWorld(game) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) game_world_nok.game.set_referee(self.referee) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) game = Game() game_world_nok = GameWorld(game) game_world_nok.set_team_color_svc(self.tcsvc) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) def test_get_player_pose(self): self.assertIs(self.GameStateManager1.get_player_pose(0, True), self.game.friends.players[0].pose) self.assertIs(self.GameStateManager2.get_player_pose(0, False), self.game.enemies.players[0].pose) self.assertIsNot(self.GameStateManager1.get_player_pose(0, True), self.game.friends.players[1].pose) self.assertIsNot(self.GameStateManager2.get_player_pose(0, False), self.game.enemies.players[1].pose) self.assertIsNot(self.GameStateManager1.get_player_pose(0, True), self.game.enemies.players[0].pose) self.assertIsNot(self.GameStateManager2.get_player_pose(0, False), self.game.friends.players[0].pose) def test_get_player_position(self): self.assertIs(self.GameStateManager1.get_player_position(0, True), self.game.friends.players[0].pose.position) self.assertIs(self.GameStateManager2.get_player_position(0, False), self.game.enemies.players[0].pose.position)
class TestActions(unittest.TestCase): def setUp(self): # ToDo : Use mock instead of actual objects self.game_state = GameState() self.game = Game() self.game.set_referee(Referee()) self.game.ball = Ball() game_world = ReferenceTransferObject(self.game) game_world.set_team_color_svc(TeamColorService(TeamColor.YELLOW_TEAM)) self.game.set_our_team_color(TeamColor.YELLOW_TEAM) self.game_state.set_reference(game_world) self.player_id = 1 # random integer @unittest.skip("I don't know whuy the f**k it is broken here.") def test_move_to(self): self.pose = Pose(Position(0, 0, 0), orientation=0.0) self.move = MoveToPosition(self.game_state, self.player_id, self.pose) self.assertEqual( self.move.exec(), AICommand(1, AICommandType.MOVE, **{"pose_goal": self.pose})) self.pose = Pose(Position(0.5, 0.3, 0.2), orientation=3.2) self.move = MoveToPosition(self.game_state, self.player_id, self.pose) self.assertEqual( MoveToPosition.exec(self.move), AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": self.pose})) @unittest.skip("I don't know whuy the f**k it is broken here.") def test_idle(self): self.idle = Idle(self.game_state, self.player_id) current_pose = None current_pose_string = AICommand(self.player_id, AICommandType.STOP) self.assertEqual(Idle.exec(self.idle), current_pose_string) @unittest.skip("I don't know what the f**k is happening here.") def test_GrabBall(self): self.grab_ball = GetBall(self.game_state, self.player_id) self.game_state.game.ball.set_position(Position(5, 0), 0) ai_cmd = self.grab_ball.exec() ball_position = self.game_state.get_ball_position() destination_orientation = get_angle( self.game_state.get_player_pose(self.player_id).position, ball_position) destination_pose = { "pose_goal": Pose(ball_position, destination_orientation) } ai_cmd_expected = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": destination_pose}) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state.game.ball.set_position(Position(-5, 5), 0) 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) @unittest.skip("LAZY ME OH HELL") def test_MoveWithBall(self): self.move_with_ball = MoveToDribblingBall(self.game_state, self.player_id, Position(100, 0)) self.game_state.game.ball.set_position(Position(5, 0), 0) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 0), 0)}) self.assertEqual(ai_cmd, ai_cmd_expected) self.game_state.game.ball.set_position(Position(5, 2), 0) ai_cmd = self.move_with_ball.exec() ai_cmd_expected = AICommand( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 0), atan(2 / 5))}) self.assertEqual(ai_cmd, ai_cmd_expected) @unittest.skip("I don't know whuy the f**k it is broken here.") 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(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(100, 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(0, 100), pi / 2)}) 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(250, 250), -3 * pi / 4)}) 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(1150, -23), 3.1215)}) 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-60, 50), 0.5235)}) 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-179, 25), -pi / 2)}) 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) @unittest.skip("I don't know whuy the f**k it is broken here.") 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(-273, -415), 0.9882)}) # 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(1000, -249), 1.5707)}) # 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( self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(675, -200), -3.1415)}) self.assertEqual(aicmd_obtenu, aicmd_cible) @unittest.skip("I don't know whuy the f**k it is broken here.") def test_kick(self): # test avec la valeur 0 (nulle) self.kick = Kick(self.game_state, self.player_id, 0) current_pose = self.game_state.get_player_pose(self.player_id) current_pose_string = AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose}) self.assertEqual(Kick.exec(self.kick), current_pose_string) # test avec la valeur 1 (force maximale) self.kick = Kick(self.game_state, self.player_id, 1) current_pose = self.game_state.get_player_pose(self.player_id) self.assertEqual( Kick.exec(self.kick), AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose})) # test avec la valeur 0.3 (force intermediaire) self.kick = Kick(self.game_state, self.player_id, 0.3) current_pose = self.game_state.get_player_pose(self.player_id) self.assertEqual( Kick.exec(self.kick), AICommand(self.player_id, AICommandType.KICK, **{"pose_goal": current_pose})) @unittest.skip("I got lazy, didn't want to review all of the protectgoal.") def test_ProtectGoal(self): # test de base self.game_state.game.friends.players[0].update(Pose(Position(4450, 10))) self.game_state.game.ball.set_position(Position(0, 0), 0) self.protectGoal = ProtectGoal(self.game_state, 0) aicmd_obtenu = self.protectGoal.exec() aicmd_cible = AICommand(self.player_id, AICommandType.MOVE, **{"pose_goal": Pose(Position(4000, 0), -pi)}) self.assertEqual(aicmd_obtenu, aicmd_cible) # test distance max < distance min self.assertRaises(AssertionError, ProtectGoal, self.game_state, 0, True, 50, 40)
class TestGameStateManager(unittest.TestCase): """ Teste les différentes fonctionnalités du GameStateManager """ def setUp(self): self.field = Field.Field(Ball.Ball()) self.my_team = Team.Team(True) self.other_team = Team.Team(False) self.GameStateManager1 = GameState() self.GameStateManager2 = GameState() def test_singleton(self): """ Teste si le Manager est un singleton, i.e. s'il ne peut y avoir qu'une seule instance du manager """ self.assertTrue(self.GameStateManager1 is self.GameStateManager2) def test_update_ball_position(self): new_ball_position = Position.Position(1500, 1500, 0) self.GameStateManager2._update_ball_position(new_ball_position) self.assertEqual(new_ball_position, self.GameStateManager1.get_ball_position()) def test_update_field(self): new_ball_position = Position.Position(2500, 2500, 0) self.field.move_ball(new_ball_position, 5) self.GameStateManager2._update_field(self.field) self.assertEqual(self.GameStateManager1.get_ball_position(), new_ball_position) def test_update_player(self): new_player_pose = Pose.Pose(Position.Position(1700, 1700, 0), 25) self.GameStateManager2._update_player(3, new_player_pose, True) self.assertEqual(new_player_pose, self.GameStateManager1.get_player_pose(3, True)) self.GameStateManager2._update_player(3, new_player_pose, False) self.assertEqual(new_player_pose, self.GameStateManager1.get_player_pose(3, False)) def test_update_team(self): new_player_pose = Pose.Pose(Position.Position(1000, 1000, 0), 25) for i in range(PLAYER_PER_TEAM): self.my_team.move_and_rotate_player(i, new_player_pose) new_player_pose.position += 200 self.GameStateManager2._update_team(self.my_team, True) for i in range(PLAYER_PER_TEAM): self.assertEqual(self.GameStateManager1.get_player_pose(i, True), self.my_team.players[i].pose) new_player_pose = Pose.Pose(Position.Position(1000, 1000, 0), 25) for i in range(PLAYER_PER_TEAM): self.other_team.move_and_rotate_player(i, new_player_pose) new_player_pose.position += 100 self.GameStateManager2._update_team(self.other_team, False) for i in range(PLAYER_PER_TEAM): self.assertEqual(self.GameStateManager1.get_player_pose(i, False), self.other_team.players[i].pose) def test_update_timestamp(self): new_timestamp = 123.25 self.GameStateManager2._update_timestamp(new_timestamp) self.assertEqual(self.GameStateManager1.timestamp, new_timestamp) def test_update(self): new_timestamp = 145.36 new_ball_position = Position.Position(500, 500, 0) self.field.move_ball(new_ball_position, 5) new_player_pose = Pose.Pose(Position.Position(1000, 1000, 0), 25) for i in range(PLAYER_PER_TEAM): self.my_team.move_and_rotate_player(i, new_player_pose) new_player_pose.position += 200 new_player_pose = Pose.Pose(Position.Position(1000, 1000, 0), 25) for i in range(PLAYER_PER_TEAM): self.other_team.move_and_rotate_player(i, new_player_pose) new_player_pose.position += 100 new_game_state = r_GameState(field=self.field, referee=Referee.Referee(), friends=self.my_team, enemies=self.other_team, timestamp=new_timestamp, debug='Test') self.GameStateManager2.update(new_game_state) self.assertEqual(new_game_state.field.ball.position, self.GameStateManager1.get_ball_position()) for i in range(PLAYER_PER_TEAM): self.assertEqual(self.GameStateManager1.get_player_pose(i, False), self.other_team.players[i].pose) self.assertEqual(self.GameStateManager1.get_player_pose(i, False), self.other_team.players[i].pose) self.assertEqual(new_game_state.timestamp, self.GameStateManager1.timestamp)
class TestGameStateManager(unittest.TestCase): """ Teste les différentes fonctionnalités du GameStateManager """ def setUp(self): config_service = ConfigService().load_file("config/sim_standard.cfg") self.game = Game() self.referee = Referee self.game.set_referee(self.referee) self.tcsvc = TeamColorService(TeamColor.BLUE_TEAM) self.game.set_our_team_color(self.tcsvc.OUR_TEAM_COLOR) self.game_world_OK = ReferenceTransferObject(self.game) self.game_world_OK.set_team_color_svc(self.tcsvc) self.GameStateManager1 = GameState() self.GameStateManager2 = GameState() self.GameStateManager1.set_reference(self.game_world_OK) def test_singleton(self): """ Teste si le Manager est un singleton, i.e. s'il ne peut y avoir qu'une seule instance du manager """ self.assertTrue(self.GameStateManager1 is self.GameStateManager2) self.assertIs(self.GameStateManager1, self.GameStateManager2) def test_set_reference(self): self.GameStateManager1.set_reference(self.game_world_OK) self.assertIs(self.GameStateManager1.game.referee, self.game_world_OK.game.referee) self.assertIs(self.GameStateManager1.field, self.game_world_OK.game.field) self.assertIs(self.GameStateManager1.game.our_team_color, self.game.our_team_color) game_state_manager = GameState() self.assertRaises(AssertionError, game_state_manager.set_reference, None) game = Game() game_world_nok = ReferenceTransferObject(game) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) game_world_nok.game.set_referee(self.referee) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) game = Game() game_world_nok = ReferenceTransferObject(game) game_world_nok.set_team_color_svc(self.tcsvc) self.assertRaises(AssertionError, game_state_manager.set_reference, game_world_nok) def test_get_player_pose(self): self.assertIs(self.GameStateManager1.get_player_pose(0, True), self.game.friends.players[0].pose) self.assertIs(self.GameStateManager2.get_player_pose(0, False), self.game.enemies.players[0].pose) self.assertIsNot(self.GameStateManager1.get_player_pose(0, True), self.game.friends.players[1].pose) self.assertIsNot(self.GameStateManager2.get_player_pose(0, False), self.game.enemies.players[1].pose) self.assertIsNot(self.GameStateManager1.get_player_pose(0, True), self.game.enemies.players[0].pose) self.assertIsNot(self.GameStateManager2.get_player_pose(0, False), self.game.friends.players[0].pose) def test_get_player_position(self): self.assertIs(self.GameStateManager1.get_player_position(0, True), self.game.friends.players[0].pose.position) self.assertIs(self.GameStateManager2.get_player_position(0, False), self.game.enemies.players[0].pose.position)