rinkplanner/rinkplanner/tests/run_level_tests.gd
torsten e4fd74ea6e feat: ISU 2026/27 und Adult-Kategorien
- SoV 2026/27 (Communication 2786) und Levels 2026/27 (2788)
- 15 Pirouetten- und 5 Sequenz-Features, Windmills, neues ChSp1
- Adult-Kategorien Gold/Silver/Bronze plus Masters/Elite aus dem
  IAFSC-Announcement 2026/27
- Kategorie-Auswahl in der Statusleiste und Kategorie-Validierung
  (Sprunganzahl, erlaubte Sprünge, Level-Caps, Pflichtelemente)
- 60 Adult-Assertions; gesamt 1012 Assertions gruen
- Doku, Findings und Roadmap aktualisiert
2026-10-31 11:21:18 +01:00

382 lines
9.9 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 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 == "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() == 15,
"spin rules contain 15 features"
)
_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"
)
_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 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_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"
)
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", "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)