62 lines
2.2 KiB
GDScript
62 lines
2.2 KiB
GDScript
extends SceneTree
|
|
|
|
var _failures := 0
|
|
var _checks := 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
func _run() -> void:
|
|
print("The Tree: automated checks")
|
|
_test_game_clock()
|
|
_test_game_state()
|
|
_test_facility_data()
|
|
load("res://tests/s0/test_kernel_and_save.gd").run(Callable(self, "_expect"))
|
|
if _failures == 0:
|
|
print("PASS: %d checks" % _checks)
|
|
else:
|
|
push_error("FAIL: %d of %d checks failed" % [_failures, _checks])
|
|
quit(_failures)
|
|
|
|
func _test_game_clock() -> void:
|
|
var clock = load("res://autoload/game_clock.gd").new()
|
|
clock.reset(1, 6, 0)
|
|
_expect(clock.get_phase() == clock.Phase.MORNING, "06:00 is morning")
|
|
clock.advance_minutes(4 * 60)
|
|
_expect(clock.get_hour() == 10, "clock advances to 10:00")
|
|
_expect(clock.get_phase() == clock.Phase.DAY, "10:00 is day phase")
|
|
clock.set_speed(4)
|
|
_expect(clock.speed == 4, "clock accepts the specified x4 speed")
|
|
clock.set_speed(3)
|
|
_expect(clock.speed == 4, "clock rejects unsupported speed values")
|
|
clock.advance_minutes(14 * 60)
|
|
_expect(clock.day == 2 and clock.get_hour() == 0, "midnight starts the next day")
|
|
clock.free()
|
|
|
|
func _test_game_state() -> void:
|
|
var state = load("res://autoload/game_state.gd").new()
|
|
state.reset()
|
|
_expect(state.can_afford({&"gold": 500, &"materials": 5}), "default resources can afford starter room")
|
|
_expect(state.spend({&"gold": 500, &"materials": 5}), "spending succeeds")
|
|
_expect(state.get_resource(&"gold") == 4500, "gold is deducted atomically")
|
|
_expect(not state.spend({&"mana": 1000}), "overspending is rejected")
|
|
state.free()
|
|
|
|
func _test_facility_data() -> void:
|
|
var catalog_script = load("res://scripts/data/facility_catalog.gd")
|
|
var facilities: Array = catalog_script.load_all()
|
|
_expect(facilities.size() == 16, "MVP facility catalog loads all baseline definitions")
|
|
var seen_ids := {}
|
|
for facility in facilities:
|
|
_expect(facility.is_valid(), "%s has valid data" % facility.resource_path)
|
|
_expect(not seen_ids.has(facility.id), "%s has a unique id" % facility.id)
|
|
seen_ids[facility.id] = true
|
|
|
|
func _expect(condition: bool, label: String) -> void:
|
|
_checks += 1
|
|
if condition:
|
|
print(" ✓ %s" % label)
|
|
return
|
|
_failures += 1
|
|
push_error(" ✗ %s" % label)
|