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:
@@ -0,0 +1,77 @@
|
||||
extends GutTest
|
||||
## Tests de AnswerValidator (choix multiple et correction de phrase).
|
||||
|
||||
var multiple_choice_exercise: Dictionary = {
|
||||
"rule_id": "regle_test",
|
||||
"answers": ["petit", "petits", "petite"],
|
||||
"correct_answer": 1,
|
||||
"hint": "indice",
|
||||
"explanation": "explication",
|
||||
}
|
||||
|
||||
var sentence_correction_exercise: Dictionary = {
|
||||
"rule_id": "regle_test",
|
||||
"hint": "indice",
|
||||
"explanation": "explication",
|
||||
"tokens":
|
||||
[
|
||||
{"text": "Les", "correct": true},
|
||||
{
|
||||
"text": "petit",
|
||||
"correct": false,
|
||||
"expected": "petits",
|
||||
"rule_id": "regle_accord_adjectif",
|
||||
},
|
||||
{"text": "chiens", "correct": true},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
func test_multiple_choice_correct_answer() -> void:
|
||||
var result := AnswerValidator.validate_multiple_choice(multiple_choice_exercise, 1)
|
||||
assert_true(result.is_correct)
|
||||
assert_eq(result.errors, [])
|
||||
|
||||
|
||||
func test_multiple_choice_wrong_answer_reports_found_and_expected() -> void:
|
||||
var result := AnswerValidator.validate_multiple_choice(multiple_choice_exercise, 0)
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["found"], "petit")
|
||||
assert_eq(result.errors[0]["expected"], "petits")
|
||||
assert_eq(result.errors[0]["rule_id"], "regle_test")
|
||||
|
||||
|
||||
func test_sentence_correction_fully_correct() -> void:
|
||||
var result := AnswerValidator.validate_sentence_correction(
|
||||
sentence_correction_exercise, [1], {1: "petits"}
|
||||
)
|
||||
assert_true(result.is_correct)
|
||||
|
||||
|
||||
func test_sentence_correction_missed_faulty_token() -> void:
|
||||
var result := AnswerValidator.validate_sentence_correction(sentence_correction_exercise, [], {})
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["rule_id"], "regle_accord_adjectif")
|
||||
assert_eq(result.errors[0]["found"], "petit")
|
||||
assert_eq(result.errors[0]["expected"], "petits")
|
||||
|
||||
|
||||
func test_sentence_correction_wrong_correction_text() -> void:
|
||||
var result := AnswerValidator.validate_sentence_correction(
|
||||
sentence_correction_exercise, [1], {1: "petite"}
|
||||
)
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors[0]["found"], "petite")
|
||||
assert_eq(result.errors[0]["expected"], "petits")
|
||||
|
||||
|
||||
func test_sentence_correction_false_positive_on_correct_token() -> void:
|
||||
var result := AnswerValidator.validate_sentence_correction(
|
||||
sentence_correction_exercise, [1, 2], {1: "petits", 2: "chien"}
|
||||
)
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["error_type"], "unclassified")
|
||||
assert_eq(result.errors[0]["position"], 2)
|
||||
Reference in New Issue
Block a user