|
| 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 | +}); |
0 commit comments