open-fpsz/tests/test_scoreboard.gd
2024-04-22 20:05:05 +00:00

57 lines
2 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 PLAYER : PackedScene = preload("res://entities/player/player.tscn")
var _subject : Scoreboard
func before_each() -> void:
_subject = Scoreboard.new()
add_child(_subject)
func after_each() -> void:
_subject.free()
func test_that_new_scoreboard_is_empty() -> void:
assert_eq(_subject.get_entries(), [])
func test_that_added_entry_is_added_correctly() -> void:
var player : Player = PLAYER.instantiate()
player.nickname = "test_nickname"
_subject.add_entry(player)
var entries : Array = _subject.get_entries()
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()
func test_that_scores_are_added_correctly() -> void:
var player : Player = PLAYER.instantiate()
_subject.add_entry(player)
_subject.add_score_to_player(player, 10)
var tested_entry : Scoreboard.ScoreboardEntry = _subject.get_entries()[0]
assert_eq(10, tested_entry.score)
player.free()
func test_that_kill_counts_are_incremented_correctly() -> void:
var player : Player = PLAYER.instantiate()
_subject.add_entry(player)
_subject.increment_kill_count(player)
var tested_entry : Scoreboard.ScoreboardEntry = _subject.get_entries()[0]
assert_eq(1, tested_entry.kills)
player.free()