mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
69 lines
2.5 KiB
GDScript
69 lines
2.5 KiB
GDScript
# This file is part of open-fpsz.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
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_autofree(_subject)
|
|
|
|
func after_each() -> void:
|
|
_subject.match_participant_component.free()
|
|
|
|
func test_that_it_has_max_health_when_ready() -> void:
|
|
assert_eq(_subject.health, _subject.max_health)
|
|
|
|
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, -1)
|
|
assert_signal_emitted(_subject, 'health_changed')
|
|
|
|
func test_that_it_emits_health_zeroed() -> void:
|
|
_subject.damage(TEST_MAX_HEALTH, -1, -1)
|
|
assert_signal_emitted_with_parameters(_subject, 'health_zeroed', [-1])
|
|
|
|
func test_that_it_heals_fully() -> void:
|
|
_subject.health = 10
|
|
_subject.heal_full()
|
|
assert_eq(_subject.health, TEST_MAX_HEALTH)
|
|
|
|
func test_that_it_emits_health_changed_after_heal_full() -> void:
|
|
_subject.heal_full()
|
|
assert_signal_emitted(_subject, 'health_changed')
|