- Types on every parameter, return value and variable, and snake_case names (the player name limit is the constant MAX_NAME_LENGTH). - Spelling fixes: *_triggered, character_selected, separator, caught_errors. The server's catched_errors key stays as the server sends it. - Signals are connected with signal.connect() instead of by name. - Code is ordered signals, constants, exported vars, vars, @onready vars, functions, with @onready on one line and two blank lines between functions. - Every script starts with a ## description. Template comments, old LOC notes and commented-out code are gone, apart from the local play code. - Lines are at most 100 characters, apart from the local play path. - The screenshot tour turns off the blinking text cursor so pictures match.
140 lines
3.4 KiB
GDScript
140 lines
3.4 KiB
GDScript
extends GdUnitTestSuite
|
|
## PlayerObject: points, and the first point, match point and winner signals.
|
|
|
|
var _winning_score: int
|
|
var _player: PlayerObject
|
|
|
|
|
|
func before_test() -> void:
|
|
_winning_score = Settings.winning_score
|
|
Settings.winning_score = 3
|
|
_player = PlayerObject.new("Crono")
|
|
|
|
|
|
func after_test() -> void:
|
|
Settings.winning_score = _winning_score
|
|
|
|
|
|
func test_first_point_triggers_first_point_signal() -> void:
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
assert_int(_player.player_score).is_equal(1)
|
|
await assert_signal(_player).is_emitted("first_point_triggered")
|
|
await assert_signal(_player).is_emitted("player_point_given")
|
|
|
|
|
|
func test_one_point_from_winning_triggers_match_point() -> void:
|
|
_player.add_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
await assert_signal(_player).is_emitted("match_point_triggered")
|
|
|
|
|
|
func test_reaching_winning_score_triggers_winner() -> void:
|
|
_player.add_point()
|
|
_player.add_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
assert_int(_player.player_score).is_equal(3)
|
|
await assert_signal(_player).is_emitted("winner_triggered")
|
|
|
|
|
|
func test_score_does_not_go_past_winning_score() -> void:
|
|
for i: int in 3:
|
|
_player.add_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
assert_int(_player.player_score).is_equal(3)
|
|
await assert_signal(_player).wait_until(50).is_not_emitted("player_point_given")
|
|
|
|
|
|
func test_ordinary_point_plays_point_sound() -> void:
|
|
Settings.winning_score = 10
|
|
_player.add_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
await assert_signal(_player).is_emitted("point_given_sound")
|
|
|
|
|
|
func test_minus_point_lowers_score() -> void:
|
|
_player.add_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.minus_point()
|
|
|
|
assert_int(_player.player_score).is_equal(0)
|
|
await assert_signal(_player).is_emitted("player_point_taken")
|
|
|
|
|
|
func test_score_does_not_go_below_zero() -> void:
|
|
monitor_signals(_player, false)
|
|
|
|
_player.minus_point()
|
|
|
|
assert_int(_player.player_score).is_equal(0)
|
|
await assert_signal(_player).wait_until(50).is_not_emitted("player_point_taken")
|
|
|
|
|
|
func test_dropping_back_to_zero_allows_first_point_again() -> void:
|
|
_player.add_point()
|
|
_player.minus_point()
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
await assert_signal(_player).is_emitted("first_point_triggered")
|
|
|
|
|
|
func test_reset_points() -> void:
|
|
_player.add_point()
|
|
_player.add_point()
|
|
|
|
_player.reset_points()
|
|
|
|
assert_int(_player.player_score).is_equal(0)
|
|
assert_bool(_player.is_first_point).is_true()
|
|
|
|
|
|
func test_id_is_a_uuid() -> void:
|
|
var uuid_pattern: RegEx = RegEx.create_from_string(
|
|
"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
|
|
|
|
assert_object(uuid_pattern.search(_player.id)).is_not_null()
|
|
|
|
|
|
func test_every_player_gets_a_different_id() -> void:
|
|
var ids: Dictionary = {}
|
|
for i: int in 100:
|
|
ids[PlayerObject.new("Player %d" % i).id] = true
|
|
|
|
assert_int(ids.size()).is_equal(100)
|
|
|
|
|
|
func test_winning_score_of_one_is_won_with_first_point() -> void:
|
|
Settings.winning_score = 1
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
await assert_signal(_player).is_emitted("winner_triggered")
|
|
|
|
|
|
func test_first_point_is_match_point_when_winning_score_is_two() -> void:
|
|
Settings.winning_score = 2
|
|
monitor_signals(_player, false)
|
|
|
|
_player.add_point()
|
|
|
|
await assert_signal(_player).is_emitted("match_point_triggered")
|
|
assert_bool(_player.is_first_point).is_false()
|