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
+13 -1
View File
@@ -47,9 +47,21 @@ 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: