rinkplanner/rinkplanner/tests/run_level_tests.gd
torsten 31d4e70ba1 feat: Features pro Fuß und Variationen je Kategorie begrenzen
Schritt 7 der Mehrsaison-Reihe: Die Level-Features folgen jetzt den drei
Zählregeln aus ISU 2788.

- "In any spin with change of foot the maximum number of features attained
  on one foot is two (2)." Level-Berechnung deckelt pro Fuß; der Validator
  meldet zu viele Features auf einem Fuß und fehlende Fußangaben.
- "In any spin only two (2) difficult variations are counted." Die Gruppe
  difficult_variation hat einen Deckel in den Daten (types.spin.groups).
- "Any category of difficult spin variation in a basic position counts only
  once per program." Die Variation ist in fünf Kategorien aufgeteilt (Sitz,
  Camel, Layback, Upright, Sonstige); damit greift einmal-pro-Programm ohne
  Sonderlogik.

Daten: `per_foot` je Feature, `max_features_per_foot` je Elementtyp,
`change_of_foot` im Katalog (sechs Pirouetten mit Fußwechsel; CSp ist die
Camel-Pirouette, nicht Change foot). Schema 9 speichert den Fuß als
`element_feature_feet` (Code → L/R).

Oberfläche: Die Fußauswahl erscheint nur, wenn sie das Ergebnis ändern kann –
bei einer Fußwechsel-Pirouette mit mehr als zwei fußbezogenen Features.
Angaben zu Level und Ausführung bleiben Selbsteinschätzung; das entscheidet
weiterhin das technische Panel.
2026-11-13 11:53:42 +01:00

465 lines
12 KiB
GDScript

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 PathSegmentModel := preload("res://src/core/model/path_segment.gd")
const SEASON := "2026/27"
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
var _rules: ElementLevelRules
func _init() -> void:
var library := RulesLibrary.scan()
var package := library.get_package(SEASON)
_check(package != null, "Saison %s ist ladbar" % SEASON)
if package == null:
_finish()
return
_rules = package.levels
_test_rules_metadata()
_test_spin_levels()
_test_sequence_levels()
_test_fixed_and_unlevelled_elements()
_test_feature_validation()
_test_foot_cap()
_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 == "2026/27", "level rules season is 2026/27")
_check(_rules.source.contains("2788"), "level rules name ISU communication 2788")
_check(_rules.valid_from == "2026-06-01", "level rules valid from 2026-06-01")
_check(
_rules.get_features(PathSegment.ElementType.SPIN).size() == 19,
"spin rules contain 19 features (five variation categories)"
)
_check(
_rules.get_features(PathSegment.ElementType.SEQUENCE).size() == 5,
"sequence rules contain 5 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_sit"
)
_check(variation != null, "difficult variation exists")
_check(variation.max_per_element == 1, "a variation counts once per element")
_check(variation.once_per_program, "a variation counts once per program")
_check(variation.per_foot, "a variation is attained on one foot")
_check(
variation.group == "difficult_variation",
"variations share a group"
)
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_sit"]),
1,
"one feature gives Level 1"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(["difficult_variation_sit", "difficult_variation_camel"]),
2,
"two difficult variations give Level 2"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
["difficult_variation_sit", "difficult_variation_camel", "difficult_variation_layback"]
),
2,
"a third difficult variation is ignored"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
[
"difficult_variation_sit", "difficult_variation_camel",
"difficult_exit",
"change_of_edge",
]
),
4,
"four features including a level-4 feature give Level 4"
)
_check_level(
spins,
"CCoSp",
PackedStringArray(
[
"difficult_variation_sit", "difficult_variation_camel",
"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 chsp := _rules.calculate_level(
PathSegment.ElementType.SPIN,
"ChSp",
PackedStringArray()
)
_check(chsp.level == 1, "ChSp is fixed at Level 1")
var chsp_with_features := _rules.calculate_level(
PathSegment.ElementType.SPIN,
"ChSp1",
PackedStringArray(["difficult_exit"])
)
_check(chsp_with_features.level == 1, "ChSp ignores feature selections")
_check(
_rules.get_fixed_level(PathSegment.ElementType.SPIN, "ChSp") == 1,
"ChSp exposes its fixed level"
)
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_foot_cap() -> void:
var spins := PathSegment.ElementType.SPIN
var features := PackedStringArray(
[
"difficult_variation_sit",
"difficult_variation_camel",
"change_of_edge",
]
)
var one_foot := _rules.calculate_level(
spins,
"CCoSp",
features,
{
"difficult_variation_sit": "L",
"difficult_variation_camel": "L",
"change_of_edge": "L",
}
)
_check(
one_foot.counted_features == 2,
"only two features on one foot count (%d)" % one_foot.counted_features
)
_check(one_foot.level == 2, "the per-foot cap lowers the level")
var both_feet := _rules.calculate_level(
spins,
"CCoSp",
features,
{
"difficult_variation_sit": "L",
"difficult_variation_camel": "R",
"change_of_edge": "R",
}
)
_check(
both_feet.counted_features == 3,
"features on two feet all count (%d)" % both_feet.counted_features
)
_check(both_feet.level == 3, "three counted features give Level 3")
var unattributed := _rules.calculate_level(spins, "CCoSp", features, {})
_check(
unattributed.counted_features == 3,
"unattributed features are not capped"
)
var group := _rules.calculate_level(
spins,
"CCoSp",
PackedStringArray(
[
"difficult_variation_sit",
"difficult_variation_camel",
"difficult_variation_layback",
]
),
{
"difficult_variation_sit": "L",
"difficult_variation_camel": "R",
"difficult_variation_layback": "L",
}
)
_check(
group.counted_features == 2,
"at most two difficult variations count per spin"
)
func _test_feature_validation() -> void:
var spins := PathSegment.ElementType.SPIN
_check(
_rules.validate_selection(
spins,
PackedStringArray(["difficult_variation_sit", "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_sit",
"difficult_variation_sit",
]
)
),
"more than 1 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"
)
var level4_features := _rules.get_level4_features(spins)
_check(
level4_features.size() == 6,
"six spin features unlock Level 4"
)
_check(
level4_features.has("windmills")
and not level4_features.has("difficult_position_change"),
"the 2026/27 Level-4 list contains windmills instead of the position change"
)
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_sit", "difficult_variation_camel", "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)