feat: ISU-Elementkatalog mit Base Values für 2025/26
- ElementDefinition/ElementCatalog in src/core/rules mit JSON-Daten - 24 Sprünge, 16 Pirouetten und 2 Sequenzen aus ISU Communication 2707 - Lookup nach Familie/Level, kanonischen Suffixen und Anzeigenamen - Level-Suffixe werden beim Übernehmen ins Level-Feld normalisiert - Base-Value-Hinweis samt Quellen-Tooltip im Element-Inspector - 160 neue Regelwerk-Assertions; Whiteboard-Tests erweitert (766 gesamt) - JSON über include_filter in allen Export-Presets - Docs: isu-rules.md, Findings, Architektur und Roadmap aktualisiert
This commit is contained in:
parent
d1a6faa53e
commit
789fbc2826
17 changed files with 1577 additions and 34 deletions
|
|
@ -21,6 +21,9 @@ $GODOT --headless --path rinkplanner --import
|
|||
# Run model tests
|
||||
$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 canvas transform/geometry tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_canvas_tests.gd
|
||||
|
||||
|
|
|
|||
359
rinkplanner/tests/run_rules_tests.gd
Normal file
359
rinkplanner/tests/run_rules_tests.gd
Normal file
|
|
@ -0,0 +1,359 @@
|
|||
extends SceneTree
|
||||
|
||||
## Headless tests for the ISU element catalog.
|
||||
##
|
||||
## Run with:
|
||||
## godot --headless --path rinkplanner --script res://tests/run_rules_tests.gd
|
||||
|
||||
const ElementDefinitionScript := preload("res://src/core/rules/element_definition.gd")
|
||||
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
|
||||
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
var _catalog: ElementCatalog
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_catalog = ElementCatalogScript.load_default()
|
||||
|
||||
_test_catalog_metadata()
|
||||
_test_jump_values()
|
||||
_test_spin_values()
|
||||
_test_sequence_values()
|
||||
_test_lookup_rules()
|
||||
_test_suggestions()
|
||||
_test_segment_integration()
|
||||
_test_invalid_catalogs()
|
||||
_finish()
|
||||
|
||||
|
||||
func _test_catalog_metadata() -> void:
|
||||
_check(_catalog != null, "catalog loads")
|
||||
_check(
|
||||
_catalog.get_errors().is_empty(),
|
||||
"catalog parses without errors (%s)" % ", ".join(_catalog.get_errors())
|
||||
)
|
||||
_check(_catalog.is_valid(), "catalog is valid")
|
||||
_check(_catalog.season == "2025/26", "catalog season is 2025/26")
|
||||
_check(_catalog.source.contains("2707"), "catalog names ISU communication 2707")
|
||||
_check(_catalog.valid_from == "2025-07-01", "catalog valid from 2025-07-01")
|
||||
_check(_catalog.get_definition_count() == 42, "catalog has 42 element families")
|
||||
_check(
|
||||
_catalog.get_codes(PathSegment.ElementType.JUMP).size() == 24,
|
||||
"catalog has 24 jump families"
|
||||
)
|
||||
_check(
|
||||
_catalog.get_codes(PathSegment.ElementType.SPIN).size() == 16,
|
||||
"catalog has 16 spin families"
|
||||
)
|
||||
_check(
|
||||
_catalog.get_codes(PathSegment.ElementType.SEQUENCE).size() == 2,
|
||||
"catalog has 2 sequence families"
|
||||
)
|
||||
|
||||
var seen: Dictionary[String, bool] = {}
|
||||
for definition: ElementDefinition in _catalog.get_definitions():
|
||||
_check(definition.is_valid(), "'%s' is a valid definition" % definition.code)
|
||||
_check(not seen.has(definition.code), "'%s' is unique" % definition.code)
|
||||
seen[definition.code] = true
|
||||
|
||||
|
||||
func _test_jump_values() -> void:
|
||||
_check_approx(_catalog.get_base_value("1T"), 0.40, "1T base value")
|
||||
_check_approx(_catalog.get_base_value("2A"), 3.30, "2A base value")
|
||||
_check_approx(_catalog.get_base_value("3Lz"), 5.90, "3Lz base value")
|
||||
_check_approx(_catalog.get_base_value("3A"), 8.00, "3A base value")
|
||||
_check_approx(_catalog.get_base_value("4Lo"), 10.50, "4Lo base value")
|
||||
_check_approx(_catalog.get_base_value("4A"), 12.50, "4A base value")
|
||||
_check_approx(
|
||||
_catalog.get_base_value("3Lz", 4),
|
||||
5.90,
|
||||
"jump levels are ignored"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("3Lz", 0, PathSegment.ElementType.JUMP),
|
||||
5.90,
|
||||
"jump lookup with matching type"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("3Lz", 0, PathSegment.ElementType.SPIN),
|
||||
-1.0,
|
||||
"jump lookup rejects a spin type"
|
||||
)
|
||||
|
||||
var triple_lutz: ElementDefinition = _catalog.find("3Lz")
|
||||
_check(triple_lutz != null, "3Lz family exists")
|
||||
_check(triple_lutz.display_name == "Triple Lutz", "3Lz has a display name")
|
||||
_check(not triple_lutz.is_leveled(), "jumps are not levelled")
|
||||
_check(
|
||||
triple_lutz.get_codes() == PackedStringArray(["3Lz"]),
|
||||
"jump family has one canonical code"
|
||||
)
|
||||
|
||||
|
||||
func _test_spin_values() -> void:
|
||||
_check_approx(_catalog.get_base_value("USpB"), 1.00, "USpB base value")
|
||||
_check_approx(_catalog.get_base_value("USp4"), 2.40, "USp4 base value")
|
||||
_check_approx(_catalog.get_base_value("LSp4"), 2.70, "LSp4 base value")
|
||||
_check_approx(_catalog.get_base_value("FCSp4"), 3.20, "FCSp4 base value")
|
||||
_check_approx(_catalog.get_base_value("CCoSpB"), 1.70, "CCoSpB base value")
|
||||
_check_approx(_catalog.get_base_value("CCoSp4"), 3.50, "CCoSp4 base value")
|
||||
_check_approx(
|
||||
_catalog.get_base_value("CCoSp", 4),
|
||||
3.50,
|
||||
"spin lookup by family and level"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("CCoSp4", -1),
|
||||
3.50,
|
||||
"spin lookup infers the level suffix"
|
||||
)
|
||||
|
||||
var combination: ElementDefinition = _catalog.find("CCoSp")
|
||||
_check(combination != null, "CCoSp family exists")
|
||||
_check(combination.is_leveled(), "spins are levelled")
|
||||
_check(
|
||||
combination.get_codes()
|
||||
== PackedStringArray(["CCoSpB", "CCoSp1", "CCoSp2", "CCoSp3", "CCoSp4"]),
|
||||
"CCoSp exposes Base through level 4"
|
||||
)
|
||||
_check(
|
||||
ElementDefinitionScript.level_label(0) == "Base",
|
||||
"level 0 is labelled Base"
|
||||
)
|
||||
_check(
|
||||
ElementDefinitionScript.level_label(3) == "Level 3",
|
||||
"level 3 is labelled Level 3"
|
||||
)
|
||||
|
||||
|
||||
func _test_sequence_values() -> void:
|
||||
_check_approx(_catalog.get_base_value("StSqB"), 1.50, "StSqB base value")
|
||||
_check_approx(_catalog.get_base_value("StSq3"), 3.30, "StSq3 base value")
|
||||
_check_approx(_catalog.get_base_value("ChSq1"), 3.00, "ChSq1 base value")
|
||||
_check_approx(
|
||||
_catalog.get_base_value("ChSq"),
|
||||
3.00,
|
||||
"single-level sequence resolves without a suffix"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("ChSq4"),
|
||||
-1.0,
|
||||
"unknown sequence level is rejected"
|
||||
)
|
||||
|
||||
|
||||
func _test_lookup_rules() -> void:
|
||||
_check(_catalog.find("3Lz") != null, "exact lookup works")
|
||||
_check(_catalog.find(" 3lz ") != null, "lookup trims and ignores case")
|
||||
_check(_catalog.find("CCoSp4") != null, "lookup accepts a level suffix")
|
||||
_check(_catalog.find("StSqB") != null, "lookup accepts the Base suffix")
|
||||
_check(_catalog.find("3X") == null, "unknown code returns null")
|
||||
_check(_catalog.find("") == null, "empty code returns null")
|
||||
_check(not _catalog.has_code("3X"), "unknown code is not reported as present")
|
||||
_check(
|
||||
_catalog.get_level_suffix("CCoSp4") == 4,
|
||||
"a spin suffix is parsed as level 4"
|
||||
)
|
||||
_check(
|
||||
_catalog.get_level_suffix("StSqB") == 0,
|
||||
"a Base suffix is parsed as level 0"
|
||||
)
|
||||
_check(
|
||||
_catalog.get_level_suffix("CCoSp") == -1,
|
||||
"a family code has no level suffix"
|
||||
)
|
||||
_check(
|
||||
_catalog.get_level_suffix("3Lz") == -1,
|
||||
"a jump code has no level suffix"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("CCoSp4", 2),
|
||||
3.50,
|
||||
"a canonical suffix wins over the level argument"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("StSqB", 4),
|
||||
1.50,
|
||||
"a Base suffix wins over a graded level argument"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("ChSq1", 0),
|
||||
3.00,
|
||||
"an explicit sequence suffix wins over level 0"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value("3X"),
|
||||
-1.0,
|
||||
"unknown code has no base value"
|
||||
)
|
||||
_check_approx(
|
||||
_catalog.get_base_value(""),
|
||||
-1.0,
|
||||
"empty code has no base value"
|
||||
)
|
||||
|
||||
|
||||
func _test_suggestions() -> void:
|
||||
var combined := _catalog.suggest(PathSegment.ElementType.SPIN, "ccosp", 8)
|
||||
_check(
|
||||
combined == PackedStringArray(["CCoSp"]),
|
||||
"suggestions match a case-insensitive code prefix"
|
||||
)
|
||||
_check(
|
||||
_catalog.suggest(PathSegment.ElementType.JUMP, "axel", 8).size() == 4,
|
||||
"suggestions match the display name"
|
||||
)
|
||||
_check(
|
||||
_catalog.suggest(PathSegment.ElementType.JUMP, "", 100).size() == 24,
|
||||
"suggestions respect the element type filter"
|
||||
)
|
||||
_check(
|
||||
_catalog.suggest(PathSegment.ElementType.JUMP, "", 3).size() == 3,
|
||||
"suggestions respect the limit"
|
||||
)
|
||||
_check(
|
||||
_catalog.suggest(PathSegment.ElementType.SPIN, "", 0).is_empty(),
|
||||
"a zero limit returns no suggestions"
|
||||
)
|
||||
_check(
|
||||
_catalog.suggest(PathSegment.ElementType.SPIN, "3Lz", 8).is_empty(),
|
||||
"suggestions do not cross element types"
|
||||
)
|
||||
|
||||
|
||||
func _test_segment_integration() -> void:
|
||||
var spin: PathSegment = PathSegmentModel.new()
|
||||
spin.segment_id = "spin"
|
||||
spin.curve = _make_point_curve(Vector2.ZERO)
|
||||
spin.set_element(PathSegment.ElementType.SPIN, "CCoSp", 4)
|
||||
_check_approx(
|
||||
_catalog.get_segment_base_value(spin),
|
||||
3.50,
|
||||
"segment integration resolves a spin"
|
||||
)
|
||||
|
||||
var jump: PathSegment = PathSegmentModel.new()
|
||||
jump.segment_id = "jump"
|
||||
jump.curve = _make_point_curve(Vector2.ZERO)
|
||||
jump.set_element(PathSegment.ElementType.JUMP, "3Lz", 2)
|
||||
_check_approx(
|
||||
_catalog.get_segment_base_value(jump),
|
||||
5.90,
|
||||
"segment integration ignores jump levels"
|
||||
)
|
||||
|
||||
var sequence: PathSegment = PathSegmentModel.new()
|
||||
sequence.segment_id = "sequence"
|
||||
sequence.curve = _make_point_curve(Vector2.ZERO)
|
||||
sequence.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 3)
|
||||
_check_approx(
|
||||
_catalog.get_segment_base_value(sequence),
|
||||
3.30,
|
||||
"segment integration resolves a sequence"
|
||||
)
|
||||
|
||||
var untagged: PathSegment = PathSegmentModel.new()
|
||||
untagged.segment_id = "untagged"
|
||||
untagged.curve = _make_point_curve(Vector2.ZERO)
|
||||
_check_approx(
|
||||
_catalog.get_segment_base_value(untagged),
|
||||
-1.0,
|
||||
"untagged segments have no base value"
|
||||
)
|
||||
|
||||
var coded: PathSegment = PathSegmentModel.new()
|
||||
coded.segment_id = "coded"
|
||||
coded.curve = _make_point_curve(Vector2.ZERO)
|
||||
coded.set_element(PathSegment.ElementType.JUMP, "3Lz", 0)
|
||||
coded.element_type = PathSegment.ElementType.SPIN
|
||||
_check_approx(
|
||||
_catalog.get_segment_base_value(coded),
|
||||
-1.0,
|
||||
"segment integration rejects a mismatched type"
|
||||
)
|
||||
|
||||
|
||||
func _test_invalid_catalogs() -> void:
|
||||
var missing := ElementCatalogScript.load_from("user://does-not-exist.json")
|
||||
_check(not missing.is_valid(), "a missing catalog is invalid")
|
||||
_check(
|
||||
_contains_error(missing.get_errors(), "cannot open"),
|
||||
"a missing catalog reports the path"
|
||||
)
|
||||
|
||||
var path := "user://invalid_catalog.json"
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(
|
||||
'{"schema_version": 1, "season": "test", "source": "test", '
|
||||
+ '"elements": ['
|
||||
+ '{"code": "3X", "name": "Unknown", "type": "lift", "base_value": 1.0},'
|
||||
+ '{"code": "Bad", "name": "Bad", "type": "spin", "base_values": {"Z": 1.0}},'
|
||||
+ '{"code": "Dup", "name": "First", "type": "jump", "base_value": 1.0},'
|
||||
+ '{"code": "dup", "name": "Second", "type": "jump", "base_value": 2.0}'
|
||||
+ "]}"
|
||||
)
|
||||
file.close()
|
||||
|
||||
var invalid := ElementCatalogScript.load_from(path)
|
||||
_check(not invalid.is_valid(), "a catalog with bad data is invalid")
|
||||
_check(
|
||||
_contains_error(invalid.get_errors(), "unknown element type"),
|
||||
"an unknown element type is reported"
|
||||
)
|
||||
_check(
|
||||
_contains_error(invalid.get_errors(), "invalid level key"),
|
||||
"an invalid level key is reported"
|
||||
)
|
||||
_check(
|
||||
_contains_error(invalid.get_errors(), "duplicate element code"),
|
||||
"a duplicate code is reported"
|
||||
)
|
||||
_check(
|
||||
invalid.find("Dup") != null,
|
||||
"the first definition of a duplicate stays available"
|
||||
)
|
||||
_check_approx(
|
||||
invalid.get_base_value("Dup"),
|
||||
1.0,
|
||||
"the first definition of a duplicate keeps its value"
|
||||
)
|
||||
|
||||
|
||||
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 _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_rules_tests.gd.uid
Normal file
1
rinkplanner/tests/run_rules_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://byd1rcnu1mpnb
|
||||
|
|
@ -720,7 +720,11 @@ func _run() -> void:
|
|||
"element code and level can be edited"
|
||||
)
|
||||
_check(
|
||||
spin.get_element_caption() == "CCoSp4 L3",
|
||||
spin.element_code == "CCoSp" and spin.element_level == 4,
|
||||
"a canonical level suffix is moved into the level field"
|
||||
)
|
||||
_check(
|
||||
spin.get_element_caption() == "CCoSp L4",
|
||||
"marker caption includes code and level"
|
||||
)
|
||||
_check_approx(
|
||||
|
|
@ -741,7 +745,7 @@ func _run() -> void:
|
|||
_check(controller.redo(), "element edit can be redone")
|
||||
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
|
||||
_check(
|
||||
spin != null and spin.get_element_caption() == "CCoSp4 L3",
|
||||
spin != null and spin.get_element_caption() == "CCoSp L4",
|
||||
"redo restores the element data"
|
||||
)
|
||||
|
||||
|
|
@ -750,17 +754,54 @@ func _run() -> void:
|
|||
controller.element_button.pressed.emit()
|
||||
_check(controller.element_dialog.visible, "element button opens the dialog")
|
||||
_check(
|
||||
controller.element_code_edit.text == "CCoSp4",
|
||||
"element dialog is prefilled with the code"
|
||||
controller.element_code_edit.text == "CCoSp",
|
||||
"element dialog is prefilled with the normalized code"
|
||||
)
|
||||
controller.element_code_edit.text = "CCoSp3"
|
||||
_check(
|
||||
controller.element_level_option.get_item_id(
|
||||
controller.element_level_option.selected
|
||||
) == 4,
|
||||
"element dialog is prefilled with the normalized level"
|
||||
)
|
||||
var catalog := controller.get_element_catalog()
|
||||
_check(catalog != null and catalog.season == "2025/26", "controller loads the ISU catalog")
|
||||
_check(
|
||||
controller.element_value_label.text.contains("3,50"),
|
||||
"element dialog shows the base value of the current code and level"
|
||||
)
|
||||
|
||||
controller.element_code_edit.text = "CCoSp"
|
||||
controller.element_level_option.select(
|
||||
controller.element_level_option.get_item_index(2)
|
||||
)
|
||||
controller.update_element_value_hint()
|
||||
_check(
|
||||
controller.element_value_label.text.contains("2,50"),
|
||||
"base value follows a family code and level 2"
|
||||
)
|
||||
|
||||
controller.element_code_edit.text = "CCoSp4"
|
||||
controller.update_element_value_hint()
|
||||
_check(
|
||||
controller.element_value_label.text.contains("3,50"),
|
||||
"a canonical suffix wins over the level control"
|
||||
)
|
||||
|
||||
controller.element_code_edit.text = "3X"
|
||||
controller.update_element_value_hint()
|
||||
_check(
|
||||
controller.element_value_label.text.contains("nicht im Katalog"),
|
||||
"unknown codes are marked as not in the catalog"
|
||||
)
|
||||
|
||||
controller.element_code_edit.text = "CCoSp"
|
||||
controller.element_level_option.select(
|
||||
controller.element_level_option.get_item_index(2)
|
||||
)
|
||||
controller.element_duration_spin.value = 6.5
|
||||
controller.element_dialog.confirmed.emit()
|
||||
_check(
|
||||
controller.get_selected_element_caption() == "CCoSp3 L2",
|
||||
controller.get_selected_element_caption() == "CCoSp L2",
|
||||
"element dialog applies code and level"
|
||||
)
|
||||
_check_approx(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue