Files
owniverse/tests/test_module_lifecycle.gd
Kirill 3fcc7211ce Implement civilization flow mechanics and profiling for resource allocation
- Added `civilization_flow.gd` to manage continuous expected flows and resource allocation within civilizations.
- Introduced `allocate_profiled` and `whole_quotas` functions in `quantity_math.gd` for precise stock allocation based on float shares.
- Enhanced `credit` logic in `object_ledger.gd` to handle production remainders more effectively.
- Updated `append_batch` in `object_batches.gd` to prevent batch creation for invalid IDs.
- Introduced `ratio_approx` function in `exact.gd` for better handling of float profiles.
- Added a benchmark script `benchmark_civilization_flows.gd` to evaluate the performance of civilization flow mechanics.
- Refactored various functions to improve clarity and efficiency in handling resource flows and allocations.
2026-10-07 22:51:55 +03:00

40 lines
1.6 KiB
GDScript

extends SceneTree
const E = preload("res://world/owniverse/math/exact.gd")
var checks: int = 0
var failures: int = 0
func _initialize() -> void:
call_deferred("run")
func check(condition: bool, message: String) -> void:
checks = E.add(checks, 1)
if (not condition):
failures = E.add(failures, 1)
push_error(message)
func run() -> void:
var World = load("res://world/owniverse/owniverse.gd")
var first = World.new()
var second = World.new()
var names: Array = ["batches", "ledger", "production", "automatic", "stellar", "life", "environment", "evolution", "civilization_flow"]
var references: Array = []
for name in names:
check(E.ne(first.get(name), second.get(name)), E.add("World has its own ", name))
check(E.eq(first.get(name).world, first), E.add("Module refers to its owner: ", name))
references.append(weakref(first.get(name)))
first.state.amount.H = 123
first.presentation.pending_amounts.H = 123
check(((not second.state.amount.has("H")) and second.presentation.pending_amounts.is_empty()), "State and pending presentation are isolated")
first.free()
for reference in references:
check(E.eq(reference.get_ref(), null), "Module is released with its world")
check(E.eq(second.evolution.world, second), "Other world remains usable")
var snapshot: Dictionary = second.state.duplicate(true)
second.evolute(NAN)
second.evolute(E.neg(1))
check(E.eq(second.state, snapshot), "Entry point rejects invalid time deltas")
second.free()
print(("Module lifecycle: %d checks, %d failures" % [checks, failures]))
quit((1 if failures else 0))