diff --git a/src/i18n/en.ts b/src/i18n/en.ts index d4923a9..25270f1 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -163,6 +163,8 @@ export const en = { digitsLegend: "In the tables, 1 is ON and 0 is OFF.", check: "Check", passed: "Cleared! The circuit works for every combination of the inputs.", + passedSteps: (count: number) => + `Cleared! The circuit works at every time step up to time step ${count}.`, next: "Next stage", backToStages: "Back to the stages", missingPin: (pinType: "input" | "output", pinName: string) => @@ -176,6 +178,14 @@ export const en = { actual: string | null, ) => `When ${listOf(inputs.map(({ name, value }) => `${name} is ${value}`))}, ${pinName} should be ${expected}, but it ${actual === null ? "has no value" : `is ${actual}`}.`, + wrongOutputAtStep: ( + stepNumber: number, + inputs: readonly { name: string; value: string }[], + pinName: string, + expected: string, + actual: string | null, + ) => + `At time step ${stepNumber}${inputs.length > 0 ? ` (${listOf(inputs.map(({ name, value }) => `${name} is ${value}`))})` : ""}, ${pinName} should be ${expected}, but it ${actual === null ? "has no value" : `is ${actual}`}.`, checkFailed: "Something went wrong while checking. Change the circuit a little and press Check again.", simulationFailed: (detail: string) => diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 1c8c72f..73f8456 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -108,6 +108,8 @@ export const ja: Messages = { digitsLegend: "表の 1 は ON、0 は OFF です。", check: "確かめる", passed: "クリア!どの入力の組み合わせでも正しく動きます。", + passedSteps: (count) => + `クリア!${count} ステップ目まで、どのステップでも正しく動きます。`, next: "次の課題へ", backToStages: "課題の一覧へ", missingPin: (pinType, pinName) => @@ -116,6 +118,8 @@ export const ja: Messages = { `${pinName} は ${expected}桁のはずですが、${actual}桁になっています。つないだ先を確かめてください。`, wrongOutput: (inputs, pinName, expected, actual) => `${inputs.map(({ name, value }) => `${name} が ${value}`).join("、")} のとき、${pinName} は ${expected} になるはずが、${actual === null ? "値がありませんでした" : `${actual} でした`}。`, + wrongOutputAtStep: (stepNumber, inputs, pinName, expected, actual) => + `${stepNumber} ステップ目${inputs.length > 0 ? `(${inputs.map(({ name, value }) => `${name} が ${value}`).join("、")})` : ""}に、${pinName} が ${expected} のはずが${actual === null ? "、値がありませんでした" : ` ${actual} でした`}。`, checkFailed: "確かめる途中で問題が起きました。回路を少し変えてから、もう一度押してください。", simulationFailed: (detail) => diff --git a/src/i18n/messages.test.ts b/src/i18n/messages.test.ts index 17cf576..562e9e3 100644 --- a/src/i18n/messages.test.ts +++ b/src/i18n/messages.test.ts @@ -132,6 +132,33 @@ describe("the message on a wrong output", () => { }); }); +describe("the message on a wrong output at a step", () => { + const { en, ja } = messagesByLanguage; + const start = [{ name: "Start", value: "ON" }]; + + it("puts the inputs of the step in brackets", () => { + expect( + en.tutorial.wrongOutputAtStep(3, start, "Count", "0011", "0010"), + ).toBe( + "At time step 3 (Start is ON), Count should be 0011, but it is 0010.", + ); + expect( + ja.tutorial.wrongOutputAtStep(3, start, "Count", "0011", "0010"), + ).toBe( + "3 ステップ目(Start が ON)に、Count が 0011 のはずが 0010 でした。", + ); + }); + + it("leaves the brackets out without inputs", () => { + expect(en.tutorial.wrongOutputAtStep(2, [], "Count", "0001", null)).toBe( + "At time step 2, Count should be 0001, but it has no value.", + ); + expect(ja.tutorial.wrongOutputAtStep(2, [], "Count", "0001", null)).toBe( + "2 ステップ目に、Count が 0001 のはずが、値がありませんでした。", + ); + }); +}); + describe("the message on a pin of the wrong width", () => { it("counts digits in both languages", () => { expect(messagesByLanguage.en.tutorial.wrongBitWidth("A", 4, 1)).toBe( diff --git a/src/pages/tutorial/stage.tsx b/src/pages/tutorial/stage.tsx index 098db80..4e3a248 100644 --- a/src/pages/tutorial/stage.tsx +++ b/src/pages/tutorial/stage.tsx @@ -29,7 +29,7 @@ import { StoreScope } from "../../store/react"; import { theme } from "../../style"; import { type CheckResult, - checkCombinational, + checkCircuit, goalTableOf, } from "../../tutorial/check"; import { describeFailure } from "../../tutorial/failure"; @@ -96,7 +96,7 @@ function StageView({ stage }: { stage: TutorialStage }) { }, [store]); const check = () => { - const checked = checkCombinational(store, stage.componentId, stage.check); + const checked = checkCircuit(store, stage.componentId, stage.check); if (checked.type === "checkFailed") console.error(checked.error); setResult(checked); if (checked.type === "passed") markStageCleared(stage.id); @@ -228,7 +228,11 @@ function StageView({ stage }: { stage: TutorialStage }) { {result?.type === "passed" && ( <> - {texts.passed} + + {stage.check.kind === "sequential" + ? texts.passedSteps(stage.check.steps.length) + : texts.passed} +