Add unit tests for action value formatting and distribution

- Implemented a new test script `test_action_values.gd` to verify the precision of fractional action amounts and the distinctiveness of adjacent values.
- Added checks to ensure that action values are correctly formatted and that the distribution of actions preserves distinct requests.
- Included validation for rendered button labels to confirm they are distinguishable.
This commit is contained in:
Kirill
2026-09-20 23:55:38 +03:00
parent f25b77b605
commit f246efd6ad
30 changed files with 221 additions and 1 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
extends SceneTree
var failures: int = 0
var checks: int = 0
func _initialize() -> void:
call_deferred("run")
func check(value: bool, message: String) -> void:
checks += 1
if not value:
failures += 1
push_error(message)
func run() -> void:
var actions = load("res://ui/actions/actions.tscn").instantiate()
root.add_child(actions)
var values: Array = [0.1, 0.01, 0.001, 1.0, 10.0]
var labels: Array = []
for value in values:
labels.append(actions._format_action_value(value))
check(labels == ["0.10", "0.010", "0.0010", "1", "10"], "Fractional action amounts retain precision")
check(labels[0] != labels[1] and labels[1] != labels[2], "Adjacent fractional amounts are distinguishable")
actions.set_actions("test", 123.0)
check(actions.action_values[0] == 1.0 and actions.action_values[1] == 10.0, "Distribution preserves distinct requests")
check(actions.action_labels[0].text != actions.action_labels[1].text, "Rendered adjacent buttons are distinct")
actions.queue_free()
print("Action values: %d checks, %d failures" % [checks, failures])
quit(0 if failures == 0 else 1)
+1
View File
@@ -0,0 +1 @@
uid://dilbcphuku6k1
+13 -1
View File
@@ -47,10 +47,22 @@ func _set_action_values(values: Array, displayed: Array) -> void:
for ind in range(0, 5):
action_values[ind] = values[ind]
# Keep the original request for execution; show the exact planned output.
var text: String = Global.format_number(displayed[ind]) if displayed[ind] > 0 else ""
var text: String = _format_action_value(displayed[ind])
if action_labels[ind].text != text:
action_labels[ind].text = text
func _format_action_value(value: float) -> String:
if value <= 0.0 or not is_finite(value):
return ""
if value >= 1.0:
return Global.format_number(value)
# Global's default is intended for object counts. Action values may be
# fractional, so retain enough precision to keep adjacent buttons distinct.
var exponent: int = int(floor(log(value) / log(10.0)))
var digits: int = clampi(-exponent + 1, 2, 6)
return Global.format_number(value, digits)
func _on_action_button_pressed(button_id: int) -> void:
action_pressed.emit(page_id, action_values[button_id])
+100
View File
@@ -42,9 +42,25 @@
[ext_resource type="Texture2D" uid="uid://bwqmmmg6w7dho" path="res://ui/indicators/trends/trend_icon_4.png" id="39_jms70"]
[ext_resource type="Texture2D" uid="uid://4tpbmpe6tbk0" path="res://ui/indicators/trends/trend_bar5.png" id="40_50rdj"]
[ext_resource type="Texture2D" uid="uid://cnf3ml5gj2cvl" path="res://ui/indicators/trends/trend_icon_5.png" id="41_mi6gc"]
[ext_resource type="Texture2D" uid="uid://drcoll8tlms5s" path="res://main_menu/Owniverse.png" id="43_58wjt"]
[ext_resource type="Texture2D" uid="uid://dcpavg1u7gne7" path="res://main_menu/en/CreateUniverse.png" id="43_k83x5"]
[ext_resource type="Texture2D" uid="uid://c7osivfr1yusc" path="res://main_menu/en/Tutorial.png" id="44_b8tmp"]
[ext_resource type="Texture2D" uid="uid://cq3ho84qxa2wj" path="res://main_menu/en/Achievements.png" id="45_vu62d"]
[ext_resource type="Texture2D" uid="uid://clifqlkiqlp7s" path="res://main_menu/en/Russian.png" id="46_58wjt"]
[ext_resource type="Texture2D" uid="uid://bp7fwgt6kwnwa" path="res://main_menu/ru/English.png" id="47_bfrib"]
[ext_resource type="Texture2D" uid="uid://c15y3813cpwtd" path="res://main_menu/en/SoundNonActive.png" id="47_dp8ul"]
[ext_resource type="Texture2D" uid="uid://cj0qbxoddsnjv" path="res://main_menu/en/EnglishActive.png" id="48_mip0j"]
[ext_resource type="Texture2D" uid="uid://cbpds0flysd4i" path="res://main_menu/en/SoundActive.png" id="48_o7xkw"]
[ext_resource type="Texture2D" uid="uid://dxh4l2ovvmrk1" path="res://main_menu/en/MusicNonActive.png" id="49_bfrib"]
[ext_resource type="Texture2D" uid="uid://so06vth6le3b" path="res://main_menu/ru/RussianActive.png" id="50_l6135"]
[ext_resource type="Texture2D" uid="uid://bamh6ko30ljb7" path="res://main_menu/en/MusicActive.png" id="50_mip0j"]
[ext_resource type="Texture2D" uid="uid://bhfva6xtyij4k" path="res://main_menu/en/Credits.png" id="51_l6135"]
[ext_resource type="Texture2D" uid="uid://dwqpcm1pryw44" path="res://main_menu/en/LeaveReality.png" id="52_uvuuk"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ifjjt"]
[sub_resource type="ButtonGroup" id="ButtonGroup_58wjt"]
[node name="World" type="Node2D" unique_id=1392592456]
[node name="Background" type="Node2D" parent="." unique_id=1988758765]
@@ -868,6 +884,90 @@ theme_override_styles/panel = SubResource("StyleBoxEmpty_ifjjt")
[node name="Border" parent="Stage/StageRows" unique_id=145801370 instance=ExtResource("12_58wjt")]
layout_mode = 2
[node name="MainMenu" type="VBoxContainer" parent="Stage" unique_id=731440017]
visible = false
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
theme_override_constants/separation = 32
[node name="TopMenu" type="HBoxContainer" parent="Stage/MainMenu" unique_id=252548655]
layout_mode = 2
[node name="BurgerButton" type="TextureButton" parent="Stage/MainMenu/TopMenu" unique_id=1685450387]
custom_minimum_size = Vector2(128, 128)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture_normal = ExtResource("4_b8tmp")
texture_pressed = ExtResource("5_en1oy")
[node name="Logo" type="TextureRect" parent="Stage/MainMenu" unique_id=1181845167]
custom_minimum_size = Vector2(1080, 256)
layout_mode = 2
texture = ExtResource("43_58wjt")
[node name="CreateOwniverse" type="TextureButton" parent="Stage/MainMenu" unique_id=1568939047]
custom_minimum_size = Vector2(1024, 128)
layout_mode = 2
texture_normal = ExtResource("43_k83x5")
[node name="Tutorial" type="TextureButton" parent="Stage/MainMenu" unique_id=663512289]
custom_minimum_size = Vector2(1024, 128)
layout_mode = 2
texture_normal = ExtResource("44_b8tmp")
[node name="Achievements" type="TextureButton" parent="Stage/MainMenu" unique_id=141361251]
custom_minimum_size = Vector2(1024, 128)
layout_mode = 2
texture_normal = ExtResource("45_vu62d")
[node name="Language" type="HBoxContainer" parent="Stage/MainMenu" unique_id=2100638475]
layout_mode = 2
[node name="English" type="TextureButton" parent="Stage/MainMenu/Language" unique_id=1495557975]
custom_minimum_size = Vector2(512, 128)
layout_mode = 2
toggle_mode = true
button_group = SubResource("ButtonGroup_58wjt")
texture_normal = ExtResource("47_bfrib")
texture_pressed = ExtResource("48_mip0j")
[node name="Russian" type="TextureButton" parent="Stage/MainMenu/Language" unique_id=2024992008]
custom_minimum_size = Vector2(512, 128)
layout_mode = 2
toggle_mode = true
button_group = SubResource("ButtonGroup_58wjt")
texture_normal = ExtResource("46_58wjt")
texture_pressed = ExtResource("50_l6135")
[node name="Media" type="HBoxContainer" parent="Stage/MainMenu" unique_id=583896501]
layout_mode = 2
[node name="Sound" type="TextureButton" parent="Stage/MainMenu/Media" unique_id=116977198]
custom_minimum_size = Vector2(512, 128)
layout_mode = 2
toggle_mode = true
texture_normal = ExtResource("47_dp8ul")
texture_pressed = ExtResource("48_o7xkw")
[node name="Music" type="TextureButton" parent="Stage/MainMenu/Media" unique_id=953224171]
custom_minimum_size = Vector2(512, 128)
layout_mode = 2
toggle_mode = true
texture_normal = ExtResource("49_bfrib")
texture_pressed = ExtResource("50_mip0j")
[node name="Credits" type="TextureButton" parent="Stage/MainMenu" unique_id=44726060]
custom_minimum_size = Vector2(1024, 128)
layout_mode = 2
texture_normal = ExtResource("51_l6135")
[node name="LeaveReality" type="TextureButton" parent="Stage/MainMenu" unique_id=2139602731]
custom_minimum_size = Vector2(1024, 128)
layout_mode = 2
texture_normal = ExtResource("52_uvuuk")
[node name="ItemAmountUpdate" type="Timer" parent="Stage" unique_id=1953928024]
wait_time = 0.2
autostart = true