2026-09-20 20:56:15 +03:00
extends SceneTree
2026-09-30 08:08:27 +03:00
const E = preload ( "res://world/owniverse/math/exact.gd" )
2026-09-20 20:56:15 +03:00
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 :
2026-09-30 08:08:27 +03:00
checks = E . add ( checks , 1 )
if ( not condition ):
failures = E . add ( failures , 1 )
2026-09-20 20:56:15 +03:00
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 ])
2026-09-29 20:23:20 +03:00
world . catalog . entities [ id ] = entity
2026-09-30 08:08:27 +03:00
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
2026-09-29 20:23:20 +03:00
world . catalog . entities [ "N" ] . life_product = {}
world . catalog . entities [ "N" ] . product_per_year_type = "H"
2026-09-30 08:08:27 +03:00
world . catalog . entities [ "N" ] . product_per_year_amount = 10
world . catalog . entities [ "N" ] . auto = 0
world . state . amount . N = 1
2026-09-20 20:56:15 +03:00
return world
func dispose ( world ) -> void :
2026-09-29 20:23:20 +03:00
for entity in world . catalog . entities . values ():
2026-09-20 20:56:15 +03:00
entity . free ()
world . free ()
func run () -> void :
var world = fixture ()
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
world . catalog . entities . N . cost = { "H" : 2 }
world . catalog . entities . N . bind = { "S" : 3 }
world . state . amount . H = 10
world . state . amount . S = 0
2026-10-01 07:48:52 +03:00
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . N ), 0 ), "Default maximum respects missing bindings" )
world . state . amount . S = 30
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . N ), 5 ), "Default maximum uses recipe resources without an oversized sentinel" )
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . N , 2 ), 2 ), "Explicit production limit is preserved" )
world . state . amount . H = E . of ( "1e27" )
world . state . amount . S = E . of ( "1e27" )
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . N ), E . floor_value ( E . divide ( E . of ( "1e27" ), 3 ))), "Default maximum at E27 retains integer precision" )
world . state . amount . BH25 = 4
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . SMBH ), world . production . smbh_available ()), "Default SMBH maximum uses available black-hole mass" )
world . state . amount . BH25 = 0
check ( E . eq ( world . production . calculate_max_producible ( world . catalog . entities . SMBH ), 0 ), "Empty SMBH maximum is zero" )
world . state . amount . H = 10
world . state . amount . S = 0
2026-09-30 08:08:27 +03:00
world . state . auto_resources = { "H" : 10 }
world . state . batches . H = [{ "amount" : 10 , "start_year" : 1 , "end_year" : 2 }]
2026-09-20 20:56:15 +03:00
var before : Dictionary = world . state . duplicate ( true )
2026-10-08 21:10:36 +03:00
var physical : Dictionary = world . ledger . physical_amounts ( world . state )
var frozen_physical : Dictionary = physical . duplicate ()
check (( not world . production . try_production ( world . state , world . catalog . entities . N , 1 , true , physical )), "Binding failure rejects production" )
check ( E . eq ( physical , frozen_physical ), "Failed production preserves the shared quantity snapshot" )
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state , before ), "Failure preserves costs, batches and budget" )
world . state . amount . S = 10
2026-10-08 21:10:36 +03:00
physical = world . ledger . physical_amounts ( world . state )
2026-09-20 20:56:15 +03:00
var old_batches : Array = world . state . batches . H
2026-10-08 21:10:36 +03:00
check ( world . production . try_production ( world . state , world . catalog . entities . N , 2 , true , physical ), "Funded production succeeds" )
check ( E . eq ( physical , world . ledger . physical_amounts ( world . state )), "Successful production updates exact totals without changing bound-resource totals" )
2026-09-30 08:08:27 +03:00
check (( E . eq ( world . state . amount . H , 6 ) and E . eq ( world . state . amount . S , 4 )), "Exact cost and binding" )
check ( E . eq ( world . state . auto_resources . H , 6 ), "Exact automatic budget" )
check (( E . eq ( old_batches [ 0 ] . amount , 10 ) and E . eq ( world . state . batches . H [ 0 ] . amount , 6 )), "Consumed batches isolated" )
2026-10-08 22:19:29 +03:00
for member in world . catalog . members ( "Star" ): world . state . amount [ member ] = 0
var star_stocks : Array = [ "1234567890123456789" , "876543210987654321" , "3141592653589793238" , "2718281828459045235" , "1414213562373095048" , "1732050807568877293" , "2236067977499789696" , "2449489742783178098" , "3162277660168379331" ]
for i in star_stocks . size (): world . state . amount [ world . catalog . members ( "Star" )[ i ]] = E . of ( star_stocks [ i ])
var scd_request : Variant = E . of ( "1e15" )
var scd_created : Variant = world . production . produce ( "SCD" , scd_request )
check ( E . eq ( scd_created , scd_request ), "Large SCD production distributes a whole star quota exactly" )
check ( E . eq ( world . state . amount . SCD , scd_request ), "Large SCD creation is committed" )
2026-09-30 08:08:27 +03:00
print (( "Transaction: %d checks, %d failures" % [ checks , failures ]))
2026-09-20 20:56:15 +03:00
dispose ( world )
2026-09-30 08:08:27 +03:00
quit (( 1 if failures else 0 ))