feat: Elementvalidierung mit Pruefdialog
- RoutineValidator und ValidationIssue gegen Katalog und Level-Regeln - Prueft Kuerzel/Typ/Level, Feature-Auswahl, Level-Abgleich sowie ChSq- und Sprung-Sonderfaelle - Programmweite once_per_program-Features als Warnung - Pruefen-Button und Dialog in der Statusleiste, nicht blockierend - 28 Validierungs-Assertions, Whiteboard-Tests auf 233 erweitert (866 gesamt) - Doku: isu-rules, Findings, Architektur und Roadmap aktualisiert
This commit is contained in:
parent
0613ffca3e
commit
223a072f5d
17 changed files with 1017 additions and 15 deletions
|
|
@ -27,6 +27,9 @@ $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 routine element-validation tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_validation_tests.gd
|
||||
|
||||
# Run canvas transform/geometry tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_canvas_tests.gd
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ func _capture() -> void:
|
|||
PackedStringArray(["difficult_variation", "difficult_exit"])
|
||||
)
|
||||
controller.element_button.pressed.emit()
|
||||
elif args.size() > 3 and args[3] == "validate":
|
||||
controller.open_validation_dialog()
|
||||
elif args.size() > 3 and args[3] == "spin":
|
||||
var elapsed := 0.0
|
||||
for segment: PathSegment in controller.get_active_section().segments:
|
||||
|
|
|
|||
356
rinkplanner/tests/run_validation_tests.gd
Normal file
356
rinkplanner/tests/run_validation_tests.gd
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
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))
|
||||
|
||||
|
||||
func _test_unknown_code() -> void:
|
||||
var issues := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"3X",
|
||||
0,
|
||||
PackedStringArray()
|
||||
)
|
||||
_check(_count(issues, ValidationIssueScript.Severity.ERROR) == 1, "unknown code is an error")
|
||||
_check(_has_message(issues, "nicht im Katalog"), "unknown code message")
|
||||
|
||||
|
||||
func _test_type_mismatch() -> void:
|
||||
var issues := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"3Lz",
|
||||
0,
|
||||
PackedStringArray()
|
||||
)
|
||||
_check(_count(issues, ValidationIssueScript.Severity.ERROR) == 1, "type mismatch is an error")
|
||||
_check(_has_message(issues, "gehört zu Sprung"), "type mismatch message")
|
||||
|
||||
|
||||
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 issues := _validator.validate(routine)
|
||||
_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")
|
||||
|
||||
|
||||
func _test_fixed_level() -> void:
|
||||
var issues := _validate_one(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"ChSq",
|
||||
2,
|
||||
PackedStringArray()
|
||||
)
|
||||
_check(
|
||||
_count(issues, ValidationIssueScript.Severity.ERROR) == 1,
|
||||
"a wrong fixed level is an error"
|
||||
)
|
||||
_check(_has_message(issues, "fest"), "fixed level message")
|
||||
|
||||
var valid := _validate_one(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"ChSq",
|
||||
1,
|
||||
PackedStringArray()
|
||||
)
|
||||
_check(valid.is_empty(), "ChSq at Level 1 is valid")
|
||||
|
||||
|
||||
func _test_missing_code() -> void:
|
||||
var issues := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"",
|
||||
0,
|
||||
PackedStringArray()
|
||||
)
|
||||
_check(
|
||||
_count(issues, ValidationIssueScript.Severity.WARNING) == 1,
|
||||
"a missing code is a warning"
|
||||
)
|
||||
_check(_has_message(issues, "ohne Kürzel"), "missing code message")
|
||||
|
||||
|
||||
func _test_feature_selection() -> void:
|
||||
var unknown := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
0,
|
||||
PackedStringArray(["nope"])
|
||||
)
|
||||
_check(
|
||||
_count(unknown, ValidationIssueScript.Severity.ERROR) == 1,
|
||||
"an unknown feature is an error"
|
||||
)
|
||||
_check(_has_message(unknown, "Unbekanntes Feature"), "unknown feature message")
|
||||
|
||||
var too_many := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
0,
|
||||
PackedStringArray(
|
||||
["difficult_variation", "difficult_variation", "difficult_variation"]
|
||||
)
|
||||
)
|
||||
_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 := _validate_one(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"StSq",
|
||||
1,
|
||||
PackedStringArray(["body_movements"])
|
||||
)
|
||||
_check(
|
||||
_count(missing, ValidationIssueScript.Severity.WARNING) == 1,
|
||||
"a missing compulsory sequence feature is a warning"
|
||||
)
|
||||
_check(_has_message(missing, "Pflichtfeature fehlt"), "compulsory feature message")
|
||||
|
||||
|
||||
func _test_level_mismatch() -> void:
|
||||
var issues := _validate_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
4,
|
||||
PackedStringArray(["difficult_variation", "difficult_exit"])
|
||||
)
|
||||
_check(
|
||||
_count(issues, ValidationIssueScript.Severity.WARNING) == 1,
|
||||
"a feature/level mismatch is a warning"
|
||||
)
|
||||
_check(_has_message(issues, "Features ergeben"), "level mismatch message")
|
||||
|
||||
|
||||
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 issues := _validator.validate(routine)
|
||||
_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"
|
||||
)
|
||||
|
||||
|
||||
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]:
|
||||
var routine := _make_routine()
|
||||
_add_marker(routine.sections[0], "segment", type, code, level, features)
|
||||
return _validator.validate(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 _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_validation_tests.gd.uid
Normal file
1
rinkplanner/tests/run_validation_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bdfvwb07656pb
|
||||
|
|
@ -1103,6 +1103,43 @@ func _run() -> void:
|
|||
)
|
||||
DirAccess.remove_absolute(save_as_path)
|
||||
|
||||
# Validation dialog.
|
||||
controller.new_routine()
|
||||
controller.add_element_marker(
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.ElementType.SPIN,
|
||||
"3X",
|
||||
0
|
||||
)
|
||||
var issues := controller.validate_routine()
|
||||
_check(issues.size() == 1, "validation reports one finding")
|
||||
_check(
|
||||
issues.size() > 0
|
||||
and issues[0].severity == ValidationIssue.Severity.ERROR,
|
||||
"an unknown element code is reported as an error"
|
||||
)
|
||||
controller.message_dialog.hide()
|
||||
controller.open_validation_dialog()
|
||||
_check(controller.validation_dialog.visible, "validation button opens the dialog")
|
||||
_check(
|
||||
controller.validation_text.text.contains("nicht im Katalog"),
|
||||
"validation dialog shows the catalog finding"
|
||||
)
|
||||
controller.validation_dialog.hide()
|
||||
|
||||
controller.new_routine()
|
||||
controller.add_element_marker(
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
4
|
||||
)
|
||||
var clean_issues := controller.validate_routine()
|
||||
_check(
|
||||
clean_issues.is_empty(),
|
||||
"a consistent routine has no validation findings"
|
||||
)
|
||||
|
||||
scene.queue_free()
|
||||
await process_frame
|
||||
_finish()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue