Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/software/ai/hl/stp/play/penalty_kick/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package(default_visibility = ["//visibility:public"])

load("@simulated_tests_deps//:requirements.bzl", "requirement")
# We force linking for all plays so that the static variables required for the
# "factory" design pattern to work are linked in
# https://www.bfilipek.com/2018/02/static-vars-static-lib.html
Expand Down Expand Up @@ -37,18 +38,13 @@ cc_test(
],
)

cc_test(
py_test(
name = "penalty_kick_play_test",
Comment thread
itsarune marked this conversation as resolved.
srcs = ["penalty_kick_play_test.cpp"],
srcs = ["penalty_kick_play_test.py"],
tags = ["exclusive"],
deps = [
":penalty_kick_play",
"//shared/test_util:tbots_gtest_main",
"//software/simulated_tests:simulated_er_force_sim_play_test_fixture",
"//software/simulated_tests/non_terminating_validation_functions",
"//software/simulated_tests/terminating_validation_functions",
"//software/simulated_tests/validation:validation_function",
"//software/test_util",
"//software/time:duration",
"//software/world",
"//software:conftest",
Comment thread
itsarune marked this conversation as resolved.
"//software/simulated_tests:validation",
requirement("pytest"),
],
)
113 changes: 0 additions & 113 deletions src/software/ai/hl/stp/play/penalty_kick/penalty_kick_play_test.cpp

This file was deleted.

111 changes: 111 additions & 0 deletions src/software/ai/hl/stp/play/penalty_kick/penalty_kick_play_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import sys

import pytest

import software.python_bindings as tbots_cpp


from software.simulated_tests.ball_enters_region import BallEventuallyEntersRegion
from software.simulated_tests.ball_moves_forward import BallAlwaysMovesForward
from software.simulated_tests.friendly_has_ball_possession import (
FriendlyAlwaysHasBallPossession,
)
from software.simulated_tests.friendly_team_scored import FriendlyTeamEventuallyScored

from proto.message_translation.tbots_protobuf import create_world_state
from proto.import_all_protos import *
from proto.ssl_gc_common_pb2 import Team
from proto.play_pb2 import Play, PlayName


def test_penalty_kick_play(simulated_test_runner):
ball_initial_pos = tbots_cpp.Point(0, 0)

def setup(*args):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring, add param docs for args.

# Setup Bots
blue_bots = [
tbots_cpp.Point(-3, 2.5),
tbots_cpp.Point(-3, 1.5),
tbots_cpp.Point(-3, 0.5),
tbots_cpp.Point(-3, -0.5),
tbots_cpp.Point(-3, -1.5),
tbots_cpp.Point(-3, -2.5),
]

yellow_bots = [
tbots_cpp.Point(1, 0),
tbots_cpp.Point(1, 2.5),
tbots_cpp.Point(1, -2.5),
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXNegYCorner(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXPosYCorner(),
]

# Force play override here
blue_play = Play()
blue_play.name = PlayName.PenaltyKickPlay

yellow_play = Play()
yellow_play.name = PlayName.PenaltyKickEnemyPlay

simulated_test_runner.blue_full_system_proto_unix_io.send_proto(Play, blue_play)
simulated_test_runner.yellow_full_system_proto_unix_io.send_proto(
Play, yellow_play
)

# Game Controller Setup
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.NORMAL_START, team=Team.BLUE
)
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.PENALTY, team=Team.BLUE
)

# Create world state
simulated_test_runner.simulator_proto_unix_io.send_proto(
WorldState,
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_initial_pos,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)

field = tbots_cpp.Field.createSSLDivisionBField()

# Always Validation
inv_always_validation_sequence_set = [[]]

ag_always_validation_sequence_set = [[FriendlyAlwaysHasBallPossession(), BallAlwaysMovesForward(ball_initial_pos)]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be inv_always?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It immediately fails cause I think the ball doesn't start moving forward? Or the robot doesn't immediately start with the ball. I forget which.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it is both.


# Eventually Validation
inv_eventually_validation_sequence_set = [
[
FriendlyTeamEventuallyScored(),
BallEventuallyEntersRegion(regions=[field.enemyDefenseArea()]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this validation is kinda redundant considering we have FriendlyTeamEventuallyScored

]
]
ag_eventually_validation_sequence_set = [[]]

simulated_test_runner.run_test(
params=[0],
setup=setup,
inv_eventually_validation_sequence_set=inv_eventually_validation_sequence_set,
inv_always_validation_sequence_set=inv_always_validation_sequence_set,
ag_eventually_validation_sequence_set=ag_eventually_validation_sequence_set,
ag_always_validation_sequence_set=ag_always_validation_sequence_set,
test_timeout_s=15,
)


if __name__ == "__main__":
# Run the test, -s disables all capturing at -vv increases verbosity
sys.exit(pytest.main([__file__, "-svv"]))
Loading