From e0408f8f3b898cc538b56eb67f25547d22b40cde Mon Sep 17 00:00:00 2001 From: AJaccP Date: Wed, 7 Aug 2024 12:24:31 +0530 Subject: [PATCH 1/2] add 2022 winter final question 1 generator --- .../2022-winter-final/1/generator.test.ts | 106 ++++++++++++++++++ .../comp2804/2022-winter-final/1/generator.ts | 93 +++++++++++++++ .../comp2804/2022-winter-final/1/index.md | 1 + 3 files changed, 200 insertions(+) create mode 100644 src/content/questions/comp2804/2022-winter-final/1/generator.test.ts create mode 100644 src/content/questions/comp2804/2022-winter-final/1/generator.ts diff --git a/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts b/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts new file mode 100644 index 00000000..ec6f2bbf --- /dev/null +++ b/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts @@ -0,0 +1,106 @@ +import { describe, expect } from "@jest/globals"; +import Generator from "./generator"; + +describe("comp2804/2022-winter-final/1", () => { + describe("generateValues", () => { + it("will return two values", () => { + const generator = new Generator(); + + const values = generator.generateValues(); + + expect(values).toHaveLength(2); + }); + + it("will return a string length between 50 and 100", () => { + const generator = new Generator(); + + const [stringLength, _] = generator.generateValues(); + + expect(stringLength).toBeGreaterThanOrEqual(50); + expect(stringLength).toBeLessThanOrEqual(100); + }); + + it("will return a positions value between 5 and 20", () => { + const generator = new Generator(); + + const [_, positions] = generator.generateValues(); + + expect(positions).toBeGreaterThanOrEqual(5); + expect(positions).toBeLessThanOrEqual(20); + }); + }); + + describe("createOptions", () => { + it("will return five options", () => { + const generator = new Generator(); + + const options = generator.createOptions(50, 5); + + expect(options).toHaveLength(5); + }); + + it("will have exactly one correct option", () => { + const generator = new Generator(); + + const options = generator.createOptions(50, 5); + const correctOptions = options.filter((option) => option.correct); + + expect(correctOptions).toHaveLength(1); + }); + }); + + describe("createCorrectOption", () => { + it("will return the correct option", () => { + const generator = new Generator(); + + const option = generator.createCorrectOption(50, 10); + + expect(option.label).toBe("$\\binom{50}{10}\\cdot 4^{40}$"); + expect(option.correct).toBe(true); + }); + }); + + describe("createIncorrectOption1", () => { + it("will return an option with the combination being multiplied with 5 ^ value instead of 4 ^ value", () => { + const generator = new Generator(); + + const option = generator.createIncorrectOption1(50, 10); + + expect(option.label).toBe("$\\binom{50}{10}\\cdot 5^{40}$"); + expect(option.correct).toBe(false); + }); + }); + + describe("createIncorrectOption2", () => { + it("will return an option with the combination using the number of letters instead of positions and being multiplied with 5 ^ value instead of 4 ^ value", () => { + const generator = new Generator(); + + const option = generator.createIncorrectOption2(50, 10); + + expect(option.label).toBe("$\\binom{50}{5}\\cdot 5^{40}$"); + expect(option.correct).toBe(false); + }); + }); + + describe("createIncorrectOption3", () => { + it("will return an option with the combination using the number of letters instead of positions", () => { + const generator = new Generator(); + + const option = generator.createIncorrectOption3(50, 10); + + expect(option.label).toBe("$\\binom{50}{5}\\cdot 4^{40}$"); + expect(option.correct).toBe(false); + }); + }); + + describe("createIncorrectOption4", () => { + it("will return an option which does not use combinations", () => { + const generator = new Generator(); + + const option = generator.createIncorrectOption4(50, 10); + + expect(option.label).toBe("$5^{10}\\cdot 4^{40}$"); + expect(option.correct).toBe(false); + }); + }); +}); \ No newline at end of file diff --git a/src/content/questions/comp2804/2022-winter-final/1/generator.ts b/src/content/questions/comp2804/2022-winter-final/1/generator.ts new file mode 100644 index 00000000..d28830a2 --- /dev/null +++ b/src/content/questions/comp2804/2022-winter-final/1/generator.ts @@ -0,0 +1,93 @@ +import { MultipleChoiceQuestionGenerator } from "@common/MultipleChoiceQuestionGenerator"; +import type { + MultipleChoiceQuestion, + MultipleChoiceQuestionOption, +} from "@common/MultipleChoiceQuestionGenerator"; + +class Generator extends MultipleChoiceQuestionGenerator { + generateQuestion(): MultipleChoiceQuestion { + const [stringLength, positions] = this.generateValues(); + const dynamicQuestionBody = `Consider strings of length $${stringLength}$, in which each character is one of the characters $a,b,c,d,e$. How many such strings have exactly $${positions}$ letters $e$?`; + return { + body: dynamicQuestionBody, + options: this.createOptions(stringLength, positions), + }; + } + + generateValues(): [number, number] { + const stringLength = Math.floor(Math.random() * 51) + 50; //generate a value between 50 and 100 + const positions = Math.floor(Math.random() * 16) + 5; //generate a value between 5 and 20 + + return [stringLength, positions]; + } + + createOptions(stringLength: number, positions: number): MultipleChoiceQuestionOption[] { + const correctOption = this.createCorrectOption(stringLength, positions); + const incorrectOption1 = this.createIncorrectOption1(stringLength, positions); + const incorrectOption2 = this.createIncorrectOption2(stringLength, positions); + const incorrectOption3 = this.createIncorrectOption3(stringLength, positions); + const incorrectOption4 = this.createIncorrectOption4(stringLength, positions); + + return this.shuffleOptions([ + correctOption, + incorrectOption1, + incorrectOption2, + incorrectOption3, + incorrectOption4 + ]); + } + + createCorrectOption( + stringLength: number, + positions: number + ): MultipleChoiceQuestionOption { + return { + label: `$\\binom{${stringLength}}{${positions}}\\cdot 4^{${stringLength - positions}}$`, + correct: true, + }; + } + + createIncorrectOption1( + stringLength: number, + positions: number + ): MultipleChoiceQuestionOption { + return { + label: `$\\binom{${stringLength}}{${positions}}\\cdot 5^{${stringLength - positions}}$`, + correct: false, + }; + } //mutliples with 5 ^ value instead of 4 + + createIncorrectOption2( + stringLength: number, + positions: number + ): MultipleChoiceQuestionOption { + return { + label: `$\\binom{${stringLength}}{5}\\cdot 5^{${stringLength - positions}}$`, + correct: false, + }; + } //uses number of letters instead of positions and multiples with 5 ^ value instead of 4 + + createIncorrectOption3( + stringLength: number, + positions: number + ): MultipleChoiceQuestionOption { + return { + label: `$\\binom{${stringLength}}{5}\\cdot 4^{${stringLength - positions}}$`, + correct: false, + }; + } //uses number of letters instead of positions + + createIncorrectOption4( + stringLength: number, + positions: number + ): MultipleChoiceQuestionOption { + return { + label: `$5^{${positions}}\\cdot 4^{${stringLength - positions}}$`, + correct: false, + }; + } //does not use combinations + + +} + +export default Generator; \ No newline at end of file diff --git a/src/content/questions/comp2804/2022-winter-final/1/index.md b/src/content/questions/comp2804/2022-winter-final/1/index.md index f89af3a4..a1b134e5 100644 --- a/src/content/questions/comp2804/2022-winter-final/1/index.md +++ b/src/content/questions/comp2804/2022-winter-final/1/index.md @@ -5,6 +5,7 @@ type: multiple-choice author: Michiel Smid question: comp2804/2022-winter-final/1/question.ts solution: comp2804/2022-winter-final/1/solution.md +generator: comp2804/2022-winter-final/1/generator.ts tags: - comp2804 - comp2804-final From 0cfa1763aedaba337c21f7b353dffcbdfc96f49e Mon Sep 17 00:00:00 2001 From: AJaccP Date: Wed, 7 Aug 2024 12:25:38 +0530 Subject: [PATCH 2/2] linting --- .../2022-winter-final/1/generator.test.ts | 132 +++++++++--------- .../comp2804/2022-winter-final/1/generator.ts | 49 ++++--- 2 files changed, 97 insertions(+), 84 deletions(-) diff --git a/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts b/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts index ec6f2bbf..551a4085 100644 --- a/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts +++ b/src/content/questions/comp2804/2022-winter-final/1/generator.test.ts @@ -2,105 +2,105 @@ import { describe, expect } from "@jest/globals"; import Generator from "./generator"; describe("comp2804/2022-winter-final/1", () => { - describe("generateValues", () => { - it("will return two values", () => { - const generator = new Generator(); + describe("generateValues", () => { + it("will return two values", () => { + const generator = new Generator(); - const values = generator.generateValues(); + const values = generator.generateValues(); - expect(values).toHaveLength(2); - }); + expect(values).toHaveLength(2); + }); - it("will return a string length between 50 and 100", () => { - const generator = new Generator(); + it("will return a string length between 50 and 100", () => { + const generator = new Generator(); - const [stringLength, _] = generator.generateValues(); + const [stringLength, _] = generator.generateValues(); - expect(stringLength).toBeGreaterThanOrEqual(50); - expect(stringLength).toBeLessThanOrEqual(100); - }); + expect(stringLength).toBeGreaterThanOrEqual(50); + expect(stringLength).toBeLessThanOrEqual(100); + }); - it("will return a positions value between 5 and 20", () => { - const generator = new Generator(); + it("will return a positions value between 5 and 20", () => { + const generator = new Generator(); - const [_, positions] = generator.generateValues(); + const [_, positions] = generator.generateValues(); - expect(positions).toBeGreaterThanOrEqual(5); - expect(positions).toBeLessThanOrEqual(20); - }); + expect(positions).toBeGreaterThanOrEqual(5); + expect(positions).toBeLessThanOrEqual(20); }); + }); - describe("createOptions", () => { - it("will return five options", () => { - const generator = new Generator(); + describe("createOptions", () => { + it("will return five options", () => { + const generator = new Generator(); - const options = generator.createOptions(50, 5); + const options = generator.createOptions(50, 5); - expect(options).toHaveLength(5); - }); + expect(options).toHaveLength(5); + }); - it("will have exactly one correct option", () => { - const generator = new Generator(); + it("will have exactly one correct option", () => { + const generator = new Generator(); - const options = generator.createOptions(50, 5); - const correctOptions = options.filter((option) => option.correct); + const options = generator.createOptions(50, 5); + const correctOptions = options.filter((option) => option.correct); - expect(correctOptions).toHaveLength(1); - }); + expect(correctOptions).toHaveLength(1); }); + }); - describe("createCorrectOption", () => { - it("will return the correct option", () => { - const generator = new Generator(); + describe("createCorrectOption", () => { + it("will return the correct option", () => { + const generator = new Generator(); - const option = generator.createCorrectOption(50, 10); + const option = generator.createCorrectOption(50, 10); - expect(option.label).toBe("$\\binom{50}{10}\\cdot 4^{40}$"); - expect(option.correct).toBe(true); - }); + expect(option.label).toBe("$\\binom{50}{10}\\cdot 4^{40}$"); + expect(option.correct).toBe(true); }); + }); - describe("createIncorrectOption1", () => { - it("will return an option with the combination being multiplied with 5 ^ value instead of 4 ^ value", () => { - const generator = new Generator(); + describe("createIncorrectOption1", () => { + it("will return an option with the combination being multiplied with 5 ^ value instead of 4 ^ value", () => { + const generator = new Generator(); - const option = generator.createIncorrectOption1(50, 10); + const option = generator.createIncorrectOption1(50, 10); - expect(option.label).toBe("$\\binom{50}{10}\\cdot 5^{40}$"); - expect(option.correct).toBe(false); - }); + expect(option.label).toBe("$\\binom{50}{10}\\cdot 5^{40}$"); + expect(option.correct).toBe(false); }); + }); - describe("createIncorrectOption2", () => { - it("will return an option with the combination using the number of letters instead of positions and being multiplied with 5 ^ value instead of 4 ^ value", () => { - const generator = new Generator(); + describe("createIncorrectOption2", () => { + it("will return an option with the combination using the number of letters instead of positions and being multiplied with 5 ^ value instead of 4 ^ value", () => { + const generator = new Generator(); - const option = generator.createIncorrectOption2(50, 10); + const option = generator.createIncorrectOption2(50, 10); - expect(option.label).toBe("$\\binom{50}{5}\\cdot 5^{40}$"); - expect(option.correct).toBe(false); - }); + expect(option.label).toBe("$\\binom{50}{5}\\cdot 5^{40}$"); + expect(option.correct).toBe(false); }); + }); - describe("createIncorrectOption3", () => { - it("will return an option with the combination using the number of letters instead of positions", () => { - const generator = new Generator(); + describe("createIncorrectOption3", () => { + it("will return an option with the combination using the number of letters instead of positions", () => { + const generator = new Generator(); - const option = generator.createIncorrectOption3(50, 10); + const option = generator.createIncorrectOption3(50, 10); - expect(option.label).toBe("$\\binom{50}{5}\\cdot 4^{40}$"); - expect(option.correct).toBe(false); - }); + expect(option.label).toBe("$\\binom{50}{5}\\cdot 4^{40}$"); + expect(option.correct).toBe(false); }); + }); - describe("createIncorrectOption4", () => { - it("will return an option which does not use combinations", () => { - const generator = new Generator(); + describe("createIncorrectOption4", () => { + it("will return an option which does not use combinations", () => { + const generator = new Generator(); - const option = generator.createIncorrectOption4(50, 10); + const option = generator.createIncorrectOption4(50, 10); - expect(option.label).toBe("$5^{10}\\cdot 4^{40}$"); - expect(option.correct).toBe(false); - }); + expect(option.label).toBe("$5^{10}\\cdot 4^{40}$"); + expect(option.correct).toBe(false); }); -}); \ No newline at end of file + }); +}); diff --git a/src/content/questions/comp2804/2022-winter-final/1/generator.ts b/src/content/questions/comp2804/2022-winter-final/1/generator.ts index d28830a2..141c14f4 100644 --- a/src/content/questions/comp2804/2022-winter-final/1/generator.ts +++ b/src/content/questions/comp2804/2022-winter-final/1/generator.ts @@ -21,25 +21,40 @@ class Generator extends MultipleChoiceQuestionGenerator { return [stringLength, positions]; } - createOptions(stringLength: number, positions: number): MultipleChoiceQuestionOption[] { + createOptions( + stringLength: number, + positions: number, + ): MultipleChoiceQuestionOption[] { const correctOption = this.createCorrectOption(stringLength, positions); - const incorrectOption1 = this.createIncorrectOption1(stringLength, positions); - const incorrectOption2 = this.createIncorrectOption2(stringLength, positions); - const incorrectOption3 = this.createIncorrectOption3(stringLength, positions); - const incorrectOption4 = this.createIncorrectOption4(stringLength, positions); + const incorrectOption1 = this.createIncorrectOption1( + stringLength, + positions, + ); + const incorrectOption2 = this.createIncorrectOption2( + stringLength, + positions, + ); + const incorrectOption3 = this.createIncorrectOption3( + stringLength, + positions, + ); + const incorrectOption4 = this.createIncorrectOption4( + stringLength, + positions, + ); return this.shuffleOptions([ - correctOption, - incorrectOption1, - incorrectOption2, - incorrectOption3, - incorrectOption4 + correctOption, + incorrectOption1, + incorrectOption2, + incorrectOption3, + incorrectOption4, ]); } createCorrectOption( stringLength: number, - positions: number + positions: number, ): MultipleChoiceQuestionOption { return { label: `$\\binom{${stringLength}}{${positions}}\\cdot 4^{${stringLength - positions}}$`, @@ -49,7 +64,7 @@ class Generator extends MultipleChoiceQuestionGenerator { createIncorrectOption1( stringLength: number, - positions: number + positions: number, ): MultipleChoiceQuestionOption { return { label: `$\\binom{${stringLength}}{${positions}}\\cdot 5^{${stringLength - positions}}$`, @@ -59,7 +74,7 @@ class Generator extends MultipleChoiceQuestionGenerator { createIncorrectOption2( stringLength: number, - positions: number + positions: number, ): MultipleChoiceQuestionOption { return { label: `$\\binom{${stringLength}}{5}\\cdot 5^{${stringLength - positions}}$`, @@ -69,7 +84,7 @@ class Generator extends MultipleChoiceQuestionGenerator { createIncorrectOption3( stringLength: number, - positions: number + positions: number, ): MultipleChoiceQuestionOption { return { label: `$\\binom{${stringLength}}{5}\\cdot 4^{${stringLength - positions}}$`, @@ -79,15 +94,13 @@ class Generator extends MultipleChoiceQuestionGenerator { createIncorrectOption4( stringLength: number, - positions: number + positions: number, ): MultipleChoiceQuestionOption { return { label: `$5^{${positions}}\\cdot 4^{${stringLength - positions}}$`, correct: false, }; } //does not use combinations - - } -export default Generator; \ No newline at end of file +export default Generator;