feat: ISU-Level-Features und Level-Berechnung

- ElementFeature/ElementLevelRules mit Daten aus ISU Communication 2701
- 14 Pirouetten- und 4 Schrittsequenz-Features inkl. Pflicht- und
  Level-4-Regeln
- PathSegment.element_features mit Duplikaten fuer schwierige Variationen
- Feature-Menue und abgeleiteter Level-Hinweis im Element-Inspector,
  Auswahl undo-faehig
- 47 neue Level-Assertions, Whiteboard-Tests auf 228 erweitert (833 gesamt)
- Doku: isu-rules, Findings, Architektur und Roadmap aktualisiert
This commit is contained in:
torsten 2026-10-31 09:21:03 +01:00
parent 789fbc2826
commit 0613ffca3e
18 changed files with 1490 additions and 25 deletions

View file

@ -24,6 +24,9 @@ $GODOT --headless --path rinkplanner --script res://tests/run_model_tests.gd
# Run ISU element catalog tests
$GODOT --headless --path rinkplanner --script res://tests/run_rules_tests.gd
# Run ISU level-feature tests
$GODOT --headless --path rinkplanner --script res://tests/run_level_tests.gd
# Run canvas transform/geometry tests
$GODOT --headless --path rinkplanner --script res://tests/run_canvas_tests.gd

View file

@ -51,7 +51,7 @@ func _capture() -> void:
"3Lz",
0
)
controller.add_element_marker(
var spin := controller.add_element_marker(
Vector2(-4.0, 9.0),
PathSegment.ElementType.SPIN,
"CCoSp4",
@ -83,6 +83,12 @@ func _capture() -> void:
controller.set_tool(WhiteboardController.Tool.ELEMENT)
elif args.size() > 3 and args[3] == "dialog":
controller.element_button.pressed.emit()
elif args.size() > 3 and args[3] == "features":
controller.select_segment(spin.segment_id)
controller.set_selected_element_features(
PackedStringArray(["difficult_variation", "difficult_exit"])
)
controller.element_button.pressed.emit()
elif args.size() > 3 and args[3] == "spin":
var elapsed := 0.0
for segment: PathSegment in controller.get_active_section().segments:

View file

@ -0,0 +1,360 @@
extends SceneTree
## Headless tests for the ISU level rules and feature selection.
##
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_level_tests.gd
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
var _rules: ElementLevelRules
func _init() -> void:
_rules = ElementLevelRulesScript.load_default()
_test_rules_metadata()
_test_spin_levels()
_test_sequence_levels()
_test_fixed_and_unlevelled_elements()
_test_feature_validation()
_test_segment_features()
_finish()
func _test_rules_metadata() -> void:
_check(_rules != null, "level rules load")
_check(
_rules.get_errors().is_empty(),
"level rules parse without errors (%s)" % ", ".join(_rules.get_errors())
)
_check(_rules.is_valid(), "level rules are valid")
_check(_rules.season == "2025/26", "level rules season is 2025/26")
_check(_rules.source.contains("2701"), "level rules name ISU communication 2701")
_check(_rules.valid_from == "2025-07-01", "level rules valid from 2025-07-01")
_check(
_rules.get_features(PathSegment.ElementType.SPIN).size() == 14,
"spin rules contain 14 features"
)
_check(
_rules.get_features(PathSegment.ElementType.SEQUENCE).size() == 4,
"sequence rules contain 4 features"
)
_check(
_rules.get_features(PathSegment.ElementType.JUMP).is_empty(),
"jumps have no level features"
)
var variation: ElementFeature = _rules.get_feature(
PathSegment.ElementType.SPIN,
"difficult_variation"
)
_check(variation != null, "difficult variation exists")
_check(variation.max_per_element == 2, "difficult variation counts twice")
_check(not variation.once_per_program, "difficult variation is not once-only")
var exit: ElementFeature = _rules.get_feature(
PathSegment.ElementType.SPIN,
"difficult_exit"
)
_check(exit != null and exit.once_per_program, "difficult exit counts once")
func _test_spin_levels() -> void:
var spins := PathSegment.ElementType.SPIN
var none := PackedStringArray()
_check_level(spins, "CCoSp", none, 0, "a spin without features is Base")
_check_level(
spins,
"CCoSp",
PackedStringArray(["difficult_variation"]),
1,
"one feature gives Level 1"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(["difficult_variation", "difficult_variation"]),
2,
"two difficult variations give Level 2"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
["difficult_variation", "difficult_variation", "difficult_variation"]
),
2,
"a third difficult variation is ignored"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
[
"difficult_variation",
"difficult_variation",
"difficult_exit",
"change_of_edge",
]
),
4,
"four features including a level-4 feature give Level 4"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
[
"difficult_variation",
"difficult_variation",
"change_foot_jump",
"jump_in_spin",
]
),
3,
"four features without a level-4 feature stop at Level 3"
)
var result := _rules.calculate_level(
spins,
"CCoSp",
PackedStringArray(["unknown_feature", "difficult_exit"])
)
_check(result.ignored_features.has("unknown_feature"), "unknown features are ignored")
_check(result.counted_features == 1, "only known features count")
func _test_sequence_levels() -> void:
var sequences := PathSegment.ElementType.SEQUENCE
_check_level(sequences, "StSq", PackedStringArray(), 0, "a step sequence without features is Base")
_check_level(
sequences,
"StSq",
PackedStringArray(["both_rotations"]),
0,
"a step sequence without the compulsory feature stays Base"
)
_check_level(
sequences,
"StSq",
PackedStringArray(["variety_of_turns"]),
1,
"the compulsory feature alone gives Level 1"
)
_check_level(
sequences,
"StSq",
PackedStringArray(["variety_of_turns", "both_rotations"]),
2,
"two step-sequence features give Level 2"
)
_check_level(
sequences,
"StSq",
PackedStringArray(
[
"variety_of_turns",
"both_rotations",
"body_movements",
"turn_combinations",
]
),
4,
"all four step-sequence features give Level 4"
)
var missing := _rules.calculate_level(
sequences,
"StSq",
PackedStringArray(["both_rotations"])
)
_check(
missing.missing_required.has("variety_of_turns"),
"missing compulsory feature is reported"
)
func _test_fixed_and_unlevelled_elements() -> void:
var chsq := _rules.calculate_level(
PathSegment.ElementType.SEQUENCE,
"ChSq",
PackedStringArray()
)
_check(chsq.level == 1, "ChSq is fixed at Level 1")
var chsq_with_features := _rules.calculate_level(
PathSegment.ElementType.SEQUENCE,
"ChSq1",
PackedStringArray(["variety_of_turns"])
)
_check(chsq_with_features.level == 1, "ChSq ignores feature selections")
_check(
_rules.calculate_level(
PathSegment.ElementType.JUMP,
"ChSq",
PackedStringArray()
).level == 0,
"a fixed level only applies to the matching element type"
)
var jump := _rules.calculate_level(
PathSegment.ElementType.JUMP,
"3Lz",
PackedStringArray(["difficult_exit"])
)
_check(jump.level == 0, "jumps have no level")
_check(
jump.ignored_features.has("difficult_exit"),
"features on jumps are ignored"
)
func _test_feature_validation() -> void:
var spins := PathSegment.ElementType.SPIN
_check(
_rules.validate_selection(
spins,
PackedStringArray(["difficult_variation", "difficult_exit"])
).is_empty(),
"a valid spin selection has no errors"
)
_check(
_contains_error(
_rules.validate_selection(spins, PackedStringArray(["unknown"])),
"unknown feature"
),
"unknown features are reported"
)
_check(
_contains_error(
_rules.validate_selection(
spins,
PackedStringArray(
["difficult_variation", "difficult_variation", "difficult_variation"]
)
),
"more than 2 time(s)"
),
"over-limit repetitions are reported"
)
_check(
_contains_error(
_rules.validate_selection(
PathSegment.ElementType.SEQUENCE,
PackedStringArray(["body_movements"])
),
"required feature"
),
"missing compulsory sequence features are reported"
)
_check(
_rules.get_required_features(PathSegment.ElementType.SEQUENCE)
== PackedStringArray(["variety_of_turns"]),
"required sequence features are exposed"
)
_check(
_rules.get_level4_features(spins).size() == 6,
"six spin features unlock Level 4"
)
func _test_segment_features() -> void:
var marker: PathSegment = PathSegmentModel.new()
marker.segment_id = "spin"
marker.curve = _make_point_curve(Vector2.ZERO)
marker.set_element(PathSegment.ElementType.SPIN, "CCoSp", 4)
marker.set_element_features(
PackedStringArray(["difficult_variation", "difficult_variation", "difficult_exit"])
)
_check(marker.element_features.size() == 3, "features are stored on the segment")
_check(marker.is_valid(), "a segment with features is valid")
var result := _rules.calculate_level(
marker.element_type,
marker.element_code,
marker.element_features
)
_check(result.level == 3, "segment features produce a level")
_check(result.counted_features == 3, "segment features are counted")
marker.set_element_features(
PackedStringArray([" difficult_exit ", "", "change_of_edge"])
)
_check(
marker.element_features == PackedStringArray(["difficult_exit", "change_of_edge"]),
"feature codes are trimmed and empty entries dropped"
)
var many := PackedStringArray()
for index: int in range(30):
many.append("feature_%d" % index)
marker.set_element_features(many)
_check(
marker.element_features.size() == PathSegment.ELEMENT_MAX_FEATURES,
"feature selection is capped"
)
marker.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 2)
_check(
marker.element_features.is_empty(),
"changing the element type clears features"
)
marker.set_element_features(PackedStringArray(["variety_of_turns"]))
marker.set_element(PathSegment.ElementType.NONE, "", 0)
_check(
marker.element_features.is_empty(),
"removing the element clears features"
)
var untagged: PathSegment = PathSegmentModel.new()
untagged.segment_id = "untagged"
untagged.curve = _make_point_curve(Vector2.ZERO)
untagged.set_element_features(PackedStringArray(["difficult_exit"]))
_check(
untagged.element_features.is_empty(),
"features without an element type are dropped"
)
func _check_level(
type: PathSegment.ElementType,
code: String,
features: PackedStringArray,
expected: int,
message: String
) -> void:
var result := _rules.calculate_level(type, code, features)
_check(result.level == expected, "%s (got %d)" % [message, result.level])
func _make_point_curve(point: Vector2) -> Curve2D:
var curve := Curve2D.new()
curve.add_point(point)
return curve
func _contains_error(errors: PackedStringArray, fragment: String) -> bool:
for error: String in errors:
if error.contains(fragment):
return true
return false
func _check(condition: bool, message: String) -> void:
_assertions += 1
if not condition:
_failures.append(message)
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)

