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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ctn0svsnq535v
|
||||
@@ -0,0 +1,67 @@
|
||||
extends GutTest
|
||||
## Tests de DictationAnalyzer : alignement, classification lexicale/grammaticale
|
||||
## via annotation, majuscule, variantes acceptees.
|
||||
|
||||
var dictation: Dictionary = {
|
||||
"target_text": "Les petits chats dorment.",
|
||||
"words":
|
||||
[
|
||||
{"text": "Les", "expects_capital": true},
|
||||
{"text": "petits", "rule_id": "regle_accord_adjectif"},
|
||||
{"text": "chats"},
|
||||
{"text": "dorment."},
|
||||
],
|
||||
"accepted_variants": [],
|
||||
}
|
||||
|
||||
|
||||
func test_exact_match_is_correct() -> void:
|
||||
var result := DictationAnalyzer.analyze(dictation, "Les petits chats dorment.")
|
||||
assert_true(result.is_correct)
|
||||
assert_eq(result.errors, [])
|
||||
|
||||
|
||||
func test_annotated_word_error_is_classified_as_grammatical() -> void:
|
||||
var result := DictationAnalyzer.analyze(dictation, "Les petit chats dorment.")
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["error_type"], "grammatical")
|
||||
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_unannotated_word_error_is_unclassified() -> void:
|
||||
var result := DictationAnalyzer.analyze(dictation, "Les petits chat dorment.")
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["error_type"], "unclassified")
|
||||
assert_eq(result.errors[0]["rule_id"], "")
|
||||
|
||||
|
||||
func test_missing_word_does_not_cascade_into_further_errors() -> void:
|
||||
# Le mot "petits" est omis : sans alignement, cela provoquerait deux
|
||||
# erreurs en cascade sur "chats" et "dorment.".
|
||||
var result := DictationAnalyzer.analyze(dictation, "Les chats dorment.")
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["rule_id"], "regle_accord_adjectif")
|
||||
|
||||
|
||||
func test_missing_capital_is_reported_separately() -> void:
|
||||
var result := DictationAnalyzer.analyze(dictation, "les petits chats dorment.")
|
||||
assert_false(result.is_correct)
|
||||
assert_eq(result.errors.size(), 1)
|
||||
assert_eq(result.errors[0]["error_type"], "capitalization")
|
||||
|
||||
|
||||
func test_accepted_variant_is_treated_as_correct() -> void:
|
||||
var dictation_with_variant: Dictionary = dictation.duplicate(true)
|
||||
dictation_with_variant["accepted_variants"] = ["Les petits chats dorment"]
|
||||
var result := DictationAnalyzer.analyze(dictation_with_variant, "Les petits chats dorment")
|
||||
assert_true(result.is_correct)
|
||||
|
||||
|
||||
func test_normalizes_before_comparing() -> void:
|
||||
var result := DictationAnalyzer.analyze(dictation, "Les petits chats dorment.")
|
||||
assert_true(result.is_correct)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ta26vku8mxa
|
||||
@@ -0,0 +1,39 @@
|
||||
extends GutTest
|
||||
## Tests de TextNormalizer : espaces, apostrophes, caracteres francais decomposes.
|
||||
|
||||
|
||||
func test_normalizes_non_breaking_spaces() -> void:
|
||||
var text := "Les petits chats"
|
||||
assert_eq(TextNormalizer.normalize(text), "Les petits chats")
|
||||
|
||||
|
||||
func test_normalizes_typographic_apostrophe() -> void:
|
||||
assert_eq(TextNormalizer.normalize("l’école"), "l'école")
|
||||
|
||||
|
||||
func test_collapses_multiple_spaces() -> void:
|
||||
assert_eq(TextNormalizer.normalize("Les petits chats"), "Les petits chats")
|
||||
|
||||
|
||||
func test_recomposes_decomposed_accented_characters() -> void:
|
||||
# "e" + accent aigu combinant (U+0301) doit devenir "é" precompose.
|
||||
var decomposed := "école"
|
||||
assert_eq(TextNormalizer.normalize(decomposed), "école")
|
||||
|
||||
|
||||
func test_recomposes_cedille() -> void:
|
||||
var decomposed := "français"
|
||||
assert_eq(TextNormalizer.normalize(decomposed), "français")
|
||||
|
||||
|
||||
func test_strips_leading_and_trailing_whitespace() -> void:
|
||||
assert_eq(TextNormalizer.normalize(" bonjour "), "bonjour")
|
||||
|
||||
|
||||
func test_split_words_splits_on_single_spaces() -> void:
|
||||
var words := TextNormalizer.split_words("Les petits chats dorment.")
|
||||
assert_eq(words, ["Les", "petits", "chats", "dorment."])
|
||||
|
||||
|
||||
func test_split_words_on_empty_text_returns_empty_array() -> void:
|
||||
assert_eq(TextNormalizer.split_words(" "), [])
|
||||
@@ -0,0 +1 @@
|
||||
uid://dqrgabx44in1k
|
||||
@@ -0,0 +1,45 @@
|
||||
extends GutTest
|
||||
## Tests de WordAligner : l'alignement doit absorber les mots omis ou ajoutes
|
||||
## sans decaler les comparaisons suivantes.
|
||||
|
||||
var target: Array[String] = ["Les", "petits", "chats", "dorment."]
|
||||
|
||||
|
||||
func test_identical_sequences_are_all_matches() -> void:
|
||||
var ops := WordAligner.align(target, target.duplicate())
|
||||
for op in ops:
|
||||
assert_eq(op["op"], "match")
|
||||
assert_eq(ops.size(), 4)
|
||||
|
||||
|
||||
func test_single_substitution_is_detected_at_the_right_position() -> void:
|
||||
var submitted: Array[String] = ["Les", "petit", "chats", "dorment."]
|
||||
var ops := WordAligner.align(target, submitted)
|
||||
assert_eq(ops.size(), 4)
|
||||
assert_eq(ops[1]["op"], "substitute")
|
||||
assert_eq(ops[1]["target_index"], 1)
|
||||
assert_eq(ops[0]["op"], "match")
|
||||
assert_eq(ops[2]["op"], "match")
|
||||
assert_eq(ops[3]["op"], "match")
|
||||
|
||||
|
||||
func test_missing_word_is_a_delete_and_does_not_shift_later_matches() -> void:
|
||||
# L'enfant a oublie "petits" : sans alignement, "chats" se comparerait a
|
||||
# "petits" et "dorment." a "chats", generant deux fausses erreurs en cascade.
|
||||
var submitted: Array[String] = ["Les", "chats", "dorment."]
|
||||
var ops := WordAligner.align(target, submitted)
|
||||
assert_eq(ops.size(), 4)
|
||||
assert_eq(ops[0]["op"], "match")
|
||||
assert_eq(ops[1]["op"], "delete")
|
||||
assert_eq(ops[1]["target_index"], 1)
|
||||
assert_eq(ops[2]["op"], "match")
|
||||
assert_eq(ops[2]["target_index"], 2)
|
||||
assert_eq(ops[3]["op"], "match")
|
||||
assert_eq(ops[3]["target_index"], 3)
|
||||
|
||||
|
||||
func test_extra_word_is_an_insert() -> void:
|
||||
var submitted: Array[String] = ["Les", "petits", "petits", "chats", "dorment."]
|
||||
var ops := WordAligner.align(target, submitted)
|
||||
var insert_ops: Array = ops.filter(func(op: Dictionary) -> bool: return op["op"] == "insert")
|
||||
assert_eq(insert_ops.size(), 1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://de278l35ygq6i
|
||||
@@ -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
|
||||
@@ -0,0 +1,19 @@
|
||||
extends GutTest
|
||||
## Tests de AttemptFlow : aide graduee sur 3 tentatives, sortie sans blocage.
|
||||
|
||||
|
||||
func test_first_error_gives_a_hint() -> void:
|
||||
assert_eq(AttemptFlow.support_level_for_attempt(1), AttemptFlow.SupportLevel.HINT)
|
||||
|
||||
|
||||
func test_second_error_gives_an_explanation() -> void:
|
||||
assert_eq(AttemptFlow.support_level_for_attempt(2), AttemptFlow.SupportLevel.EXPLANATION)
|
||||
|
||||
|
||||
func test_third_error_reveals_the_answer() -> void:
|
||||
assert_eq(AttemptFlow.support_level_for_attempt(3), AttemptFlow.SupportLevel.REVEAL)
|
||||
|
||||
|
||||
func test_exercise_ends_at_max_attempts() -> void:
|
||||
assert_false(AttemptFlow.should_end_exercise(2))
|
||||
assert_true(AttemptFlow.should_end_exercise(3))
|
||||
@@ -0,0 +1 @@
|
||||
uid://dkijvppw88nt8
|
||||
@@ -0,0 +1,32 @@
|
||||
extends GutTest
|
||||
## Tests de DifficultyManager.
|
||||
|
||||
|
||||
func test_three_consecutive_successes_raise_difficulty() -> void:
|
||||
var recent: Array[bool] = [true, true, true]
|
||||
assert_eq(DifficultyManager.next_difficulty(1, recent), 2)
|
||||
|
||||
|
||||
func test_three_consecutive_failures_lower_difficulty() -> void:
|
||||
var recent: Array[bool] = [false, false, false]
|
||||
assert_eq(DifficultyManager.next_difficulty(2, recent), 1)
|
||||
|
||||
|
||||
func test_mixed_results_keep_difficulty_stable() -> void:
|
||||
var recent: Array[bool] = [true, false, true]
|
||||
assert_eq(DifficultyManager.next_difficulty(2, recent), 2)
|
||||
|
||||
|
||||
func test_difficulty_never_exceeds_maximum() -> void:
|
||||
var recent: Array[bool] = [true, true, true]
|
||||
assert_eq(DifficultyManager.next_difficulty(3, recent), 3)
|
||||
|
||||
|
||||
func test_difficulty_never_goes_below_minimum() -> void:
|
||||
var recent: Array[bool] = [false, false, false]
|
||||
assert_eq(DifficultyManager.next_difficulty(1, recent), 1)
|
||||
|
||||
|
||||
func test_not_enough_history_keeps_difficulty_unchanged() -> void:
|
||||
var recent: Array[bool] = [true, true]
|
||||
assert_eq(DifficultyManager.next_difficulty(2, recent), 2)
|
||||
@@ -0,0 +1 @@
|
||||
uid://tglbwa62prwa
|
||||
@@ -0,0 +1,133 @@
|
||||
extends GutTest
|
||||
## Tests de ReviewScheduler : transitions de maitrise (cahier des charges §9)
|
||||
## et planification des revisions en seances (pas en dates calendaires).
|
||||
|
||||
|
||||
func _attempt(
|
||||
success: bool, hint_used: bool = false, exercise_type: String = "multiple_choice"
|
||||
) -> Dictionary:
|
||||
return {"success": success, "hint_used": hint_used, "exercise_type": exercise_type}
|
||||
|
||||
|
||||
func test_initial_state_is_decouverte() -> void:
|
||||
assert_eq(ReviewScheduler.initial_state()["status"], ReviewScheduler.STATUS_DECOUVERTE)
|
||||
|
||||
|
||||
func test_first_success_moves_to_en_acquisition() -> void:
|
||||
var state := ReviewScheduler.record_attempt(ReviewScheduler.initial_state(), _attempt(true), 1)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_EN_ACQUISITION)
|
||||
|
||||
|
||||
func test_first_failure_stays_at_decouverte() -> void:
|
||||
var state := ReviewScheduler.record_attempt(ReviewScheduler.initial_state(), _attempt(false), 1)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_DECOUVERTE)
|
||||
|
||||
|
||||
func test_two_hintless_successes_reach_en_consolidation() -> void:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 1)
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 1)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_EN_CONSOLIDATION)
|
||||
|
||||
|
||||
func test_successes_with_hints_do_not_reach_en_consolidation() -> void:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true, true), 1)
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true, true), 1)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_EN_ACQUISITION)
|
||||
|
||||
|
||||
func test_full_path_to_acquise_requires_sessions_and_formats() -> void:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
var sessions := [1, 1, 2, 2, 3, 3, 4, 4]
|
||||
var types := ["multiple_choice", "sentence_correction"]
|
||||
for i in 8:
|
||||
state = ReviewScheduler.record_attempt(
|
||||
state, _attempt(true, false, types[i % 2]), sessions[i]
|
||||
)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
assert_eq(state["review_interval_index"], 0)
|
||||
assert_eq(state["next_review_session"], 4 + ReviewScheduler.REVIEW_INTERVALS_SESSIONS[0])
|
||||
|
||||
|
||||
func test_acquise_requires_at_least_three_distinct_sessions() -> void:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
var types := ["multiple_choice", "sentence_correction"]
|
||||
# 8 succes mais seulement 2 seances distinctes : ne doit pas atteindre "acquise".
|
||||
for i in 8:
|
||||
state = ReviewScheduler.record_attempt(
|
||||
state, _attempt(true, false, types[i % 2]), 1 if i < 4 else 2
|
||||
)
|
||||
assert_ne(state["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
|
||||
|
||||
func test_acquise_requires_at_least_two_distinct_formats() -> void:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
var sessions := [1, 1, 2, 2, 3, 3, 4, 4]
|
||||
for i in 8:
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), sessions[i])
|
||||
assert_ne(state["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
|
||||
|
||||
func _make_acquise_state(interval_index: int, next_review_session: int) -> Dictionary:
|
||||
var state := ReviewScheduler.initial_state()
|
||||
state["status"] = ReviewScheduler.STATUS_ACQUISE
|
||||
state["recent_results"] = [true, true, true, true, true, true, true, true]
|
||||
state["recent_hint_used"] = [false, false, false, false, false, false, false, false]
|
||||
state["sessions_succeeded"] = [1, 2, 3]
|
||||
state["formats_succeeded"] = ["multiple_choice", "sentence_correction"]
|
||||
state["review_interval_index"] = interval_index
|
||||
state["next_review_session"] = next_review_session
|
||||
return state
|
||||
|
||||
|
||||
func test_failure_on_acquise_skill_moves_to_a_reviser() -> void:
|
||||
var state := _make_acquise_state(0, 99)
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(false), 5)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_A_REVISER)
|
||||
assert_eq(state["next_review_session"], -1)
|
||||
|
||||
|
||||
func test_success_on_a_reviser_skill_returns_to_acquise_at_first_interval() -> void:
|
||||
var state := _make_acquise_state(2, 99)
|
||||
state["status"] = ReviewScheduler.STATUS_A_REVISER
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 10)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
assert_eq(state["review_interval_index"], 0)
|
||||
assert_eq(state["next_review_session"], 10 + ReviewScheduler.REVIEW_INTERVALS_SESSIONS[0])
|
||||
|
||||
|
||||
func test_successful_review_on_time_advances_to_next_interval() -> void:
|
||||
var state := _make_acquise_state(0, 5)
|
||||
assert_true(ReviewScheduler.is_due_for_review(state, 5))
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 5)
|
||||
assert_eq(state["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
assert_eq(state["review_interval_index"], 1)
|
||||
assert_eq(state["next_review_session"], 5 + ReviewScheduler.REVIEW_INTERVALS_SESSIONS[1])
|
||||
|
||||
|
||||
func test_success_before_due_date_does_not_advance_interval() -> void:
|
||||
var state := _make_acquise_state(0, 10)
|
||||
assert_false(ReviewScheduler.is_due_for_review(state, 5))
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 5)
|
||||
assert_eq(state["review_interval_index"], 0)
|
||||
assert_eq(state["next_review_session"], 10)
|
||||
|
||||
|
||||
func test_review_interval_never_exceeds_last_step() -> void:
|
||||
var last_index := ReviewScheduler.REVIEW_INTERVALS_SESSIONS.size() - 1
|
||||
var state := _make_acquise_state(last_index, 5)
|
||||
state = ReviewScheduler.record_attempt(state, _attempt(true), 5)
|
||||
assert_eq(state["review_interval_index"], last_index)
|
||||
|
||||
|
||||
func test_mark_overdue_as_review_transitions_without_new_attempt() -> void:
|
||||
var state := _make_acquise_state(0, 5)
|
||||
var updated := ReviewScheduler.mark_overdue_as_review(state, 6)
|
||||
assert_eq(updated["status"], ReviewScheduler.STATUS_A_REVISER)
|
||||
|
||||
|
||||
func test_mark_overdue_as_review_does_nothing_before_due_date() -> void:
|
||||
var state := _make_acquise_state(0, 5)
|
||||
var updated := ReviewScheduler.mark_overdue_as_review(state, 3)
|
||||
assert_eq(updated["status"], ReviewScheduler.STATUS_ACQUISE)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cryfvtynu2fue
|
||||
Reference in New Issue
Block a user