feat: Segment-Timing mit Profilen und Kalibrierung hinzufügen
- Timing-Leiste mit gekoppelter Dauer-/Tempo-Bearbeitung - Level-Presets Adult Bronze bis Elite, Default Adult Gold 4,3 m/s - Kalibrierdialog Strecke/Zeit und Standard-Reset - PathSegment speichert Geschwindigkeit oder Dauer als maßgebliche Größe - Schema-Version 2 mit Migration alter Dateien - Tests auf 400 Assertions erweitert
This commit is contained in:
parent
d163b01fa5
commit
43da04b3cc
13 changed files with 819 additions and 44 deletions
|
|
@ -32,6 +32,9 @@ $GODOT --headless --path rinkplanner --script res://tests/run_history_tests.gd
|
|||
|
||||
# Run playback dot/timeline tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_playback_tests.gd
|
||||
|
||||
# Run segment timing/presets/calibration tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_timing_tests.gd
|
||||
```
|
||||
|
||||
Exit code `0` means all assertions passed. Failures are printed to stderr.
|
||||
|
|
|
|||
|
|
@ -110,6 +110,48 @@ func _test_segment_timing() -> void:
|
|||
"segment with length but no duration is invalid"
|
||||
)
|
||||
|
||||
var timed: PathSegment = PathSegmentModel.new()
|
||||
timed.segment_id = "seg-timed"
|
||||
timed.curve = _make_curve(Vector2(0.0, 0.0), Vector2(10.0, 0.0))
|
||||
_check_approx(timed.speed_mps, 4.3, "default segment speed is adult gold")
|
||||
_check(
|
||||
timed.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"default timing mode is speed"
|
||||
)
|
||||
timed.set_speed_mps(5.0)
|
||||
_check_approx(timed.duration_seconds, 2.0, "speed sets the duration")
|
||||
timed.set_duration_seconds(4.0)
|
||||
_check_approx(timed.get_speed_mps(), 2.5, "duration sets the speed")
|
||||
_check(
|
||||
timed.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"duration mode is stored"
|
||||
)
|
||||
timed.curve.set_point_position(1, Vector2(20.0, 0.0))
|
||||
timed.apply_geometry_length(20.0)
|
||||
_check_approx(
|
||||
timed.duration_seconds,
|
||||
4.0,
|
||||
"duration mode preserves the authored duration"
|
||||
)
|
||||
_check_approx(
|
||||
timed.get_speed_mps(),
|
||||
5.0,
|
||||
"duration mode updates the implied speed"
|
||||
)
|
||||
timed.set_speed_mps(4.0)
|
||||
timed.curve.set_point_position(1, Vector2(8.0, 0.0))
|
||||
timed.apply_geometry_length(8.0)
|
||||
_check_approx(
|
||||
timed.duration_seconds,
|
||||
2.0,
|
||||
"speed mode preserves the authored speed"
|
||||
)
|
||||
_check_approx(
|
||||
timed.get_speed_mps(),
|
||||
4.0,
|
||||
"speed mode keeps the speed after a geometry edit"
|
||||
)
|
||||
|
||||
var arc_segment: PathSegment = PathSegmentModel.new()
|
||||
arc_segment.segment_id = "seg-arc"
|
||||
arc_segment.curve = _make_curve(Vector2(-5.0, 0.0), Vector2(5.0, 0.0))
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ func _run() -> void:
|
|||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
|
||||
for segment: PathSegment in [forward, backward, last]:
|
||||
segment.set_speed_mps(6.0)
|
||||
controller._update_status()
|
||||
|
||||
_check_approx(controller.get_playback_duration(), 6.0, "duration sums all sections")
|
||||
_check(not controller.play_button.disabled, "play is enabled with segments")
|
||||
_check(controller.playback_timeline.editable, "timeline is enabled with segments")
|
||||
|
|
|
|||
275
rinkplanner/tests/run_timing_tests.gd
Normal file
275
rinkplanner/tests/run_timing_tests.gd
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
extends SceneTree
|
||||
|
||||
## Headless tests for segment timing, presets and calibration.
|
||||
##
|
||||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_timing_tests.gd
|
||||
|
||||
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_run.call_deferred()
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var scene := WhiteboardScene.instantiate()
|
||||
var controller := scene as WhiteboardController
|
||||
if controller != null:
|
||||
controller.restore_autosave = false
|
||||
controller.autosave_enabled = false
|
||||
root.add_child(scene)
|
||||
await process_frame
|
||||
|
||||
_check(controller != null, "timing scene has a controller")
|
||||
if controller == null:
|
||||
_finish()
|
||||
return
|
||||
|
||||
_check(
|
||||
controller.timing_selection_label.text.contains("Kein Segment"),
|
||||
"timing starts without a selected segment"
|
||||
)
|
||||
_check(
|
||||
controller.duration_plus_button.disabled,
|
||||
"duration controls start disabled"
|
||||
)
|
||||
_check(
|
||||
controller.profile_option.selected == WhiteboardController.DEFAULT_PROFILE_INDEX,
|
||||
"adult gold is the default profile"
|
||||
)
|
||||
|
||||
var segment := controller.add_segment(
|
||||
Vector2(-5.0, 0.0),
|
||||
Vector2(5.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
_check_approx(segment.get_length_m(), 10.0, "test segment is 10 m long")
|
||||
_check_approx(
|
||||
segment.duration_seconds,
|
||||
10.0 / WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"new segments use the default speed"
|
||||
)
|
||||
_check_approx(
|
||||
segment.speed_mps,
|
||||
WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"new segment stores the authored speed"
|
||||
)
|
||||
|
||||
controller.select_segment(segment.segment_id)
|
||||
_check(
|
||||
not controller.duration_plus_button.disabled,
|
||||
"timing controls enable with a selection"
|
||||
)
|
||||
_check(
|
||||
controller.timing_selection_label.text.contains("10,0 m"),
|
||||
"timing bar shows the segment length"
|
||||
)
|
||||
_check(
|
||||
controller.duration_value_label.text.contains("2,3"),
|
||||
"timing bar shows the duration"
|
||||
)
|
||||
_check(
|
||||
controller.speed_value_label.text.contains("4,3"),
|
||||
"timing bar shows the speed"
|
||||
)
|
||||
|
||||
var duration_before := segment.duration_seconds
|
||||
controller.duration_plus_button.pressed.emit()
|
||||
_check_approx(
|
||||
segment.duration_seconds,
|
||||
duration_before + 0.1,
|
||||
"duration plus increases the duration"
|
||||
)
|
||||
_check(
|
||||
segment.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"duration editing switches to duration mode"
|
||||
)
|
||||
_check(
|
||||
segment.get_speed_mps() < WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"a longer duration lowers the implied speed"
|
||||
)
|
||||
|
||||
_check(controller.undo(), "duration change can be undone")
|
||||
var restored := controller.get_active_section().get_segment_by_id(
|
||||
segment.segment_id
|
||||
)
|
||||
_check(restored != null, "segment survives undo")
|
||||
if restored != null:
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
duration_before,
|
||||
"undo restores the duration"
|
||||
)
|
||||
_check(
|
||||
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"undo restores the timing mode"
|
||||
)
|
||||
controller.select_segment(restored.segment_id)
|
||||
controller.speed_plus_button.pressed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
4.4,
|
||||
"speed plus increases the speed"
|
||||
)
|
||||
_check(
|
||||
restored.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"speed editing switches to speed mode"
|
||||
)
|
||||
|
||||
var speed_before_profile := restored.get_speed_mps()
|
||||
controller.profile_option.item_selected.emit(3)
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
5.0,
|
||||
"masters profile applies 5 m/s"
|
||||
)
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
2.0,
|
||||
"profile updates the duration"
|
||||
)
|
||||
_check(controller.undo(), "profile change can be undone")
|
||||
restored = controller.get_active_section().get_segment_by_id(segment.segment_id)
|
||||
if restored != null:
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
speed_before_profile,
|
||||
"undo restores the previous speed"
|
||||
)
|
||||
controller.select_segment(restored.segment_id)
|
||||
|
||||
controller.reset_timing_button.pressed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
WhiteboardController.DEFAULT_SPEED_MPS,
|
||||
"reset applies the default profile speed"
|
||||
)
|
||||
|
||||
controller.calibrate_button.pressed.emit()
|
||||
controller.calibration_distance_edit.text = "20"
|
||||
controller.calibration_time_edit.text = "4"
|
||||
controller.calibration_dialog.confirmed.emit()
|
||||
_check_approx(
|
||||
restored.get_speed_mps(),
|
||||
5.0,
|
||||
"calibration derives speed from distance and time"
|
||||
)
|
||||
_check_approx(
|
||||
restored.duration_seconds,
|
||||
2.0,
|
||||
"calibration updates the duration"
|
||||
)
|
||||
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
controller.profile_option.item_selected.emit(0)
|
||||
_check_approx(
|
||||
controller.get_preset_speed(),
|
||||
3.0,
|
||||
"profile without selection sets the next-segment speed"
|
||||
)
|
||||
var bronze := controller.add_segment(
|
||||
Vector2(0.0, 8.0),
|
||||
Vector2(6.0, 8.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
)
|
||||
_check_approx(bronze.get_speed_mps(), 3.0, "new segment uses the bronze preset")
|
||||
_check_approx(bronze.duration_seconds, 2.0, "bronze duration follows the length")
|
||||
|
||||
var save_path := "user://test_timing.tres"
|
||||
_check(controller.save_to_path(save_path), "timing routine can be saved")
|
||||
_check(controller.load_from_path(save_path), "timing routine can be loaded")
|
||||
var loaded_first := controller.get_routine().get_section_by_id(
|
||||
"section-001"
|
||||
)
|
||||
_check(loaded_first != null, "loaded timing routine has its section")
|
||||
if loaded_first != null:
|
||||
var loaded_arc := loaded_first.get_segment_by_id(segment.segment_id)
|
||||
_check(loaded_arc != null, "loaded timing routine has the first segment")
|
||||
if loaded_arc != null:
|
||||
_check_approx(
|
||||
loaded_arc.get_speed_mps(),
|
||||
5.0,
|
||||
"load preserves the authored speed"
|
||||
)
|
||||
_check(
|
||||
loaded_arc.timing_mode == PathSegment.TimingMode.SPEED,
|
||||
"load preserves the timing mode"
|
||||
)
|
||||
DirAccess.remove_absolute(save_path)
|
||||
|
||||
# Migration: old routines had no speed field; their duration must survive.
|
||||
var old_routine := Routine.new()
|
||||
old_routine.schema_version = 1
|
||||
old_routine.routine_id = "old-routine"
|
||||
old_routine.title = "Alt"
|
||||
old_routine.rink = RinkDimensions.new()
|
||||
var old_section := RoutineSection.new()
|
||||
old_section.section_id = "section-001"
|
||||
old_section.title = "Abschnitt 1"
|
||||
old_section.sequence_order = 0
|
||||
var old_segment := PathSegment.new()
|
||||
old_segment.segment_id = "seg-old"
|
||||
old_segment.curve = Curve2D.new()
|
||||
old_segment.curve.add_point(Vector2(-5.0, 0.0))
|
||||
old_segment.curve.add_point(Vector2(5.0, 0.0))
|
||||
old_segment.duration_seconds = 5.0
|
||||
old_segment.speed_mps = 4.3
|
||||
old_segment.timing_mode = PathSegment.TimingMode.SPEED
|
||||
old_section.segments = [old_segment]
|
||||
old_routine.sections = [old_section]
|
||||
|
||||
var old_path := "user://test_timing_v1.tres"
|
||||
ResourceSaver.save(old_routine, old_path)
|
||||
_check(controller.load_from_path(old_path), "schema-1 routine can be loaded")
|
||||
var migrated := controller.get_active_section().get_segment_by_id("seg-old")
|
||||
_check(migrated != null, "migrated segment exists")
|
||||
if migrated != null:
|
||||
_check(
|
||||
migrated.timing_mode == PathSegment.TimingMode.DURATION,
|
||||
"migration preserves the old duration"
|
||||
)
|
||||
_check_approx(
|
||||
migrated.speed_mps,
|
||||
2.0,
|
||||
"migration derives the old speed"
|
||||
)
|
||||
_check(
|
||||
controller.get_routine().schema_version == Routine.CURRENT_SCHEMA_VERSION,
|
||||
"migration updates the schema version"
|
||||
)
|
||||
DirAccess.remove_absolute(old_path)
|
||||
|
||||
scene.queue_free()
|
||||
await process_frame
|
||||
_finish()
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
_assertions += 1
|
||||
if not condition:
|
||||
_failures.append(message)
|
||||
|
||||
|
||||
func _check_approx(actual: float, expected: float, message: String) -> void:
|
||||
_check(
|
||||
absf(actual - expected) <= 0.001,
|
||||
"%s (expected %.3f, got %.3f)" % [message, expected, actual]
|
||||
)
|
||||
|
||||
|
||||
func _finish() -> void:
|
||||
if _failures.is_empty():
|
||||
print("PASS: %d assertions" % _assertions)
|
||||
quit(0)
|
||||
return
|
||||
|
||||
for failure: String in _failures:
|
||||
printerr("FAIL: %s" % failure)
|
||||
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
|
||||
quit(1)
|
||||
1
rinkplanner/tests/run_timing_tests.gd.uid
Normal file
1
rinkplanner/tests/run_timing_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cu00yy7ajnuqb
|
||||
Loading…
Add table
Add a link
Reference in a new issue