mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-13 07:25:06 +00:00
Extract MatchParticipantComponent from Player entity and fix HealthComponent tests
This commit is contained in:
parent
d238c29f76
commit
b339bf34f0
23 changed files with 149 additions and 124 deletions
|
|
@ -16,11 +16,17 @@ extends GutTest
|
|||
|
||||
var _subject : HealthComponent
|
||||
const TEST_MAX_HEALTH : float = 100.0
|
||||
const TEST_PLAYER_ID : int = 1
|
||||
const TEST_TEAM_ID : int = 1
|
||||
|
||||
func before_each() -> void:
|
||||
_subject = HealthComponent.new()
|
||||
watch_signals(_subject)
|
||||
_subject.max_health = TEST_MAX_HEALTH
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
participant.player_id = TEST_PLAYER_ID
|
||||
participant.team_id = TEST_TEAM_ID
|
||||
_subject.match_participant_component = participant
|
||||
add_child(_subject)
|
||||
|
||||
func after_each() -> void:
|
||||
|
|
@ -29,17 +35,27 @@ func after_each() -> void:
|
|||
func test_that_it_has_max_health_when_ready() -> void:
|
||||
assert_eq(_subject.health, _subject.max_health)
|
||||
|
||||
func test_that_it_takes_damage() -> void:
|
||||
var damage_amount : float = 10
|
||||
_subject.damage(damage_amount, -1, 0)
|
||||
func test_that_it_takes_damage_from_opponent_team() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, -1, -1)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
|
||||
|
||||
func test_that_it_takes_no_damage_from_same_team() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, -1, TEST_TEAM_ID)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH)
|
||||
|
||||
func test_that_it_can_self_damage() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, TEST_PLAYER_ID, TEST_TEAM_ID)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
|
||||
|
||||
func test_that_it_emits_health_changed_after_damage() -> void:
|
||||
_subject.damage(1, -1, 0)
|
||||
_subject.damage(1, -1, -1)
|
||||
assert_signal_emitted(_subject, 'health_changed')
|
||||
|
||||
func test_that_it_emits_health_zeroed() -> void:
|
||||
_subject.damage(TEST_MAX_HEALTH, -1, 0)
|
||||
_subject.damage(TEST_MAX_HEALTH, -1, -1)
|
||||
assert_signal_emitted_with_parameters(_subject, 'health_zeroed', [-1])
|
||||
|
||||
func test_that_it_heals_fully() -> void:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends GutTest
|
||||
|
||||
var PLAYER : PackedScene = preload("res://entities/player/player.tscn")
|
||||
var SCOREBOARD : PackedScene = preload("res://interfaces/scoreboard/scoreboard.tscn")
|
||||
|
||||
var _subject : Scoreboard
|
||||
|
|
@ -30,29 +29,29 @@ func test_that_new_scoreboard_is_empty() -> void:
|
|||
assert_eq(_subject._entries, {})
|
||||
|
||||
func test_that_added_entry_is_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
player.nickname = "test_nickname"
|
||||
_subject.add_player(player)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
participant.nickname = "test_nickname"
|
||||
_subject.add_participant(participant)
|
||||
var entries : Array = _subject._entries.values()
|
||||
assert_eq(1, entries.size())
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = entries[0]
|
||||
assert_eq("test_nickname", tested_entry.nickname)
|
||||
assert_eq(0, tested_entry.kills)
|
||||
assert_eq(0, tested_entry.score)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
||||
func test_that_scores_are_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_player(player)
|
||||
_subject.add_score_to_player(player, 10)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
_subject.add_participant(participant)
|
||||
_subject.add_score_to_player(participant, 10)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]
|
||||
assert_eq(10, tested_entry.score)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
||||
func test_that_kill_counts_are_incremented_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_player(player)
|
||||
_subject.increment_kill_count(player)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
_subject.add_participant(participant)
|
||||
_subject.increment_kill_count(participant)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]
|
||||
assert_eq(1, tested_entry.kills)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue