2026-09-20 23:55:38 +03:00
extends SceneTree
2026-09-30 08:08:27 +03:00
const E = preload ( "res://world/owniverse/math/exact.gd" )
2026-09-20 23:55:38 +03:00
var failures : int = 0
var checks : int = 0
func _initialize () -> void :
call_deferred ( "run" )
func check ( value : bool , message : String ) -> void :
2026-09-30 08:08:27 +03:00
checks = E . add ( checks , 1 )
if ( not value ):
failures = E . add ( failures , 1 )
2026-09-20 23:55:38 +03:00
push_error ( message )
func run () -> void :
var actions = load ( "res://ui/actions/actions.tscn" ) . instantiate ()
root . add_child ( actions )
2026-10-01 07:48:52 +03:00
for maximum in [ 0 , E . of ( "0.1" ), E . of ( "0.99" ), 1 , E . of ( "1.9" ), 10 , 100 , 123 , 1000 , 10000 , E . of ( "1e9" ), E . of ( "1.1e9" ), E . of ( "9e27" )]:
2026-09-21 20:42:40 +03:00
actions . set_actions ( "test" , maximum )
var labels : Array = []
var values : Array = []
for i in 5 :
2026-09-30 08:08:27 +03:00
var value : Variant = actions . action_values [ i ]
2026-09-21 20:42:40 +03:00
var text : String = actions . action_labels [ i ] . text
2026-09-30 08:08:27 +03:00
check (( E . eq ( value , E . floor_value ( value )) and E . le ( value , E . floor_value ( maximum ))), "Whole affordable request" )
if E . gt ( value , 0 ):
check ((( not values . has ( value )) and ( not labels . has ( text ))), "Unique requests and displayed labels" )
2026-09-21 20:42:40 +03:00
values . append ( value )
labels . append ( text )
else :
2026-09-30 08:08:27 +03:00
check (( E . eq ( text , "" ) and actions . action_labels [ i ] . get_parent () . get_node ( "TextureButton" ) . disabled ), "Unused button blank and disabled" )
if E . ge ( maximum , 1 ): check ( E . eq ( values . back (), E . floor_value ( maximum )), "Maximum retained" )
actions . set_actions ( "test" , 100 )
check ( E . eq ( actions . action_values . values (), [ 1 , 10 , 100 , 0 , 0 ]), "Exact power of ten not duplicated" )
actions . set_actions ( "SMBH" , 25 , func ( _request ) : return 25 )
check ( E . eq ( actions . action_values . values (), [ 25 , 0 , 0 , 0 , 0 ]), "Identical SMBH previews collapse to one button" )
actions . set_actions ( "step" , 123 , func ( request ) : return E . multiply ( E . floor_value ( E . divide ( request , 5 )), 5 ))
check ( E . eq ( actions . action_values . values (), [ 10 , 100 , 123 , 0 , 0 ]), "Unproducible small requests omitted" )
check ( E . eq ( actions . action_labels [ 2 ] . text , "120" ), "Recipe preview displayed while original request retained" )
2026-10-08 22:19:29 +03:00
actions . mark_pending ( 123 )
check ( actions . action_labels [ 2 ] . text == "…" and actions . action_labels [ 2 ] . get_parent () . get_node ( "TextureButton" ) . disabled , "Queued action is visibly pending and cannot be duplicated" )
actions . set_actions ( "step" , 123 , func ( request ) : return E . multiply ( E . floor_value ( E . divide ( request , 5 )), 5 ))
check ( actions . action_labels [ 2 ] . text == "120" and not actions . action_labels [ 2 ] . get_parent () . get_node ( "TextureButton" ) . disabled , "Action refresh clears pending state" )
2026-09-21 20:42:40 +03:00
var emitted : Array = []
2026-09-30 08:08:27 +03:00
actions . action_pressed . connect ( func ( _page , amount ) : emitted . append ( amount ))
2026-09-21 20:42:40 +03:00
actions . _on_action_button_pressed ( 2 )
actions . _on_action_button_pressed ( 4 )
2026-09-30 08:08:27 +03:00
check ( E . eq ( emitted , [ 123 ]), "Only active button emits its matching request" )
2026-09-20 23:55:38 +03:00
actions . queue_free ()
2026-09-30 08:08:27 +03:00
print (( "Action values: %d checks, %d failures" % [ checks , failures ]))
quit (( 0 if E . eq ( failures , 0 ) else 1 ))