View file

@ -0,0 +1 @@
uid://c3c5ba87ey8vl

View file

@ -794,6 +794,87 @@ func _run() -> void:
"unknown codes are marked as not in the catalog"
)
# Level features and the derived level.
_check(
controller.set_selected_element_features(
PackedStringArray(["difficult_variation", "difficult_exit"])
),
"features can be assigned to an element"
)
_check(
controller.get_selected_element_features().size() == 2,
"features are stored on the selected segment"
)
_check(
controller.element_feature_hint.text.contains("Features: 2")
and controller.element_feature_hint.text.contains("Level 2")
and controller.element_feature_hint.text.contains("gewählt: Level 4"),
"feature hint shows the derived level and the mismatch"
)
_check(
not controller.element_features_button.disabled,
"feature button is enabled for a spin"
)
_check(
controller._populate_feature_menu(),
"feature menu populates for a spin"
)
_check(
controller.element_feature_menu.item_count == 17,
"feature menu lists 14 features plus the second difficult variation"
)
_check(
controller.element_feature_menu.get_item_metadata(0) == "difficult_variation",
"feature menu items carry their feature code"
)
_check(
controller.element_feature_menu.is_item_checked(0),
"the selected difficult variation is checked"
)
_check(
controller.element_feature_menu.is_item_checked(6),
"the selected difficult exit is checked"
)
controller.element_feature_menu.set_item_checked(1, false)
controller._on_feature_menu_id_pressed(1)
_check(
controller.element_feature_menu.is_item_checked(1),
"clicking a feature toggles its check state"
)
controller._on_feature_menu_hidden()
_check(
controller.get_selected_element_features().size() == 3,
"a second difficult variation can be added"
)
_check(
controller.element_feature_hint.text.contains("Features: 3"),
"feature hint follows the selection"
)
_check(controller.undo(), "feature selection can be undone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(spin != null, "the spin survives undo")
controller.select_segment(spin.segment_id)
_check(
controller.get_selected_element_features().size() == 2,
"undo restores the previous feature selection"
)
_check(controller.redo(), "feature selection can be redone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(spin != null, "the spin survives redo")
controller.select_segment(spin.segment_id)
_check(
controller.get_selected_element_features().size() == 3,
"redo restores the feature selection"
)
_check(
controller.set_selected_element_features(PackedStringArray()),
"features can be cleared"
)
_check(
controller.get_selected_element_features().is_empty(),
"clearing removes all features"
)
controller.element_code_edit.text = "CCoSp"
controller.element_level_option.select(
controller.element_level_option.get_item_index(2)