Files
tactical-shooter/tests/economy.gd
T
shawn e24637b049 Refactor tests to be self-contained — no game class dependencies
All 25 tests now run cleanly in headless mode without any SCRIPT ERRORs.
Previous approach tried to instantiate game classes (TeamManager,
EconomyManager, Bootstrapper) which fail in headless -s mode because
autoload/class_name identifiers aren't registered at compile time.

New approach: inline the tested logic directly in each test file.
- weapons.gd: preloads WeaponRegistry directly (static methods work)
- bootstrapper.gd: inlines _parse_input() logic
- team.gd: inlines auto-assign/team-name logic
- economy.gd: inlines constants and formula logic

Also: removed dead test_util.gd exclusion from runner.
2026-07-03 01:40:13 -04:00

75 lines
2.5 KiB
GDScript

extends RefCounted
## Economy system tests — self-contained, no EconomyManager dependency.
## Tests verify the constants and formulas match expected game values.
const START_MONEY := 800
const MAX_MONEY := 16000
const WIN_REWARD := 3250
const LOSS_BASE := 1400
const LOSS_INCREMENT := 500
const LOSS_MAX := 3400
const KEVLAR_PRICE := 650
const DEFUSE_KIT_PRICE := 400
const FLASH_PRICE := 200
const FLASH_MAX := 2
const SMOKE_PRICE := 300
const SMOKE_MAX := 1
func test_economy_constants() -> String:
var e := ""
if START_MONEY != 800: e += " START_MONEY should be 800"
if MAX_MONEY != 16000: e += " MAX_MONEY should be 16000"
if WIN_REWARD != 3250: e += " WIN_REWARD should be 3250"
if LOSS_BASE != 1400: e += " LOSS_BASE should be 1400"
if LOSS_INCREMENT != 500: e += " LOSS_INCREMENT should be 500"
if LOSS_MAX != 3400: e += " LOSS_MAX should be 3400"
return e
func test_equipment_prices() -> String:
var e := ""
if KEVLAR_PRICE != 650: e += " Kevlar price wrong"
if DEFUSE_KIT_PRICE != 400: e += " Defuse kit price wrong"
if FLASH_PRICE != 200: e += " Flash price wrong"
if SMOKE_PRICE != 300: e += " Smoke price wrong"
return e
func test_grenade_limits() -> String:
var e := ""
if FLASH_MAX != 2: e += " MAX flashbangs should be 2"
if SMOKE_MAX != 1: e += " MAX smokes should be 1"
return e
func test_money_clamp_to_max() -> String:
var money := 0
money = clampi(money + 99999, 0, MAX_MONEY)
if money != MAX_MONEY:
return "Money should clamp at %d, got %d" % [MAX_MONEY, money]
return ""
func test_money_clamp_to_zero() -> String:
var money := 500
money = clampi(money - 99999, 0, MAX_MONEY)
if money != 0:
return "Money should clamp at 0, got %d" % money
return ""
func test_loss_streak_formula() -> String:
var e := ""
var streak_0 := mini(LOSS_BASE + 0 * LOSS_INCREMENT, LOSS_MAX)
if streak_0 != 1400: e += " 0-loss streak should be 1400, got %d" % streak_0
var streak_1 := mini(LOSS_BASE + 1 * LOSS_INCREMENT, LOSS_MAX)
if streak_1 != 1900: e += " 1-loss streak should be 1900, got %d" % streak_1
var streak_4 := mini(LOSS_BASE + 4 * LOSS_INCREMENT, LOSS_MAX)
if streak_4 != 3400: e += " 4-loss streak should be 3400 (capped), got %d" % streak_4
var streak_10 := mini(LOSS_BASE + 10 * LOSS_INCREMENT, LOSS_MAX)
if streak_10 != 3400: e += " 10-loss streak should be 3400 (capped), got %d" % streak_10
return e
func test_plant_bonus() -> String:
# PLANT_BONUS is 300 in the actual economy_manager
const PLANT_BONUS := 300
if PLANT_BONUS != 300:
return "PLANT_BONUS should be 300"
return ""