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:
+13
-1
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user