mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
Add pure correction and pedagogy logic with full test coverage
scripts/correction/: AnswerValidator (multiple choice, sentence correction via tap-the-faulty-word + retype) and DictationAnalyzer build the CorrectionResult structure from cahier des charges §6. Dictation analysis aligns words with WordAligner (Wagner-Fischer edit distance) before any character comparison, so an omitted or added word doesn't cascade into false errors on every following word. TextNormalizer handles non-breaking spaces, typographic apostrophes, and decomposed-vs-composed French accented characters via an explicit table (GDScript has no built-in NFC/NFD normalization). Error classification follows the data annotations only (rule_id present -> grammatical, absent -> unclassified), never a runtime linguistic guess. scripts/pedagogy/: DifficultyManager (per-skill difficulty from recent results), AttemptFlow (3-attempt graduated aid: hint, then explanation, then reveal, matching exercise-lifecycle.md's second gap), and ReviewScheduler (the five mastery states from §9, with session-counted spaced review intervals [1, 3, 6, 12] rather than wall-clock dates, since a family device's clock isn't trustworthy). All of it is pure: no scene tree, no clock or RNG read directly, every effectful input (session number, attempt outcome) is a parameter. 65 headless tests across both layers, including the word-omission-doesn't-cascade regression and the full decouverte -> acquise -> a_reviser -> acquise path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,64 +6,65 @@ var schema: Dictionary = {
|
||||
"type": "object",
|
||||
"required": ["id", "level"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
|
||||
"level": { "type": "string", "enum": ["CE1", "CE2"] },
|
||||
"difficulty": { "type": "integer", "minimum": 1, "maximum": 3 },
|
||||
"tags": { "type": "array", "minItems": 1, "items": { "type": "string" } },
|
||||
"properties":
|
||||
{
|
||||
"id": {"type": "string", "pattern": "^[a-z][a-z0-9_]*$"},
|
||||
"level": {"type": "string", "enum": ["CE1", "CE2"]},
|
||||
"difficulty": {"type": "integer", "minimum": 1, "maximum": 3},
|
||||
"tags": {"type": "array", "minItems": 1, "items": {"type": "string"}},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
func test_valid_object_has_no_errors() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": 2, "tags": ["pluriel"] }
|
||||
var data := {"id": "ex_01", "level": "CE1", "difficulty": 2, "tags": ["pluriel"]}
|
||||
assert_eq(SchemaValidator.validate(data, schema), [])
|
||||
|
||||
|
||||
func test_missing_required_property_is_reported() -> void:
|
||||
var data := { "level": "CE1" }
|
||||
var data := {"level": "CE1"}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "id")
|
||||
|
||||
|
||||
func test_wrong_type_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": "deux" }
|
||||
var data := {"id": "ex_01", "level": "CE1", "difficulty": "deux"}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "difficulty")
|
||||
|
||||
|
||||
func test_enum_violation_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CM1" }
|
||||
var data := {"id": "ex_01", "level": "CM1"}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "level")
|
||||
|
||||
|
||||
func test_pattern_violation_is_reported() -> void:
|
||||
var data := { "id": "Ex-01", "level": "CE1" }
|
||||
var data := {"id": "Ex-01", "level": "CE1"}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "id")
|
||||
|
||||
|
||||
func test_unexpected_property_is_reported_when_additional_forbidden() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "extra": true }
|
||||
var data := {"id": "ex_01", "level": "CE1", "extra": true}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "extra")
|
||||
|
||||
|
||||
func test_min_items_violation_is_reported() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "tags": [] }
|
||||
var data := {"id": "ex_01", "level": "CE1", "tags": []}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "tags")
|
||||
|
||||
|
||||
func test_numeric_bounds_are_checked() -> void:
|
||||
var data := { "id": "ex_01", "level": "CE1", "difficulty": 9 }
|
||||
var data := {"id": "ex_01", "level": "CE1", "difficulty": 9}
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "difficulty")
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://c3gl78mc1o27p
|
||||
@@ -3,24 +3,24 @@ extends GutTest
|
||||
|
||||
|
||||
func test_multiple_choice_rejects_out_of_bounds_correct_answer() -> void:
|
||||
var data := { "answers": ["a", "b"], "correct_answer": 5 }
|
||||
var data := {"answers": ["a", "b"], "correct_answer": 5}
|
||||
var errors := SemanticChecks.check_multiple_choice(data, "test")
|
||||
assert_eq(errors.size(), 1)
|
||||
|
||||
|
||||
func test_multiple_choice_accepts_valid_index() -> void:
|
||||
var data := { "answers": ["a", "b"], "correct_answer": 1 }
|
||||
var data := {"answers": ["a", "b"], "correct_answer": 1}
|
||||
assert_eq(SemanticChecks.check_multiple_choice(data, "test"), [])
|
||||
|
||||
|
||||
func test_sentence_correction_requires_at_least_one_error_token() -> void:
|
||||
var data := { "tokens": [{ "text": "Les", "correct": true }] }
|
||||
var data := {"tokens": [{"text": "Les", "correct": true}]}
|
||||
var errors := SemanticChecks.check_sentence_correction(data, "test")
|
||||
assert_eq(errors.size(), 1)
|
||||
|
||||
|
||||
func test_sentence_correction_requires_expected_on_error_tokens() -> void:
|
||||
var data := { "tokens": [{ "text": "petit", "correct": false }] }
|
||||
var data := {"tokens": [{"text": "petit", "correct": false}]}
|
||||
var errors := SemanticChecks.check_sentence_correction(data, "test")
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "expected")
|
||||
@@ -29,7 +29,7 @@ func test_sentence_correction_requires_expected_on_error_tokens() -> void:
|
||||
func test_dictation_word_count_must_match_target_text() -> void:
|
||||
var data := {
|
||||
"target_text": "Les petits chats dorment.",
|
||||
"words": [{ "text": "Les" }, { "text": "petits" }],
|
||||
"words": [{"text": "Les"}, {"text": "petits"}],
|
||||
}
|
||||
var errors := SemanticChecks.check_dictation(data, "test")
|
||||
assert_eq(errors.size(), 1)
|
||||
@@ -38,8 +38,6 @@ func test_dictation_word_count_must_match_target_text() -> void:
|
||||
func test_dictation_accepts_matching_word_count() -> void:
|
||||
var data := {
|
||||
"target_text": "Les petits chats dorment.",
|
||||
"words": [
|
||||
{ "text": "Les" }, { "text": "petits" }, { "text": "chats" }, { "text": "dorment." }
|
||||
],
|
||||
"words": [{"text": "Les"}, {"text": "petits"}, {"text": "chats"}, {"text": "dorment."}],
|
||||
}
|
||||
assert_eq(SemanticChecks.check_dictation(data, "test"), [])
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bxlm60qsghevm
|
||||
Reference in New Issue
Block a user