78 lines
3.7 KiB
GDScript
78 lines
3.7 KiB
GDScript
extends SceneTree
|
|
|
|
const Service = preload("res://p9_3/core_loop_service.gd")
|
|
const State = preload("res://p9_3/core_loop_state.gd")
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
verify_hire_transactions()
|
|
verify_encounter_differences()
|
|
if failures.is_empty():
|
|
print("ABG_P9_3_REFERENCE_FIDELITY_DOMAIN_OK offers=3 encounters=3 company=2/10 hire_once=true rewards=8,12,16 return_preserved=true")
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func verify_hire_transactions() -> void:
|
|
for member_id in ["Wayrunner", "Farstring", "Kindhand"]:
|
|
var service = Service.new()
|
|
expect(service.enter_hall().ok, "%s enters Hall" % member_id)
|
|
var before: Dictionary = service.state.snapshot()
|
|
expect(service.focus_offer(member_id).ok, "%s focuses an available person" % member_id)
|
|
var hired: Dictionary = service.hire(member_id)
|
|
expect(hired.ok and hired.code == "hire_committed", "%s hire commits" % member_id)
|
|
var cost := int(service.offer(member_id).cost)
|
|
expect(service.state.coin == int(before.coin) - cost, "%s deducts the exact cost" % member_id)
|
|
expect(service.state.company == ["Hearthguard", member_id], "%s joins the visible line" % member_id)
|
|
expect(service.state.phase == State.Phase.ENCOUNTER, "%s opens encounter choice" % member_id)
|
|
expect(service.state.hire_receipts.size() == 1, "%s creates one receipt" % member_id)
|
|
var committed: Dictionary = service.state.snapshot()
|
|
var duplicate: Dictionary = service.hire(member_id)
|
|
expect(not duplicate.ok and service.state.snapshot() == committed, "%s duplicate hire is inert" % member_id)
|
|
|
|
|
|
func verify_encounter_differences() -> void:
|
|
var expected := {
|
|
"open_road": {"living": 1, "reward": 8, "lead_position": 100},
|
|
"crosswind": {"living": 2, "reward": 12, "lead_position": 100},
|
|
"bell_breach": {"living": 2, "reward": 16, "lead_position": 72},
|
|
}
|
|
for encounter_id in ["open_road", "crosswind", "bell_breach"]:
|
|
var service = Service.new()
|
|
service.enter_hall()
|
|
service.focus_offer("Farstring")
|
|
service.hire("Farstring")
|
|
expect(service.select_encounter(encounter_id).ok, "%s selects" % encounter_id)
|
|
expect(service.start_battle().ok, "%s starts" % encounter_id)
|
|
expect(service.battle.state.living_enemy_ids().size() == int(expected[encounter_id].living), "%s changes living enemy count" % encounter_id)
|
|
expect(int(service.battle.state.enemy_positions.RiftBulwark) == int(expected[encounter_id].lead_position), "%s changes opening pressure" % encounter_id)
|
|
var guard := 0
|
|
while service.state.phase == State.Phase.BATTLE and guard < 1000:
|
|
service.advance_battle_ticks(1)
|
|
guard += 1
|
|
expect(service.state.phase == State.Phase.RESULT, "%s reaches a bounded result" % encounter_id)
|
|
expect(service.state.last_outcome == "victory", "%s is winnable by the fixed first line" % encounter_id)
|
|
var coin_before: int = service.state.coin
|
|
var returned: Dictionary = service.claim_and_return()
|
|
expect(returned.ok and service.state.phase == State.Phase.HALL, "%s returns to Hall" % encounter_id)
|
|
expect(service.state.coin == coin_before + int(expected[encounter_id].reward), "%s grants exact reward" % encounter_id)
|
|
expect(service.state.company == ["Hearthguard", "Farstring"], "%s preserves the hired line" % encounter_id)
|
|
expect(service.state.reward_receipts.size() == 1, "%s reward commits once" % encounter_id)
|
|
var settled: Dictionary = service.state.snapshot()
|
|
var duplicate: Dictionary = service.claim_and_return()
|
|
expect(not duplicate.ok and service.state.snapshot() == settled, "%s duplicate reward is inert" % encounter_id)
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.3 reference-fidelity domain: %s" % message)
|