2026-10-08 20:43:51 +03:00
|
|
|
extends "res://tests/test_civilization_evolution.gd"
|
|
|
|
|
|
|
|
|
|
func run():
|
|
|
|
|
var rules: Dictionary = root.get_node("Global").CivilizationRules
|
|
|
|
|
for count in [103, E.of("10000000000000000000000000000000000000103"), E.add(E.of("1e400"), 103)]:
|
|
|
|
|
var world = fixture()
|
|
|
|
|
var third: Variant = E.floor_value(E.divide(count, 3))
|
|
|
|
|
var free: Variant = E.subtract(count, E.multiply(third, 2))
|
|
|
|
|
world.state.amount["C0.2"] = free
|
|
|
|
|
world.state.binds.RD = {"C0.2": third}
|
|
|
|
|
world.state.binds.OD = {"C0.2": third}
|
|
|
|
|
var counts: Dictionary = {"C0.2": third, "C0.3": third, "HP": free}
|
|
|
|
|
var profile: Dictionary = {"m": 0.4, "l": 0.2, "w": 0.1, "d": 0.1, "c": 0.1, "b": 0.1}
|
|
|
|
|
var profiles: Dictionary = {}
|
|
|
|
|
for id in counts: profiles[id] = profile
|
|
|
|
|
var physical: Dictionary = world.ledger.physical_amounts(world.state)
|
2026-10-08 21:10:36 +03:00
|
|
|
var initial_physical: Dictionary = physical.duplicate()
|
|
|
|
|
var committed: Dictionary = world.civilization_flow._commit(world.state, physical, {"C0.2": {"counts": counts, "profiles": profiles}}, rules, 100)
|
|
|
|
|
check(E.eq(committed, world.ledger.physical_amounts(world.state)), "Commit snapshot matches a full physical rebuild")
|
|
|
|
|
check(E.eq(physical, initial_physical), "Commit does not mutate its input snapshot")
|
2026-10-08 20:43:51 +03:00
|
|
|
for id in counts:
|
|
|
|
|
check(E.eq(world.ledger.physical_amount(world.state, id), counts[id]), "Commit preserves exact destination quota: " + id)
|
|
|
|
|
for owner in ["RD", "OD"]:
|
|
|
|
|
var held: Variant = 0
|
|
|
|
|
for id in counts: held = E.add(held, world.state.binds[owner].get(id, 0))
|
|
|
|
|
check(E.eq(held, third), "Commit preserves each owner's exact population")
|
|
|
|
|
for id in ["C0.2", "C0.3"]:
|
|
|
|
|
for ethic in profile: check(absf(world.state.ethics[id][ethic] - profile[ethic]) < 1e-12, "Commit preserves incoming ethical profile")
|
|
|
|
|
invariants(world)
|
|
|
|
|
dispose(world)
|
|
|
|
|
world = fixture()
|
|
|
|
|
world.state.binds.RD = {"C4.4": count}
|
|
|
|
|
var terminal: Dictionary = {"Ct": State.empty_profile()}
|
|
|
|
|
world.civilization_flow._commit(world.state, world.ledger.physical_amounts(world.state), {"C4.4": {"counts": {"Ct": count}, "profiles": terminal}}, rules, 100)
|
|
|
|
|
check(E.eq(world.state.amount.Ct, count), "Transcendent population is entirely free")
|
|
|
|
|
check(E.eq(world.state.binds.RD.get("Ct", 0), 0), "Transcendent population cannot retain a stellar owner")
|
|
|
|
|
dispose(world)
|
|
|
|
|
world = fixture()
|
2026-10-08 21:10:36 +03:00
|
|
|
world.state.amount["C2.0"] = count
|
|
|
|
|
var initial_capacity: Dictionary = world.ledger.physical_amounts(world.state)
|
|
|
|
|
var frozen_capacity: Dictionary = initial_capacity.duplicate()
|
|
|
|
|
var constrained: Dictionary = State.enforce_capacity(world, world.state, rules, 100, initial_capacity)
|
|
|
|
|
check(E.eq(constrained, world.ledger.physical_amounts(world.state)), "Cascading capacity changes maintain exact physical totals")
|
|
|
|
|
check(E.eq(initial_capacity, frozen_capacity), "Capacity correction does not mutate the previous snapshot")
|
|
|
|
|
dispose(world)
|
|
|
|
|
world = fixture()
|
2026-10-08 20:43:51 +03:00
|
|
|
var original_owners: Dictionary = {}
|
|
|
|
|
for owner in ["RD", "OD", "YD", "WYD"]:
|
|
|
|
|
world.state.binds[owner] = {}
|
|
|
|
|
for resource in ["GG", "AB", "RP", "HP"]:
|
|
|
|
|
world.state.binds[owner][resource] = count
|
|
|
|
|
original_owners[owner] = E.multiply(count, 4)
|
|
|
|
|
var colonies: Dictionary = {
|
|
|
|
|
"C1.4": {"counts": {"C1.4": E.multiply(count, 3)}, "profiles": {"C1.4": profile}},
|
|
|
|
|
"C1.5": {"counts": {"C1.5": E.multiply(count, 5)}, "profiles": {"C1.5": profile}}
|
|
|
|
|
}
|
2026-10-08 21:10:36 +03:00
|
|
|
var physical_before: Dictionary = world.ledger.physical_amounts(world.state)
|
|
|
|
|
var untouched: Dictionary = physical_before.duplicate()
|
|
|
|
|
var colonized: Dictionary = world.civilization_flow._colonize(world.state, colonies, 100, rules, physical_before)
|
|
|
|
|
check(E.eq(colonized, world.ledger.physical_amounts(world.state)), "Colonization snapshot matches a full physical rebuild")
|
|
|
|
|
check(E.eq(physical_before, untouched), "Colonization does not mutate its input snapshot")
|
|
|
|
|
var capacity: Dictionary = State.enforce_capacity(world, world.state, rules, 100, colonized)
|
|
|
|
|
check(E.eq(capacity, world.ledger.physical_amounts(world.state)), "Capacity snapshot matches a full physical rebuild")
|
2026-10-08 20:43:51 +03:00
|
|
|
check(E.eq(world.ledger.physical_amount(world.state, "C1.4"), E.multiply(count, 3)), "Colonization credits exact first quota")
|
|
|
|
|
check(E.eq(world.ledger.physical_amount(world.state, "C1.5"), E.multiply(count, 5)), "Colonization credits exact second quota")
|
|
|
|
|
check(E.eq(world.state.stats.total_amount["C1.4"], E.multiply(count, 3)), "Consolidated credit preserves creation statistics")
|
|
|
|
|
check(E.eq(world.state.civilization_stats.colonies, E.multiply(count, 8)), "Colonization statistics equal exact granted total")
|
|
|
|
|
for owner in original_owners:
|
|
|
|
|
var held: Variant = 0
|
|
|
|
|
for id in ["GG", "AB", "RP", "HP", "C1.4", "C1.5"]: held = E.add(held, world.state.binds[owner].get(id, 0))
|
|
|
|
|
check(E.eq(held, original_owners[owner]), "Colonization preserves each owner's occupied worlds")
|
|
|
|
|
var remaining_planets: Variant = 0
|
|
|
|
|
for id in ["GG", "AB", "RP", "HP"]: remaining_planets = E.add(remaining_planets, world.ledger.physical_amount(world.state, id))
|
|
|
|
|
check(E.eq(remaining_planets, E.multiply(count, 8)), "Planet loss equals colonies created")
|
|
|
|
|
invariants(world)
|
|
|
|
|
dispose(world)
|
|
|
|
|
print("Flow commit: %d checks, %d failures" % [checks, failures])
|
|
|
|
|
quit(1 if failures else 0)
|