Skip to content

Commit 4bdaca5

Browse files
author
Ezra Nyabuti
committed
updated my merge
2 parents 303b855 + d7940e1 commit 4bdaca5

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

lesson_03/quiz/quiz.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ quiz:
1010
- $2y$10$fisFjMsmMwzlj3.PELyBNeupdruYROU00dwq296pg0VfHo05SSkta
1111
- $2y$10$.Z44VoTaxQSdPEx7RatO6OVCw1ff6ohS0kZnCrHEcFnElIgkfjP0u
1212
- $2y$10$nCm/E52FKO7DRo4XbpR2vu.HTyAzsDNNZr2dDfYJyblY1oLuGpnPO
13+
14+
meikostephens:
15+
- $2y$10$AD1YHmrZZivus7DoM91UMuErNnpi63ueluFs7DcSQSrZbXwDycAOi
16+
- $2y$10$KvnxAYKh3A151RyOOFtOv.wfImRzZMgbBgKy3gyLd1uUSSjHaN.4u
17+
- $2y$10$qJDpo1X1kFXRD1M6Kpi8WeKg.a8dgzd8RawXX/3RuMqM82biBc6iK
1318
computerparts:
1419
- $2y$10$7TUXmYaJlWnRZTzYR..CsefgVcOZJMGt7ctxyAf.G3obBBFEAB342
1520
- $2y$10$0ghuTDegle177q8VjCgQ2OhManKjotYXrcDT3SLyUF8KvI152Wd0.

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeAll, describe, expect, it } from '@jest/globals';
33
import { Test, TestingModule } from '@nestjs/testing';
44
import {
55
AnswerChoice,
6+
MultipleChoiceQuizQuestion,
67
QuizConfig,
78
QuizQuestion,
89
} from 'codedifferently-instructional';
@@ -76,16 +77,42 @@ describe('Lesson3Test', () => {
7677

7778
const maybeIt = process.env.PROVIDER_NAME ? it : it.skip;
7879

80+
maybeIt(
81+
'checks multiple choice answers are configured correctly',
82+
async () => {
83+
for (const [providerName, questions] of quizQuestionsByProvider) {
84+
for (const question of questions) {
85+
if (!(question instanceof MultipleChoiceQuizQuestion)) {
86+
continue;
87+
}
88+
89+
// Assert that multiple choice questions have at least one correct answer.
90+
const choices = question.getAnswerChoices();
91+
const areAnswersValid = await Promise.all(
92+
[...choices].map(async (choice) => {
93+
return quizConfig.checkAnswer(
94+
providerName,
95+
question.getQuestionNumber(),
96+
choice,
97+
);
98+
}),
99+
);
100+
101+
expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true);
102+
}
103+
}
104+
},
105+
);
106+
79107
maybeIt('checks for correct answers', async () => {
80-
const targetProviderName =
81-
process.env.PROVIDER_NAME?.toLowerCase().trim() || '';
108+
const targetProviderName = process.env.PROVIDER_NAME?.trim() || '';
82109

83110
if (!quizQuestionsByProvider.has(targetProviderName)) {
84111
throw new Error(`Unknown provider name: ${targetProviderName}`);
85112
}
86113

87114
for (const [providerName, questions] of quizQuestionsByProvider) {
88-
if (providerName !== process.env.PROVIDER_NAME?.toLowerCase().trim()) {
115+
if (providerName !== process.env.PROVIDER_NAME?.trim()) {
89116
continue;
90117
}
91118
for (const question of questions) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
AnswerChoice,
3+
MultipleChoiceQuizQuestion,
4+
QuizQuestion,
5+
QuizQuestionProvider,
6+
} from 'codedifferently-instructional';
7+
8+
export class MeikoStephensQuiz implements QuizQuestionProvider {
9+
getProviderName(): string {
10+
return 'meikostephens';
11+
}
12+
13+
makeQuizQuestions(): QuizQuestion[] {
14+
return [
15+
MeikoStephensQuiz.makeQuestion0(),
16+
MeikoStephensQuiz.makeQuestion1(),
17+
MeikoStephensQuiz.makeQuestion2(),
18+
];
19+
}
20+
21+
private static makeQuestion0(): QuizQuestion {
22+
return new MultipleChoiceQuizQuestion(
23+
0,
24+
'What is a branch?',
25+
new Map<AnswerChoice, string>([
26+
[AnswerChoice.A, 'A new line of code'],
27+
[
28+
AnswerChoice.B,
29+
'A copy of a repository that allows you make changes and merge them later',
30+
],
31+
[AnswerChoice.C, 'A way to delete a respository and start over'],
32+
[AnswerChoice.D, 'A way to run code'],
33+
]),
34+
AnswerChoice.UNANSWERED,
35+
); // Replace `UNANSWERED` with the correct answer.
36+
}
37+
38+
private static makeQuestion1(): QuizQuestion {
39+
return new MultipleChoiceQuizQuestion(
40+
1,
41+
'What does a syncfork do?',
42+
new Map<AnswerChoice, string>([
43+
[AnswerChoice.A, 'Updates changes from the original repository'],
44+
[AnswerChoice.B, 'Deletes the repositiory'],
45+
[AnswerChoice.C, 'Transforms the repository into a branch'],
46+
[AnswerChoice.D, 'Runs the code more efficiently'],
47+
]),
48+
AnswerChoice.UNANSWERED,
49+
); // Replace `UNANSWERED` with the correct answer.
50+
}
51+
52+
private static makeQuestion2(): QuizQuestion {
53+
return new MultipleChoiceQuizQuestion(
54+
2,
55+
'What brings the modify changes to merge into the main repositiory?',
56+
new Map<AnswerChoice, string>([
57+
[AnswerChoice.A, 'A terminal'],
58+
[AnswerChoice.B, 'A branch'],
59+
[AnswerChoice.C, 'A syncfork'],
60+
[AnswerChoice.D, 'A pull request'],
61+
]),
62+
AnswerChoice.UNANSWERED,
63+
); // Replace `UNANSWERED` with the correct answer.
64+
}
65+
}

lesson_03/quiz/src/quizzes/quizzes.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AnthonyMaysQuiz } from './anthony_mays_quiz.js';
44
import { DavidAdenaikeQuiz } from './david_adenaike_quiz.js';
55
import { EzraQuiz } from './ezra_quiz.js';
66
import { Jbeyquiz } from './jbeyquiz.js';
7+
import { MeikoStephensQuiz } from './meiko_stephens_quiz.js';
78
import { MercedesMathewsQuiz } from './mercedes_mathews_quiz.js';
89
import { RasheedMillerQuiz } from './rasheed_miller_quiz.js';
910

@@ -14,6 +15,7 @@ export const Quizzes = Symbol.for('Quizzes');
1415
const QUIZ_PROVIDERS = [
1516
AnthonyMaysQuiz,
1617
AnotherQuiz,
18+
MeikoStephensQuiz,
1719
MercedesMathewsQuiz,
1820
Jbeyquiz,
1921
EzraQuiz,

0 commit comments

Comments
 (0)