5f3875bc14
- Introduced a new file `life_rules.txt` to define life progression and degradation rules. - Created `test_civilization_state.gd` to validate the functionality of civilization rules and ethics. - Added `test_life.gd` to test life evolution, including initialization, batch processing, and state validation. - Implemented `civilization_state.gd` to manage civilization ethics and space civilization detachment logic. - Ensured all tests check for expected outcomes and validate state integrity after operations.
76 lines
3.6 KiB
GDScript
76 lines
3.6 KiB
GDScript
extends SceneTree
|
|
const Clock = preload("res://world/owniverse/simulation_time.gd")
|
|
var checks: int = 0
|
|
var failures: int = 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run")
|
|
|
|
func check(condition: bool, message: String) -> void:
|
|
checks += 1
|
|
if not condition:
|
|
failures += 1
|
|
push_error(message)
|
|
|
|
func fixture():
|
|
var world = load("res://world/owniverse/owniverse.gd").new()
|
|
var global: Node = root.get_node("Global")
|
|
for id in global.OwniverseEntities:
|
|
var entity = load("res://world/owniverse/owniverse_entity.gd").new(global.OwniverseEntities[id])
|
|
world.entities[id] = entity
|
|
world.state.amount[id] = 0.0
|
|
world.state.stats.total_amount[id] = 0.0
|
|
if entity.group_as != "":
|
|
world.state.amount[entity.group_as] = 0.0
|
|
world.state.stats.total_amount[entity.group_as] = 0.0
|
|
world.entities["N"].life_product = {}
|
|
world.entities["N"].product_per_year_type = "H"
|
|
world.entities["N"].product_per_year_amount = 10.0
|
|
world.entities["N"].auto = 0.0
|
|
world.state.amount.N = 1.0
|
|
return world
|
|
|
|
func dispose(world) -> void:
|
|
for entity in world.entities.values():
|
|
entity.free()
|
|
world.free()
|
|
|
|
func run() -> void:
|
|
var world = fixture()
|
|
var global: Node = root.get_node("Global")
|
|
check(global.CivilizationRules.size() == 43, "Load all ethical civilization stages")
|
|
for row: Dictionary in global.CivilizationRules.values():
|
|
check(row.ethics.size() == 6, "Every ethical stage has six rules")
|
|
world.state.amount["C0.2"] = 8.0
|
|
world.state.binds.RD = {"C2.0": 12.0, "C1.9": 3.0}
|
|
world.initialize_life_batches()
|
|
check(world.state.amount["C2.0"] == 12.0 and world.state.binds.RD["C2.0"] == 0.0, "Old space civilizations detach without loss")
|
|
check(world.state.binds.RD["C1.9"] == 3.0, "Planetary civilizations retain their host")
|
|
check(world.state.ethics["C0.2"] == {"m": 2.0, "l": 2.0, "w": 1.0, "d": 1.0, "c": 1.0, "b": 1.0}, "Migration uses equal ethics and deterministic remainder")
|
|
check(world.state.ethics["C2.0"].values().all(func(n): return n == 2.0), "Bound civilization ethics count physical population")
|
|
var before: Dictionary = world.state.duplicate(true)
|
|
world.initialize_life_batches()
|
|
check(world.state == before, "Repeated initialization preserves ethics")
|
|
world.state.ethics["C0.2"] = {"m": 8.0, "l": 0.0, "w": 0.0, "d": 0.0, "c": 0.0, "b": 0.0}
|
|
world.initialize_life_batches()
|
|
check(world.state.ethics["C0.2"].m == 8.0, "Existing unequal distribution is retained")
|
|
world.state.amount["C0.2"] = 3.0
|
|
world.initialize_life_batches()
|
|
check(world.state.ethics["C0.2"].m == 3.0, "Losses reduce ethics without inventing population")
|
|
check(root.get_node("SaveManager").validate_data({"state": world.state}) == "", "Ethics state validates")
|
|
var restored = fixture()
|
|
restored.state = bytes_to_var(var_to_bytes(world.state))
|
|
restored.initialize_life_batches()
|
|
check(restored.state == world.state, "Save roundtrip preserves ethics and ownership")
|
|
dispose(restored)
|
|
dispose(world)
|
|
world = fixture()
|
|
world.entities["C1.9"].output_and = {"C2.0": 1.0}
|
|
world.state.binds.RD = {"C1.9": 10.0}
|
|
world.state.batches["C1.9"] = [{"amount": 10.0, "start_year": 1.0, "end_year": 1.0}]
|
|
world._evolve_batches(world.state, 1.0)
|
|
check(world.state.amount["C2.0"] == 10.0 and world.state.binds.RD.get("C2.0", 0.0) == 0.0, "Space successor does not inherit planetary binding")
|
|
dispose(world)
|
|
print("Civilization state: %d checks, %d failures" % [checks, failures])
|
|
quit(0 if failures == 0 else 1)
|