Skip to content

Commit bca25e2

Browse files
authored
add 2022 winter final question 1 generator (#32)
* add 2022 winter final question 1 generator * linting
1 parent 1cd907a commit bca25e2

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { describe, expect } from "@jest/globals";
2+
import Generator from "./generator";
3+
4+
describe("comp2804/2022-winter-final/1", () => {
5+
describe("generateValues", () => {
6+
it("will return two values", () => {
7+
const generator = new Generator();
8+
9+
const values = generator.generateValues();
10+
11+
expect(values).toHaveLength(2);
12+
});
13+
14+
it("will return a string length between 50 and 100", () => {
15+
const generator = new Generator();
16+
17+
const [stringLength, _] = generator.generateValues();
18+
19+
expect(stringLength).toBeGreaterThanOrEqual(50);
20+
expect(stringLength).toBeLessThanOrEqual(100);
21+
});
22+
23+
it("will return a positions value between 5 and 20", () => {
24+
const generator = new Generator();
25+
26+
const [_, positions] = generator.generateValues();
27+
28+
expect(positions).toBeGreaterThanOrEqual(5);
29+
expect(positions).toBeLessThanOrEqual(20);
30+
});
31+
});
32+
33+
describe("createOptions", () => {
34+
it("will return five options", () => {
35+
const generator = new Generator();
36+
37+
const options = generator.createOptions(50, 5);
38+
39+
expect(options).toHaveLength(5);
40+
});
41+
42+
it("will have exactly one correct option", () => {
43+
const generator = new Generator();
44+
45+
const options = generator.createOptions(50, 5);
46+
const correctOptions = options.filter((option) => option.correct);
47+
48+
expect(correctOptions).toHaveLength(1);
49+
});
50+
});
51+
52+
describe("createCorrectOption", () => {
53+
it("will return the correct option", () => {
54+
const generator = new Generator();
55+
56+
const option = generator.createCorrectOption(50, 10);
57+
58+
expect(option.label).toBe("$\\binom{50}{10}\\cdot 4^{40}$");
59+
expect(option.correct).toBe(true);
60+
});
61+
});
62+
63+
describe("createIncorrectOption1", () => {
64+
it("will return an option with the combination being multiplied with 5 ^ value instead of 4 ^ value", () => {
65+
const generator = new Generator();
66+
67+
const option = generator.createIncorrectOption1(50, 10);
68+
69+
expect(option.label).toBe("$\\binom{50}{10}\\cdot 5^{40}$");
70+
expect(option.correct).toBe(false);
71+
});
72+
});
73+
74+
describe("createIncorrectOption2", () => {
75+
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", () => {
76+
const generator = new Generator();
77+
78+
const option = generator.createIncorrectOption2(50, 10);
79+
80+
expect(option.label).toBe("$\\binom{50}{5}\\cdot 5^{40}$");
81+
expect(option.correct).toBe(false);
82+
});
83+
});
84+
85+
describe("createIncorrectOption3", () => {
86+
it("will return an option with the combination using the number of letters instead of positions", () => {
87+
const generator = new Generator();
88+
89+
const option = generator.createIncorrectOption3(50, 10);
90+
91+
expect(option.label).toBe("$\\binom{50}{5}\\cdot 4^{40}$");
92+
expect(option.correct).toBe(false);
93+
});
94+
});
95+
96+
describe("createIncorrectOption4", () => {
97+
it("will return an option which does not use combinations", () => {
98+
const generator = new Generator();
99+
100+
const option = generator.createIncorrectOption4(50, 10);
101+
102+
expect(option.label).toBe("$5^{10}\\cdot 4^{40}$");
103+
expect(option.correct).toBe(false);
104+
});
105+
});
106+
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { MultipleChoiceQuestionGenerator } from "@common/MultipleChoiceQuestionGenerator";
2+
import type {
3+
MultipleChoiceQuestion,
4+
MultipleChoiceQuestionOption,
5+
} from "@common/MultipleChoiceQuestionGenerator";
6+
7+
class Generator extends MultipleChoiceQuestionGenerator {
8+
generateQuestion(): MultipleChoiceQuestion {
9+
const [stringLength, positions] = this.generateValues();
10+
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$?`;
11+
return {
12+
body: dynamicQuestionBody,
13+
options: this.createOptions(stringLength, positions),
14+
};
15+
}
16+
17+
generateValues(): [number, number] {
18+
const stringLength = Math.floor(Math.random() * 51) + 50; //generate a value between 50 and 100
19+
const positions = Math.floor(Math.random() * 16) + 5; //generate a value between 5 and 20
20+
21+
return [stringLength, positions];
22+
}
23+
24+
createOptions(
25+
stringLength: number,
26+
positions: number,
27+
): MultipleChoiceQuestionOption[] {
28+
const correctOption = this.createCorrectOption(stringLength, positions);
29+
const incorrectOption1 = this.createIncorrectOption1(
30+
stringLength,
31+
positions,
32+
);
33+
const incorrectOption2 = this.createIncorrectOption2(
34+
stringLength,
35+
positions,
36+
);
37+
const incorrectOption3 = this.createIncorrectOption3(
38+
stringLength,
39+
positions,
40+
);
41+
const incorrectOption4 = this.createIncorrectOption4(
42+
stringLength,
43+
positions,
44+
);
45+
46+
return this.shuffleOptions([
47+
correctOption,
48+
incorrectOption1,
49+
incorrectOption2,
50+
incorrectOption3,
51+
incorrectOption4,
52+
]);
53+
}
54+
55+
createCorrectOption(
56+
stringLength: number,
57+
positions: number,
58+
): MultipleChoiceQuestionOption {
59+
return {
60+
label: `$\\binom{${stringLength}}{${positions}}\\cdot 4^{${stringLength - positions}}$`,
61+
correct: true,
62+
};
63+
}
64+
65+
createIncorrectOption1(
66+
stringLength: number,
67+
positions: number,
68+
): MultipleChoiceQuestionOption {
69+
return {
70+
label: `$\\binom{${stringLength}}{${positions}}\\cdot 5^{${stringLength - positions}}$`,
71+
correct: false,
72+
};
73+
} //mutliples with 5 ^ value instead of 4
74+
75+
createIncorrectOption2(
76+
stringLength: number,
77+
positions: number,
78+
): MultipleChoiceQuestionOption {
79+
return {
80+
label: `$\\binom{${stringLength}}{5}\\cdot 5^{${stringLength - positions}}$`,
81+
correct: false,
82+
};
83+
} //uses number of letters instead of positions and multiples with 5 ^ value instead of 4
84+
85+
createIncorrectOption3(
86+
stringLength: number,
87+
positions: number,
88+
): MultipleChoiceQuestionOption {
89+
return {
90+
label: `$\\binom{${stringLength}}{5}\\cdot 4^{${stringLength - positions}}$`,
91+
correct: false,
92+
};
93+
} //uses number of letters instead of positions
94+
95+
createIncorrectOption4(
96+
stringLength: number,
97+
positions: number,
98+
): MultipleChoiceQuestionOption {
99+
return {
100+
label: `$5^{${positions}}\\cdot 4^{${stringLength - positions}}$`,
101+
correct: false,
102+
};
103+
} //does not use combinations
104+
}
105+
106+
export default Generator;

src/content/questions/comp2804/2022-winter-final/1/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type: multiple-choice
55
author: Michiel Smid
66
question: comp2804/2022-winter-final/1/question.ts
77
solution: comp2804/2022-winter-final/1/solution.md
8+
generator: comp2804/2022-winter-final/1/generator.ts
89
tags:
910
- comp2804
1011
- comp2804-final

0 commit comments

Comments
 (0)