mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
✅ add scoreboard tests
This commit is contained in:
parent
7cd8bbeadb
commit
9f4617fb52
|
|
@ -1,14 +1,28 @@
|
|||
class_name Scoreboard extends Node
|
||||
# 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/>.
|
||||
class_name Scoreboard extends Node2D
|
||||
|
||||
# define the properties
|
||||
@export var num_teams: int = 1
|
||||
@export var num_players_per_team: int = 1
|
||||
@export var _num_teams: int = 1
|
||||
@export var _num_players_per_team: int = 1
|
||||
|
||||
# define the scoreboard dictionary
|
||||
var scoreboard := {}
|
||||
|
||||
# initialize the scoreboard
|
||||
func _init() -> void:
|
||||
func _init(num_teams: int = _num_teams, num_players_per_team: int = _num_players_per_team) -> void:
|
||||
scoreboard = {}
|
||||
for team in range(1, num_teams + 1):
|
||||
scoreboard[team] = {}
|
||||
|
|
|
|||
60
tests/test_systems_scoreboard.gd
Normal file
60
tests/test_systems_scoreboard.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# 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()
|
||||
Loading…
Reference in a new issue