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:
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dilbcphuku6k1
|
||||
Reference in New Issue
Block a user