open-fpsz/tests/test_systems_scoreboard.gd
2024-04-15 02:13:20 -04:00

61 lines
2.1 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 scoreboard : Scoreboard
func before_all():
# test init with params
scoreboard = Scoreboard.new(1,2)
# check if `num_teams` is correctly initialized
assert_true(scoreboard.scoreboard.size() == 1)
# check if `num_players_per_team` is correctly initialized
assert_true(scoreboard.scoreboard[1].size() == 2)
scoreboard.queue_free()
# test default init
scoreboard = Scoreboard.new()
# check if `num_teams` is correctly initialized
assert_true(scoreboard.scoreboard.size() == 1)
# check if `num_players_per_team` is correctly initialized
assert_true(scoreboard.scoreboard[1].size() == 1)
func test_update_score():
# update offense score for team 1, player 1 by 5 points
scoreboard.update_score(1, 1, 5, 'O')
# check player score
var player_score = scoreboard.get_player_score(1, 1)
assert_true(player_score['O'] == 5)
func test_get_player_score():
# update offense score for team 1, player 1 by 5 points
scoreboard.update_score(1, 1, 5, 'O')
var player_score = scoreboard.get_player_score(1, 1)
# check player score
assert_true(player_score['O'] == 10)
func test_get_team_score():
# update offense score for team 1, player 1 by 5 points
scoreboard.update_score(1, 1, 5, 'O')
# update defense score for team 1, player 1 by 5 points
scoreboard.update_score(1, 1, 5, 'D')
var team_score = scoreboard.get_team_score(1)
# check team score
assert_true(team_score['O'] == 15)
assert_true(team_score['D'] == 5)
func after_all():
scoreboard.queue_free()