mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 15:37:11 +01:00
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T Co-authored-by: Claude <noreply@anthropic.com>
123 lines
6.2 KiB
TypeScript
123 lines
6.2 KiB
TypeScript
import { test, describe } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { DEFAULT_COURSE } from "../../course/registry.ts";
|
|
import { SITUATIONS } from "../../situations/active.ts";
|
|
import type { SituationPack } from "../../situations/pack.ts";
|
|
import { VARIETY } from "../../variety/active.ts";
|
|
import type { VarietyPack } from "../../variety/pack.ts";
|
|
import { closenessOf, levelOf, yardstickOf } from "../vocabulary/distance.ts";
|
|
import { packItems } from "./generate.ts";
|
|
import { declaredLevels, distanceLevels, levelNames, levelSourceFor, STEP_OF, withLevels } from "./levels.ts";
|
|
import { getDictionary } from "../../i18n/index.ts";
|
|
import { LOCALES } from "../../i18n/locales.ts";
|
|
import { PACK_ITEMS } from "./published.ts";
|
|
import type { PracticeItem } from "./types.ts";
|
|
|
|
const levelsOf = (items: readonly PracticeItem[]) => new Map(items.map((i) => [i.id, i.source.level]));
|
|
|
|
/** The pack with a level declared on everything, the way a zero-entry course would write it. */
|
|
const DECLARED: VarietyPack = {
|
|
...VARIETY,
|
|
vocabulary: (VARIETY.vocabulary ?? []).map((w) => ({ ...w, level: "A1" as const })),
|
|
grammar: (VARIETY.grammar ?? []).map((t) => ({ ...t, level: "B2" as const })),
|
|
};
|
|
const DECLARED_SCENES: readonly SituationPack[] = SITUATIONS.map((p) => ({
|
|
...p,
|
|
situations: p.situations.map((s) => ({ ...s, phrases: s.phrases.map((l) => ({ ...l, level: "A2" as const })) })),
|
|
}));
|
|
|
|
describe("the Zurich course keeps every level it had", () => {
|
|
test("the default course is entered from a sibling, so its levels are measured", () => {
|
|
assert.equal(DEFAULT_COURSE.entry, "sibling");
|
|
const measured = levelsOf(withLevels(PACK_ITEMS, distanceLevels(VARIETY, SITUATIONS)));
|
|
const published = levelsOf(PACK_ITEMS);
|
|
assert.equal(published.size, PACK_ITEMS.length);
|
|
for (const [id, level] of published) assert.equal(level, measured.get(id), `${id} changed level`);
|
|
});
|
|
|
|
test("every published word item carries exactly its word's distance from the sibling", () => {
|
|
// Recomputed here from the one classification, not from `levels.ts`.
|
|
const by = yardstickOf(VARIETY);
|
|
const words = new Map((VARIETY.vocabulary ?? []).map((w) => [w.target, levelOf(closenessOf(w, by))]));
|
|
let checked = 0;
|
|
for (const item of PACK_ITEMS) {
|
|
if (item.source.kind !== "word") continue;
|
|
assert.equal(item.source.level, words.get(item.source.word), item.id);
|
|
checked++;
|
|
}
|
|
assert.ok(checked > 500, `only ${checked} word items`);
|
|
});
|
|
|
|
test("the levels the product has always quoted", () => {
|
|
const word = (target: string) => PACK_ITEMS.find((i) => i.source.kind === "word" && i.source.word === target)?.source.level;
|
|
assert.equal(word("Chind"), 2, "free once k → ch is known");
|
|
assert.equal(word("nöd"), 3, "nothing in the sibling leads there");
|
|
for (const item of PACK_ITEMS) {
|
|
if (item.source.kind === "rule") assert.equal(item.source.level, 2, item.id);
|
|
if (item.source.kind === "grammar") assert.ok((item.source.level ?? 0) >= 2, `${item.id}: a topic never ranks 1`);
|
|
}
|
|
});
|
|
|
|
test("every published item has one of the three levels", () => {
|
|
const count = (level: number | undefined) => PACK_ITEMS.filter((i) => i.source.level === level).length;
|
|
assert.equal(count(undefined), 0);
|
|
assert.equal(count(1) + count(2) + count(3), PACK_ITEMS.length);
|
|
});
|
|
|
|
test("a declared level on an entry never changes a measured course", () => {
|
|
const plain = levelsOf(packItems(VARIETY, SITUATIONS, "sibling"));
|
|
const withDeclared = levelsOf(packItems(DECLARED, DECLARED_SCENES, "sibling"));
|
|
assert.deepEqual([...withDeclared], [...plain]);
|
|
});
|
|
});
|
|
|
|
describe("a course entered from zero reads the level somebody declared", () => {
|
|
test("the source follows the course's entry mode", () => {
|
|
const items = packItems(DECLARED, DECLARED_SCENES, "zero");
|
|
const direct = withLevels(items, declaredLevels(DECLARED, DECLARED_SCENES));
|
|
assert.deepEqual([...levelsOf(items)], [...levelsOf(direct)]);
|
|
assert.deepEqual(
|
|
[...levelsOf(withLevels(items, levelSourceFor("sibling", DECLARED, DECLARED_SCENES)))],
|
|
[...levelsOf(withLevels(items, distanceLevels(DECLARED, DECLARED_SCENES)))],
|
|
);
|
|
});
|
|
|
|
test("a word, a line and a topic each carry their own declared band", () => {
|
|
for (const item of packItems(DECLARED, DECLARED_SCENES, "zero")) {
|
|
const { kind } = item.source;
|
|
if (kind === "word") assert.equal(item.source.level, STEP_OF.A1, item.id);
|
|
if (kind === "grammar") assert.equal(item.source.level, STEP_OF.B2, item.id);
|
|
if (kind === "situation" && item.source.line !== undefined) assert.equal(item.source.level, STEP_OF.A2, item.id);
|
|
if (kind === "rule") assert.equal(item.source.level, undefined, "a sound rule is a sibling's, and is not levelled here");
|
|
}
|
|
});
|
|
|
|
test("nothing is inferred where nothing was declared", () => {
|
|
const items = packItems(VARIETY, SITUATIONS, "zero");
|
|
assert.ok(items.length > 0);
|
|
for (const item of items) assert.equal(item.source.level, undefined, `${item.id} got a level nobody declared`);
|
|
});
|
|
|
|
test("the six bands fall onto the three steps in order", () => {
|
|
const steps = (["A1", "A2", "B1", "B2", "C1", "C2"] as const).map((band) => STEP_OF[band]);
|
|
assert.deepEqual(steps, [...steps].sort((a, b) => a - b));
|
|
assert.deepEqual([...new Set(steps)], [1, 2, 3]);
|
|
});
|
|
});
|
|
|
|
test("the names of the levels follow the course's entry: a distance for a sibling course, a band from zero", () => {
|
|
for (const locale of LOCALES) {
|
|
const t = getDictionary(locale).progressBy;
|
|
assert.equal(levelNames(t, "sibling"), t.levels);
|
|
assert.equal(levelNames(t, "zero"), t.levelsFromZero);
|
|
for (const step of ["1", "2", "3"] as const) {
|
|
assert.ok(t.levelsFromZero[step].trim(), `${locale} has no name for step ${step} of a course entered from zero`);
|
|
assert.notEqual(t.levelsFromZero[step], t.levels[step], `${locale}: step ${step} from zero is still worded as a distance`);
|
|
}
|
|
// The step a band lands on is named by that band, in every language.
|
|
for (const [band, step] of Object.entries(STEP_OF)) {
|
|
if (band === "A1" || band === "A2" || band === "B1") assert.ok(t.levelsFromZero[String(step) as "1"].includes(band), `${locale}: ${band}`);
|
|
}
|
|
}
|
|
});
|