rinkplanner/rinkplanner/tests/run_validation_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

474 lines
13 KiB
GDScript

extends SceneTree
## Headless tests for routine element validation.
##
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_validation_tests.gd
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
const RoutineValidatorScript := preload("res://src/core/rules/routine_validator.gd")
const ValidationIssueScript := preload("res://src/core/rules/validation_issue.gd")
const RoutineModel := preload("res://src/core/model/routine.gd")
const RoutineSectionModel := preload("res://src/core/model/routine_section.gd")
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
var _catalog: ElementCatalog
var _rules: ElementLevelRules
var _validator: RoutineValidator
func _init() -> void:
_catalog = ElementCatalogScript.load_default()
_rules = ElementLevelRulesScript.load_default()
_validator = RoutineValidatorScript.new(_catalog, _rules)
_test_clean_routine()
_test_unknown_code()
_test_type_mismatch()
_test_unavailable_level()
_test_jump_level_and_features()
_test_fixed_level()
_test_missing_code()
_test_feature_selection()
_test_level_mismatch()
_test_program_once_features()
_test_missing_rules()
_finish()
func _test_clean_routine() -> void:
var routine := _make_routine()
var section := routine.sections[0]
_add_marker(
section,
"spin",
PathSegment.ElementType.SPIN,
"CCoSp",
4,
PackedStringArray(
[
"difficult_variation",
"difficult_variation",
"difficult_exit",
"change_of_edge",
]
)
)
_add_marker(
section,
"sequence",
PathSegment.ElementType.SEQUENCE,
"StSq",
4,
PackedStringArray(
[
"variety_of_turns",
"both_rotations",
"body_movements",
"turn_combinations",
]
)
)
var issues := _validator.validate(routine)
_check(issues.is_empty(), "a consistent routine has no findings (%s)" % _messages(issues))
var report := _validator.validate_report(routine)
_check(report.element_count == 2, "the report counts the elements")
_check(report.section_count == 1, "the report counts the sections")
_check(report.get_check("code").passed == 2, "both codes were checked")
_check(report.get_check("type").passed == 2, "both types were checked")
_check(report.get_check("level").passed == 2, "both levels were checked")
_check(
report.get_check("fixed_level").is_skipped(),
"fixed-level check is skipped without ChSq"
)
_check(report.get_check("features").passed == 2, "both feature sets were checked")
_check(
report.get_check("required").passed == 1,
"the compulsory sequence feature was checked"
)
_check(report.get_check("level_features").passed == 2, "both derived levels match")
_check(report.get_check("once").passed == 6, "once-per-program features were checked")
_check_approx(
report.base_value_total,
8.30,
"the report sums the base values (4.20 + 4.10)"
)
_check(report.scored_elements == 2, "both elements were scored")
_check(report.unscored_elements == 0, "no element is unscored")
_check(
report.element_values.size() == 2,
"the report keeps one value entry per element"
)
func _test_unknown_code() -> void:
var report := _report_one(
PathSegment.ElementType.SPIN,
"3X",
0,
PackedStringArray()
)
var issues := report.issues
_check(_count(issues, ValidationIssueScript.Severity.ERROR) == 1, "unknown code is an error")
_check(_has_message(issues, "nicht im Katalog"), "unknown code message")
_check(report.get_check("code").errors == 1, "the code check records the error")
_check(
report.get_check("type").is_skipped(),
"the type check is skipped without a definition"
)
_check(report.unscored_elements == 1, "an unknown code has no base value")
_check(report.base_value_total == 0.0, "an unknown code adds no points")
_check(
report.element_values.size() == 1
and float(report.element_values[0]["value"]) < 0.0,
"the score entry marks the unknown code as unscored"
)
func _test_type_mismatch() -> void:
var report := _report_one(
PathSegment.ElementType.SPIN,
"3Lz",
0,
PackedStringArray()
)
var issues := report.issues
_check(_count(issues, ValidationIssueScript.Severity.ERROR) == 1, "type mismatch is an error")
_check(_has_message(issues, "gehört zu Sprung"), "type mismatch message")
_check(report.get_check("code").passed == 1, "the code itself exists")
_check(report.get_check("type").errors == 1, "the type check records the mismatch")
_check(
report.get_check("level").is_skipped(),
"the level check is skipped after a type mismatch"
)
func _test_unavailable_level() -> void:
var routine := _make_routine()
var segment := _add_marker(
routine.sections[0],
"spin",
PathSegment.ElementType.SPIN,
"CCoSp",
0,
PackedStringArray()
)
segment.element_level = 7
var issues := _validator.validate(routine)
_check(
_count(issues, ValidationIssueScript.Severity.ERROR) == 1,
"an unavailable level is an error"
)
_check(_has_message(issues, "nicht verfügbar"), "unavailable level message")
func _test_jump_level_and_features() -> void:
var routine := _make_routine()
var segment := _add_marker(
routine.sections[0],
"jump",
PathSegment.ElementType.JUMP,
"3Lz",
2,
PackedStringArray(["difficult_exit"])
)
var report := _validator.validate_report(routine)
var issues := report.issues
_check(
_count(issues, ValidationIssueScript.Severity.WARNING) == 2,
"jump level and features are two warnings"
)
_check(_has_message(issues, "nicht levelbar"), "jump level warning")
_check(_has_message(issues, "Level-Features"), "jump feature warning")
_check(segment.element_level == 2, "the validator does not mutate the segment")
_check(
report.get_check("level").warnings == 1,
"the level check records the jump warning"
)
_check(
report.get_check("features").warnings == 1,
"the feature check records the jump warning"
)
_check_approx(
report.base_value_total,
5.90,
"the jump contributes its base value despite the level warning"
)
func _test_fixed_level() -> void:
var report := _report_one(
PathSegment.ElementType.SEQUENCE,
"ChSq",
2,
PackedStringArray()
)
var issues := report.issues
_check(
_count(issues, ValidationIssueScript.Severity.ERROR) == 1,
"a wrong fixed level is an error"
)
_check(_has_message(issues, "fest"), "fixed level message")
_check(report.get_check("fixed_level").errors == 1, "the fixed-level check fails")
_check(
report.get_check("level").is_skipped(),
"the generic level check is skipped for fixed levels"
)
var valid := _report_one(
PathSegment.ElementType.SEQUENCE,
"ChSq",
1,
PackedStringArray()
)
_check(valid.issues.is_empty(), "ChSq at Level 1 is valid")
_check(valid.get_check("fixed_level").passed == 1, "the fixed-level check passes")
_check_approx(valid.base_value_total, 3.50, "ChSq contributes 3.50")
func _test_missing_code() -> void:
var report := _report_one(
PathSegment.ElementType.SPIN,
"",
0,
PackedStringArray()
)
var issues := report.issues
_check(
_count(issues, ValidationIssueScript.Severity.WARNING) == 1,
"a missing code is a warning"
)
_check(_has_message(issues, "ohne Kürzel"), "missing code message")
_check(
report.get_check("code").warnings == 1,
"the code check records the missing code"
)
func _test_feature_selection() -> void:
var unknown_report := _report_one(
PathSegment.ElementType.SPIN,
"CCoSp",
0,
PackedStringArray(["nope"])
)
var unknown := unknown_report.issues
_check(
_count(unknown, ValidationIssueScript.Severity.ERROR) == 1,
"an unknown feature is an error"
)
_check(_has_message(unknown, "Unbekanntes Feature"), "unknown feature message")
_check(
unknown_report.get_check("features").errors == 1,
"the feature check records the unknown code"
)
var too_many_report := _report_one(
PathSegment.ElementType.SPIN,
"CCoSp",
0,
PackedStringArray(
["difficult_variation", "difficult_variation", "difficult_variation"]
)
)
var too_many := too_many_report.issues
_check(
_count(too_many, ValidationIssueScript.Severity.ERROR) == 1,
"too many difficult variations is an error"
)
_check(_has_message(too_many, "zu oft"), "over-limit feature message")
var missing_report := _report_one(
PathSegment.ElementType.SEQUENCE,
"StSq",
1,
PackedStringArray(["body_movements"])
)
var missing := missing_report.issues
_check(
_count(missing, ValidationIssueScript.Severity.WARNING) == 1,
"a missing compulsory sequence feature is a warning"
)
_check(_has_message(missing, "Pflichtfeature fehlt"), "compulsory feature message")
_check(
missing_report.get_check("required").warnings == 1,
"the required-feature check records the warning"
)
_check(
missing_report.get_check("level_features").is_skipped(),
"the level check is skipped when a required feature is missing"
)
func _test_level_mismatch() -> void:
var report := _report_one(
PathSegment.ElementType.SPIN,
"CCoSp",
4,
PackedStringArray(["difficult_variation", "difficult_exit"])
)
var issues := report.issues
_check(
_count(issues, ValidationIssueScript.Severity.WARNING) == 1,
"a feature/level mismatch is a warning"
)
_check(_has_message(issues, "Features ergeben"), "level mismatch message")
_check(
report.get_check("level_features").warnings == 1,
"the derived-level check records the mismatch"
)
func _test_program_once_features() -> void:
var routine := _make_routine()
var section := routine.sections[0]
_add_marker(
section,
"spin-a",
PathSegment.ElementType.SPIN,
"CCoSp",
1,
PackedStringArray(["difficult_exit"])
)
_add_marker(
section,
"spin-b",
PathSegment.ElementType.SPIN,
"CCoSp",
1,
PackedStringArray(["difficult_exit"])
)
var report := _validator.validate_report(routine)
var issues := report.issues
_check(
_count(issues, ValidationIssueScript.Severity.WARNING) == 1,
"repeated once-per-program features warn once per repeated occurrence"
)
_check(_has_message(issues, "nur einmal pro Programm"), "once-per-program message")
_check(
_has_message(issues, "zuerst in Segment „spin-a“"),
"once-per-program message names the first segment"
)
_check(
report.get_check("once").passed == 1
and report.get_check("once").warnings == 1,
"the once-per-program check counts both occurrences"
)
func _test_missing_rules() -> void:
var broken := RoutineValidatorScript.new(null, null)
var routine := _make_routine()
_add_marker(
routine.sections[0],
"spin",
PathSegment.ElementType.SPIN,
"CCoSp",
0,
PackedStringArray()
)
var issues := broken.validate(routine)
_check(
_count(issues, ValidationIssueScript.Severity.ERROR) == 1,
"a missing rule set is an error"
)
func _validate_one(
type: PathSegment.ElementType,
code: String,
level: int,
features: PackedStringArray
) -> Array[ValidationIssue]:
return _report_one(type, code, level, features).issues
func _report_one(
type: PathSegment.ElementType,
code: String,
level: int,
features: PackedStringArray
) -> ValidationReport:
var routine := _make_routine()
_add_marker(routine.sections[0], "segment", type, code, level, features)
return _validator.validate_report(routine)
func _make_routine() -> Routine:
var routine: Routine = RoutineModel.new()
routine.routine_id = "validation-test"
routine.title = "Validation"
var section: RoutineSection = RoutineSectionModel.new()
section.section_id = "section-001"
section.title = "Abschnitt 1"
section.sequence_order = 0
var sections: Array[RoutineSection] = [section]
routine.sections = sections
return routine
func _add_marker(
section: RoutineSection,
segment_id: String,
type: PathSegment.ElementType,
code: String,
level: int,
features: PackedStringArray
) -> PathSegment:
var segment: PathSegment = PathSegmentModel.new()
segment.segment_id = segment_id
var curve := Curve2D.new()
curve.add_point(Vector2.ZERO)
segment.curve = curve
segment.set_element(type, code, level)
segment.set_element_features(features)
section.segments.append(segment)
return segment
func _count(issues: Array[ValidationIssue], severity: int) -> int:
return RoutineValidatorScript.count_severity(issues, severity)
func _has_message(issues: Array[ValidationIssue], fragment: String) -> bool:
for issue: ValidationIssue in issues:
if issue.message.contains(fragment):
return true
return false
func _messages(issues: Array[ValidationIssue]) -> String:
var parts := PackedStringArray()
for issue: ValidationIssue in issues:
parts.append(issue.message)
return "; ".join(parts)
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)