class TestNode(unittest.TestCase): def setUp(self): self.aTactic = TestNode._create_mock_tactic("A command") self.anotherTactic = TestNode._create_mock_tactic("Another command") self.node1 = Node(self.aTactic) self.node2 = Node(self.anotherTactic) self.vertex1 = Vertex(self.node1, lambda: True) self.vertex2 = Vertex(self.node2, lambda: False) @staticmethod def _create_mock_tactic(command): tactic = create_autospec(Tactic) tactic.exec = lambda: command return tactic def test_init(self): with self.assertRaises(AssertionError): Node("not a tactic") self.assertIsInstance(self.node2.tactic, Tactic) assert len(self.node2.vertices) == 0 def test_add_vertex(self): with self.assertRaises(AssertionError): self.node1.add_vertex("not a vertex") self.node1.add_vertex(self.vertex1) assert len(self.node1.vertices) == 1 self.node1.add_vertex(self.vertex1) assert len( self.node1.vertices ) == 1 # il ne peut y avoir qu'un vertex entre deux noeuds dans un sens self.node1.add_vertex(self.vertex2) assert len(self.node1.vertices) == 2 def test_exec(self): self.node1.add_vertex(self.vertex1) self.node1.add_vertex(self.vertex2) command_from_tactic, next_node = self.node1.exec() assert next_node == self.node1 assert command_from_tactic == self.aTactic.exec() self.node2.add_vertex(self.vertex2) command_from_tactic, next_node = self.node2.exec() assert next_node is self.node2 assert command_from_tactic == self.anotherTactic.exec() def test_set_flag(self): with self.assertRaises(AssertionError): self.node1.set_flag("not a flag") self.node1.set_flag(Flags.SUCCESS) assert self.node1.tactic.status_flag == Flags.SUCCESS
class TestNode(unittest.TestCase): def setUp(self): self.aTactic = TestNode._create_mock_tactic("A command") self.anotherTactic = TestNode._create_mock_tactic("Another command") self.node1 = Node(self.aTactic) self.node2 = Node(self.anotherTactic) self.vertex1 = Vertex(self.node1, lambda: True) self.vertex2 = Vertex(self.node2, lambda: False) @staticmethod def _create_mock_tactic(command): tactic = create_autospec(Tactic) tactic.exec = lambda: command return tactic def test_init(self): with self.assertRaises(AssertionError): Node("not a tactic") self.assertIsInstance(self.node2.tactic, Tactic) assert len(self.node2.vertices) == 0 def test_add_vertex(self): with self.assertRaises(AssertionError): self.node1.add_vertex("not a vertex") self.node1.add_vertex(self.vertex1) assert len(self.node1.vertices) == 1 self.node1.add_vertex(self.vertex1) assert len(self.node1.vertices) == 1 # il ne peut y avoir qu'un vertex entre deux noeuds dans un sens self.node1.add_vertex(self.vertex2) assert len(self.node1.vertices) == 2 def test_exec(self): self.node1.add_vertex(self.vertex1) self.node1.add_vertex(self.vertex2) command_from_tactic, next_node = self.node1.exec() assert next_node == self.node1 assert command_from_tactic == self.aTactic.exec() self.node2.add_vertex(self.vertex2) command_from_tactic, next_node = self.node2.exec() assert next_node is self.node2 assert command_from_tactic == self.anotherTactic.exec() def test_set_flag(self): with self.assertRaises(AssertionError): self.node1.set_flag("not a flag") self.node1.set_flag(Flags.SUCCESS) assert self.node1.tactic.status_flag == Flags.SUCCESS
class TestNode(unittest.TestCase): def setUp(self): 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.game_state.game.friends.players[0].update(Pose(Position(-4450, 0), 0)) self.tactic1 = GoalKeeper(self.game_state, 0) self.tactic2 = Stop(self.game_state, 1) self.node1 = Node(self.tactic1) self.node2 = Node(self.tactic2) self.vertex1 = Vertex(0, foo) self.vertex2 = Vertex(1, foo2) def test_init(self): self.assertRaises(AssertionError, Node, "not a tactic") self.assertIsInstance(self.node2.tactic, Tactic) self.assertEqual(len(self.node2.vertices), 0) def test_add_vertex(self): self.assertRaises(AssertionError, self.node1.add_vertex, "not a vertex") self.node1.add_vertex(self.vertex1) self.assertEqual(len(self.node1.vertices), 1) self.node1.add_vertex(self.vertex1) self.assertEqual(len(self.node1.vertices), 1) # il ne peut y avoir qu'un vertex entre deux noeuds dans un sens self.node1.add_vertex(self.vertex2) self.assertEqual(len(self.node1.vertices), 2) def test_remove_vertex(self): self.assertRaises(AssertionError, self.node1.remove_vertex, "not an int") self.assertRaises(AssertionError, self.node1.remove_vertex, -1) self.node1.add_vertex(self.vertex1) self.node1.remove_vertex(420) self.assertEqual(len(self.node1.vertices), 1) self.node1.remove_vertex(0) self.assertEqual(len(self.node1.vertices), 0) @unittest.skip("thinkin we should have generic tactic for test purpose, this is infuriating") 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(0, AICommandType.MOVE, **{"pose_goal": Pose(Position(-4000, 0), 0)}) self.assertEqual(next_ai_command, expected_aicmd) self.node2.add_vertex(self.vertex2) expected_aicmd = AICommand(0, AICommandType.STOP)#, **{"pose_goal": Pose(Position(-4000, 0), 0)}) next_ai_command, next_node = self.node2.exec() self.assertEqual(next_ai_command, expected_aicmd) self.assertEqual(next_node, -1) def test_str(self): self.node1.add_vertex(self.vertex1) self.node1.add_vertex(self.vertex2) expected_string = "Tactic: GoalKeeper Vertices: " for vertex in self.node1.vertices: expected_string += "\n " + str(vertex) self.assertEqual(str(self.node1), expected_string) def test_set_flag(self): self.assertRaises(AssertionError, self.node1.set_flag, "not a flag") self.node1.set_flag(Flags.SUCCESS) self.assertEqual(self.node1.tactic.status_flag, Flags.SUCCESS)
class TestNode(unittest.TestCase): def setUp(self): 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)) self.game_state.set_reference(game_world) self.game_state.game.friends.players[0].pose = Pose( Position(-4450, 0), 0) self.tactic1 = GoalKeeper( self.game_state, self.game_state.game.friends.players[A_GOAL_PLAYER_ID]) self.tactic2 = Stop(self.game_state, self.game_state.game.friends.players[A_PLAYER_ID]) self.node1 = Node(self.tactic1) self.node2 = Node(self.tactic2) self.vertex1 = Vertex(0, foo) self.vertex2 = Vertex(1, foo2) self.a_player = OurPlayer(TeamColor.BLUE, 0) def test_init(self): self.assertRaises(AssertionError, Node, "not a tactic") self.assertIsInstance(self.node2.tactic, Tactic) self.assertEqual(len(self.node2.vertices), 0) def test_add_vertex(self): self.assertRaises(AssertionError, self.node1.add_vertex, "not a vertex") self.node1.add_vertex(self.vertex1) self.assertEqual(len(self.node1.vertices), 1) self.node1.add_vertex(self.vertex1) self.assertEqual( len(self.node1.vertices), 1 ) # il ne peut y avoir qu'un vertex entre deux noeuds dans un sens self.node1.add_vertex(self.vertex2) self.assertEqual(len(self.node1.vertices), 2) def test_remove_vertex(self): self.assertRaises(AssertionError, self.node1.remove_vertex, "not an int") self.assertRaises(AssertionError, self.node1.remove_vertex, -1) self.node1.add_vertex(self.vertex1) self.node1.remove_vertex(420) self.assertEqual(len(self.node1.vertices), 1) self.node1.remove_vertex(0) self.assertEqual(len(self.node1.vertices), 0) @unittest.skip( "With the current implemention of aiCommand, testing this is more or less impossible" ) 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( self.a_player, AICommandType.MOVE, **{"pose_goal": Pose(Position(-4000, 0), 0)}) self.assertEqual(next_ai_command, expected_aicmd) self.node2.add_vertex(self.vertex2) expected_aicmd = AICommand( self.a_player, AICommandType.STOP ) #, **{"pose_goal": Pose(Position(-4000, 0), 0)}) next_ai_command, next_node = self.node2.exec() self.assertEqual(next_ai_command, expected_aicmd) self.assertEqual(next_node, -1) def test_set_flag(self): self.assertRaises(AssertionError, self.node1.set_flag, "not a flag") self.node1.set_flag(Flags.SUCCESS) self.assertEqual(self.node1.tactic.status_flag, Flags.SUCCESS)
class TestNode(unittest.TestCase): def setUp(self): config_service = ConfigService().load_file("config/sim_standard.cfg") 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_state.set_reference(game_world) self.game_state.game.friends.players[0].update( Pose(Position(-4450, 0), 0)) self.tactic1 = GoalKeeper(self.game_state, 0) self.tactic2 = Stop(self.game_state, 1) self.node1 = Node(self.tactic1) self.node2 = Node(self.tactic2) self.vertex1 = Vertex(0, foo) self.vertex2 = Vertex(1, foo2) def test_init(self): self.assertRaises(AssertionError, Node, "not a tactic") self.assertIsInstance(self.node2.tactic, Tactic) self.assertEqual(len(self.node2.vertices), 0) def test_add_vertex(self): self.assertRaises(AssertionError, self.node1.add_vertex, "not a vertex") self.node1.add_vertex(self.vertex1) self.assertEqual(len(self.node1.vertices), 1) self.node1.add_vertex(self.vertex1) self.assertEqual( len(self.node1.vertices), 1 ) # il ne peut y avoir qu'un vertex entre deux noeuds dans un sens self.node1.add_vertex(self.vertex2) self.assertEqual(len(self.node1.vertices), 2) def test_remove_vertex(self): self.assertRaises(AssertionError, self.node1.remove_vertex, "not an int") self.assertRaises(AssertionError, self.node1.remove_vertex, -1) self.node1.add_vertex(self.vertex1) self.node1.remove_vertex(420) self.assertEqual(len(self.node1.vertices), 1) self.node1.remove_vertex(0) self.assertEqual(len(self.node1.vertices), 0) @unittest.skip( "thinkin we should have generic tactic for test purpose, this is infuriating" ) 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( 0, AICommandType.MOVE, **{"pose_goal": Pose(Position(-4000, 0), 0)}) self.assertEqual(next_ai_command, expected_aicmd) self.node2.add_vertex(self.vertex2) expected_aicmd = AICommand( 0, AICommandType.STOP ) #, **{"pose_goal": Pose(Position(-4000, 0), 0)}) next_ai_command, next_node = self.node2.exec() self.assertEqual(next_ai_command, expected_aicmd) self.assertEqual(next_node, -1) def test_str(self): self.node1.add_vertex(self.vertex1) self.node1.add_vertex(self.vertex2) expected_string = "Tactic: GoalKeeper Vertices: " for vertex in self.node1.vertices: expected_string += "\n " + str(vertex) self.assertEqual(str(self.node1), expected_string) def test_set_flag(self): self.assertRaises(AssertionError, self.node1.set_flag, "not a flag") self.node1.set_flag(Flags.SUCCESS) self.assertEqual(self.node1.tactic.status_flag, Flags.SUCCESS)