Files
owniverse/tests/test_descriptions.gd
Kirill c4e7302567 Add new tests and implement frame budget management
- Introduced `civilization_benchmark.gd` and `legacy_quantity_math.gd` for benchmarking and legacy quantity calculations.
- Created `test_dynamic_math.gd`, `test_frame_evolution.gd`, and `test_sparse_batches.gd` to validate mathematical operations and frame evolution logic.
- Implemented `frame_budget.gd` to manage cooperative work on the main thread, ensuring no partially calculated state is published.
- Added UID files for all new scripts to maintain unique identifiers.
2026-10-01 23:43:34 +03:00

98 lines
5.1 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends SceneTree
const E = preload("res://world/owniverse/math/exact.gd")
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 = E.add(checks, 1)
if (not condition):
failures = E.add(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.catalog.entities[id] = entity
world.state.amount[id] = 0
world.state.stats.total_amount[id] = 0
if E.ne(entity.group_as, ""):
world.state.amount[entity.group_as] = 0
world.state.stats.total_amount[entity.group_as] = 0
world.catalog.entities["N"].life_product = {}
world.catalog.entities["N"].product_per_year_type = "H"
world.catalog.entities["N"].product_per_year_amount = 10
world.catalog.entities["N"].auto = 0
world.state.amount.N = 1
return world
func dispose(world) -> void:
for entity in world.catalog.entities.values():
entity.free()
world.free()
func run() -> void:
var global: Node = root.get_node("Global")
var description = load("res://world/owniverse/item_description.gd")
var world = fixture()
world.state.amount.H = 8
world.state.amount.He = 2
for locale in ["en", "ru"]:
global.Locale = locale
var text: String = description.render(world, global, "RD")
check((text.contains("[b]") and (not text.contains("%value"))), E.add("Localized template resolved: ", locale))
check(text.contains("#40cc40"), E.add("Affordable cost green: ", locale))
check(text.contains("40 000 000 000"), E.add("Lifespan substituted: ", locale))
text = description.render(world, global, "He")
check((text.contains("He: 20.00% / H: 80.00%") and (not text.contains("%value"))), E.add("Helium metadata and mixture: ", locale))
text = description.render(world, global, "Shovelin", "Force")
check(E.eq(text.count("]—[/color]"), 4), E.add("Missing force levels use dash: ", locale))
text = description.render(world, global, "YD")
check(text.contains("#ff6060"), E.add("Insufficient cost red: ", locale))
var reordered: Dictionary = {"text": "%value0% / %value1%", "value0": "lifespan", "value1": "amount"}
check(E.eq(global.render_template(reordered, {"amount": "12", "lifespan": "99"}), "99 / 12"), "Metadata chooses variables, not fixed argument positions")
world.state.amount.RD = 2
world.state.binds.G = {"RD": 3, "HP": 7}
var values: Dictionary = description.variables(world, global, "RD", E.neg(2))
check(((values.amount.contains("2") and values.amount.contains("(5)")) and values.amount.contains("#888888")), "Free and total counts with gray binding total")
check((values.amount.contains("#ff6060") and values.amount.contains("−2.0")), "Real-time decrease red")
values = description.variables(world, global, "HP")
check(E.eq(values.amount, "7"), "Planet description includes bound planets")
world.state.amount.EON1 = 2
world.state.binds.G.EON2 = 3
var saved_state: Dictionary = world.state.duplicate(true)
var counters: Dictionary = world.presentation.amounts(world.state, world.catalog)
check(((E.eq(counters.HP, 7) and E.eq(counters.LP, 5)) and E.eq(counters.Planet, 12)), "Planet counters include bound objects and aggregate eons")
check(E.eq(counters.RD, 2), "Star counters retain available quantity")
check(E.eq(world.state, saved_state), "Reading counters does not mutate simulation")
check(E.eq(world.presentation.amounts(world.state, world.catalog, true).HP, 0), "Produced counters remain independent of current population")
values = description.variables(world, global, "RD", 2)
check((values.amount.contains("#40cc40") and values.amount.contains("+2.0")), "Increase green")
var stage_script = load("res://stage/stage.gd")
check(stage_script.can_instantiate(), "Stage integration compiles")
var stage = stage_script.new()
stage.owniverse.free()
stage.owniverse = world
var label: RichTextLabel = RichTextLabel.new()
stage.g_item_descriptions = [label]
stage.description_targets[0] = {"id": "RD", "category": "Entity"}
stage._refresh_descriptions()
check((label.bbcode_enabled and label.text.contains("Красный карлик")), "Stage displays localized rich text")
stage._update_descriptions(0.25)
world.state.amount.RD = E.add(world.state.amount.RD, 1)
stage._update_descriptions(0.25)
check(label.text.contains("+4.0"), "Selected description refreshes with rate per real second")
global.Locale = "en"
stage._update_descriptions(0.25)
check(label.text.contains("Red Dwarf"), "Selected description follows locale changes")
label.free()
stage.free()
dispose(world)
print(("Descriptions: %d checks, %d failures" % [checks, failures]))
quit((0 if E.eq(failures, 0) else 1))