Skip to content

Commit 31f7669

Browse files
rootroot
authored andcommitted
fix: neutral placeholder, exam edge cases, stronger invariants (review)
1 parent 11167a7 commit 31f7669

2 files changed

Lines changed: 60 additions & 8 deletions

File tree

app/extended_curriculum.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ def _make_questions(
14201420
"kind": "input",
14211421
"prompt": f"Какой ключевой инструмент или термин связывает урок «{title}»?",
14221422
"answers": [keyword, *TERM_SYNONYMS.get(keyword, ())],
1423-
"placeholder": f"Например: {keyword}",
1423+
"placeholder": "Введите термин",
14241424
"explanation": f"Ключевой ориентир урока — «{keyword}». {subtitle}.",
14251425
},
14261426
{"id": f"{lesson_id}-code", "kind": "code", **code_task},
@@ -1483,6 +1483,7 @@ def build_extended_course() -> tuple[
14831483
question_ids = [
14841484
random.Random(f"{module_id}:{kind}").choice(ids)
14851485
for kind, ids in question_ids_by_kind.items()
1486+
if ids
14861487
]
14871488
remaining_ids = [
14881489
question_id
@@ -1491,7 +1492,8 @@ def build_extended_course() -> tuple[
14911492
if question_id not in question_ids
14921493
]
14931494
random.Random(f"{module_id}:exam").shuffle(remaining_ids)
1494-
question_ids.append(remaining_ids[0])
1495+
if remaining_ids:
1496+
question_ids.append(remaining_ids[0])
14951497
random.Random(f"{module_id}:exam-order").shuffle(question_ids)
14961498
exams[module_id] = {
14971499
"title": f"Контрольная точка: {unit['title']}",

tests/test_curriculum.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from app import extended_curriculum
12
from app.content import EXAMS, LESSONS, MODULES, QUESTION_BY_ID
3+
from app.evaluator import normalize
4+
from app.extended_curriculum import TERM_SYNONYMS, build_extended_course
25

36

47
def test_full_course_has_120_progressive_lessons() -> None:
@@ -29,13 +32,14 @@ def test_every_module_has_a_valid_exam() -> None:
2932

3033
def test_extended_questions_are_fair_and_exams_are_mixed() -> None:
3134
extended_lessons = [lesson for lesson in LESSONS if lesson["order"] >= 13]
32-
choice_positions = {
35+
choice_positions = [
3336
question["options"].index(question["answer"])
3437
for lesson in extended_lessons
3538
for question in lesson["questions"]
3639
if question["kind"] == "choice"
37-
}
38-
assert len(choice_positions) > 1
40+
]
41+
assert len(set(choice_positions)) > 1
42+
assert all(0 <= position < 3 for position in choice_positions)
3943
assert (
4044
sum(
4145
len(question["answers"]) > 1
@@ -47,6 +51,52 @@ def test_extended_questions_are_fair_and_exams_are_mixed() -> None:
4751
)
4852
extended_modules = {lesson["module_id"] for lesson in extended_lessons}
4953
for module_id in extended_modules:
50-
assert {
51-
QUESTION_BY_ID[question_id]["kind"] for question_id in EXAMS[module_id]["question_ids"]
52-
} == {"choice", "input", "code"}
54+
question_ids = EXAMS[module_id]["question_ids"]
55+
assert len(question_ids) == len(set(question_ids)) == 4
56+
assert {QUESTION_BY_ID[question_id]["kind"] for question_id in question_ids} == {
57+
"choice",
58+
"input",
59+
"code",
60+
}
61+
62+
term_question = next(
63+
question
64+
for lesson in extended_lessons
65+
for question in lesson["questions"]
66+
if question["kind"] == "input" and len(question["answers"]) > 1
67+
)
68+
assert all(
69+
normalize(answer) not in normalize(term_question["placeholder"])
70+
for answer in term_question["answers"]
71+
)
72+
73+
keyword, synonyms = next(iter(TERM_SYNONYMS.items()))
74+
answers = next(
75+
question["answers"]
76+
for lesson in extended_lessons
77+
for question in lesson["questions"]
78+
if question["kind"] == "input" and keyword in question["answers"]
79+
)
80+
assert normalize(f" {synonyms[0].upper()} ") in {normalize(answer) for answer in answers}
81+
82+
83+
def test_extended_generation_is_deterministic_and_handles_short_modules(monkeypatch) -> None:
84+
first = build_extended_course()
85+
second = build_extended_course()
86+
assert first == second
87+
88+
monkeypatch.setattr(
89+
extended_curriculum,
90+
"COURSE_UNITS",
91+
[
92+
{
93+
**extended_curriculum.COURSE_UNITS[0],
94+
"lessons": extended_curriculum.COURSE_UNITS[0]["lessons"][:1],
95+
}
96+
],
97+
)
98+
monkeypatch.setattr(
99+
extended_curriculum, "TASK_CYCLES", [extended_curriculum.TASK_CYCLES[0][:1]]
100+
)
101+
_, _, exams = build_extended_course()
102+
assert len(next(iter(exams.values()))["question_ids"]) == 3

0 commit comments

Comments
 (0)