66 lines
2.1 KiB
GDScript
66 lines
2.1 KiB
GDScript
extends SceneTree
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
await process_frame
|
|
var bus: Node = load("res://autoload/event_bus.gd").new()
|
|
bus.name = "EventBus"
|
|
root.add_child(bus)
|
|
var counter: Node = load("res://scenes/components/streak_counter.gd").new()
|
|
counter.name = "StreakCounter"
|
|
root.add_child(counter)
|
|
await process_frame
|
|
|
|
var broadcasts: Array = []
|
|
bus.connect("streak_changed", func(count: int) -> void:
|
|
broadcasts.append(count)
|
|
)
|
|
|
|
bus.emit_signal("skill_executed", null, &"perfect")
|
|
bus.emit_signal("skill_executed", null, &"good")
|
|
_expect_int(int(counter.get("streak")), 2, "skill_executed should increment the streak")
|
|
_expect_equal(str(broadcasts), str([1, 2]), "each increment should broadcast streak_changed")
|
|
|
|
bus.emit_signal("judgement_made", &"good", 12.0, 4)
|
|
_expect_int(int(counter.get("streak")), 2, "non-miss judgements must not clear the streak")
|
|
|
|
bus.emit_signal("judgement_made", &"miss", 300.0, 5)
|
|
_expect_int(int(counter.get("streak")), 0, "miss should clear the streak")
|
|
_expect_equal(str(broadcasts), str([1, 2, 0]), "miss clear should broadcast zero")
|
|
|
|
bus.emit_signal("judgement_made", &"miss", 300.0, 6)
|
|
_expect_equal(str(broadcasts), str([1, 2, 0]), "already-zero streak should not rebroadcast on miss")
|
|
|
|
bus.emit_signal("skill_executed", null, &"perfect")
|
|
bus.emit_signal("chart_reset", &"test")
|
|
_expect_int(int(counter.get("streak")), 0, "chart_reset should clear the streak")
|
|
_expect_equal(str(broadcasts), str([1, 2, 0, 1, 0]), "chart_reset clear should broadcast zero")
|
|
|
|
_finish()
|
|
|
|
|
|
func _expect_equal(actual: Variant, expected: Variant, label: String) -> void:
|
|
if actual != expected:
|
|
failures.append("%s: expected %s, got %s" % [label, expected, actual])
|
|
|
|
|
|
func _expect_int(actual: int, expected: int, label: String) -> void:
|
|
if actual != expected:
|
|
failures.append("%s: expected %d, got %d" % [label, expected, actual])
|
|
|
|
|
|
func _finish() -> void:
|
|
if failures.is_empty():
|
|
print("PASS streak counter")
|
|
quit(0)
|
|
else:
|
|
for failure: String in failures:
|
|
push_error(failure)
|
|
quit(1)
|