괄호 안의 항을 2, 3, 4 항으로 설정하는 기능 추가

This commit is contained in:
2026-05-31 13:40:45 +09:00
parent e148a957ea
commit ac3c939051
21 changed files with 708 additions and 344 deletions
+17 -2
View File
@@ -10,7 +10,7 @@ import type { VariableParenthesisProblem } from "./variable-types";
function findCorrectChoiceIds(problem: VariableParenthesisProblem) {
return problem.correctTerms.map((term, index) => {
const choices = problem.choices[index as 0 | 1];
const choices = problem.choices[index];
const choice = choices.find(
(item) =>
item.coefficient === term.coefficient && item.variable === term.variable,
@@ -19,7 +19,7 @@ function findCorrectChoiceIds(problem: VariableParenthesisProblem) {
if (!choice) throw new Error("correct choice not found.");
return choice.id;
}) as [string, string];
});
}
describe("variable parenthesis engine", () => {
@@ -97,6 +97,21 @@ describe("variable parenthesis engine", () => {
expect(keys.size).toBe(10);
});
it("generates the selected number of variable choices", () => {
const problem = generateVariableParenthesisProblem(4);
expect(problem.terms).toHaveLength(4);
expect(problem.operators).toHaveLength(3);
expect(problem.correctTerms).toHaveLength(4);
expect(problem.choices).toHaveLength(4);
expect(problem.terms.filter((term) => term.kind === "variable")).toHaveLength(1);
expect(
gradeVariableParenthesisAnswer(problem, {
selectedChoiceIds: findCorrectChoiceIds(problem),
}).correct,
).toBe(true);
});
it("formats expressions with variable terms", () => {
expect(
formatVariableExpressionLatex([