Skip to content

Commit 0d42f88

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/Lesson_04' into Lesson_04
2 parents 8121612 + 5d1a93c commit 0d42f88

File tree

4 files changed

+132
-37
lines changed

4 files changed

+132
-37
lines changed

lesson_03/quiz/quiz.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ quiz:
3434
- $2y$10$FquR69q7W4E68TX/SNCB7u8Ri0DOFRDqsUPdGfuyIBjZJRVFkNI.6
3535
- $2y$10$FSWRA7hulVpyVxd8s67Nxuq/1cdmviW24qqoUbqihBf79cR.w9yly
3636
- $2y$10$Qy1IsNsfuJvA384ypL/72uWubUuNbMRp4LD6j/LM0RIH66D/HIjF6
37+
jeremiahwing:
38+
- $2y$10$YLN9gvb8/fBf3ByHNIdb9.UZ8ilcuCdPgZN9QIYd2rwD23vzt2lvy
39+
- $2y$10$AEUmg5pH8c2VLZ871//G4eKjwx5cnKH5c2HGTNXdnAPF.3/ZmNap2
40+
- $2y$10$bcTYSI0R/3x0pPHcGPAjautopYx2MD8mJPqf2nXKMJeteoIwJQrQm
41+
- $2y$10$V8pMtwgtZe725nPssrr8kejs4Evh/Vi3ia8RulylOQ8x2YV4tJ4LO
3742
jasonwatson:
3843
- $2y$10$AZtPKyQ.6Bzb.jreO/u.2O3C7XfvYAVpjHzLkuhLVdsX74wc4vXwS
3944
- $2y$10$QbKtEXqpeItigRLAHsn8Qe/06ZpXhKEP1bGPJSFXymsoFw9.04NHy
40-
- $2y$10$tJLScW1OZpOLpVllM65EI.W1QjkSIIBtz.KG8z/s.07RNb7ZWC0um
45+
- $2y$10$tJLScW1OZpOLpVllM65EI.W1QjkSIIBtz.KG8z/s.07RNb7ZWC0um

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,52 +80,57 @@ describe('Lesson3Test', () => {
8080
maybeIt(
8181
'checks multiple choice answers are configured correctly',
8282
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);
83+
const { providerName, questions } = getQuestionsFromCurrentProvider();
84+
for (const question of questions) {
85+
if (!(question instanceof MultipleChoiceQuizQuestion)) {
86+
continue;
10287
}
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);
103102
}
104103
},
105104
);
106105

107106
maybeIt('checks for correct answers', async () => {
107+
const { providerName, questions } = getQuestionsFromCurrentProvider();
108+
for (const question of questions) {
109+
const actualAnswer = question.getAnswer();
110+
softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED);
111+
softExpect(
112+
await quizConfig.checkAnswer(
113+
providerName,
114+
question.getQuestionNumber(),
115+
actualAnswer,
116+
),
117+
).toBe(true);
118+
}
119+
});
120+
121+
function getQuestionsFromCurrentProvider(): {
122+
providerName: string;
123+
questions: QuizQuestion[];
124+
} {
108125
const targetProviderName = process.env.PROVIDER_NAME?.trim() || '';
109126

110127
if (!quizQuestionsByProvider.has(targetProviderName)) {
111128
throw new Error(`Unknown provider name: ${targetProviderName}`);
112129
}
113130

114-
for (const [providerName, questions] of quizQuestionsByProvider) {
115-
if (providerName !== process.env.PROVIDER_NAME?.trim()) {
116-
continue;
117-
}
118-
for (const question of questions) {
119-
const actualAnswer = question.getAnswer();
120-
softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED);
121-
softExpect(
122-
await quizConfig.checkAnswer(
123-
providerName,
124-
question.getQuestionNumber(),
125-
actualAnswer,
126-
),
127-
).toBe(true);
128-
}
129-
}
130-
});
131+
return {
132+
providerName: targetProviderName,
133+
questions: quizQuestionsByProvider.get(targetProviderName) || [],
134+
};
135+
}
131136
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {
2+
AnswerChoice,
3+
MultipleChoiceQuizQuestion,
4+
QuizQuestion,
5+
QuizQuestionProvider,
6+
} from 'codedifferently-instructional';
7+
8+
export class JeremiahWingQuiz implements QuizQuestionProvider {
9+
getProviderName(): string {
10+
return 'jeremiahwing';
11+
}
12+
13+
makeQuizQuestions(): QuizQuestion[] {
14+
return [
15+
JeremiahWingQuiz.makeQuestion0(),
16+
JeremiahWingQuiz.makeQuestion1(),
17+
JeremiahWingQuiz.makeQuestion2(),
18+
JeremiahWingQuiz.makeQuestion3(),
19+
];
20+
}
21+
22+
private static makeQuestion0(): QuizQuestion {
23+
return new MultipleChoiceQuizQuestion(
24+
0,
25+
'What does the SRC element stand for?',
26+
new Map<AnswerChoice, string>([
27+
[AnswerChoice.A, 'Source'],
28+
[AnswerChoice.B, 'Script'],
29+
[AnswerChoice.C, 'Style'],
30+
[AnswerChoice.D, 'Section'],
31+
]),
32+
AnswerChoice.UNANSWERED,
33+
);
34+
}
35+
36+
private static makeQuestion1(): QuizQuestion {
37+
return new MultipleChoiceQuizQuestion(
38+
1,
39+
'What does the git fetch command do?',
40+
new Map<AnswerChoice, string>([
41+
[AnswerChoice.A, 'Downloads objects and refs from another repository'],
42+
[AnswerChoice.B, 'Merges changes from another branch'],
43+
[AnswerChoice.C, 'Commits changes to the local repository'],
44+
[AnswerChoice.D, 'Deletes a branch from the repository'],
45+
]),
46+
AnswerChoice.UNANSWERED,
47+
);
48+
}
49+
50+
private static makeQuestion2(): QuizQuestion {
51+
return new MultipleChoiceQuizQuestion(
52+
2,
53+
'What does the git pull command do?',
54+
new Map<AnswerChoice, string>([
55+
[
56+
AnswerChoice.A,
57+
'Fetches from and integrates with another repository or a local branch',
58+
],
59+
[AnswerChoice.B, 'Merges changes from another branch'],
60+
[AnswerChoice.C, 'Commits changes to the local repository'],
61+
[AnswerChoice.D, 'Deletes a branch from the repository'],
62+
]),
63+
AnswerChoice.UNANSWERED,
64+
);
65+
}
66+
67+
private static makeQuestion3(): QuizQuestion {
68+
return new MultipleChoiceQuizQuestion(
69+
3,
70+
'What does the git push command do?',
71+
new Map<AnswerChoice, string>([
72+
[
73+
AnswerChoice.A,
74+
'Uploads local repository content to a remote repository',
75+
],
76+
[AnswerChoice.B, 'Merges changes from another branch'],
77+
[AnswerChoice.C, 'Commits changes to the local repository'],
78+
[AnswerChoice.D, 'Downloads objects and refs from another repository'],
79+
]),
80+
AnswerChoice.UNANSWERED,
81+
);
82+
}
83+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Jbeyquiz } from './jbeyquiz.js';
99
import { KhaylaSaundersQuiz } from './khayla_quiz.js';
1010
import { MercedesMathewsQuiz } from './mercedes_mathews_quiz.js';
1111
import { RasheedMillerQuiz } from './rasheed_miller_quiz.js';
12+
import { JeremiahWingQuiz } from './jeremiah_wing_quiz.js';
1213

1314
export const Quizzes = Symbol.for('Quizzes');
1415

@@ -24,6 +25,7 @@ const QUIZ_PROVIDERS = [
2425
DavidAdenaikeQuiz,
2526
KhaylaSaundersQuiz,
2627
RasheedMillerQuiz,
28+
JeremiahWingQuiz,
2729
JasonWatsonQuiz,
2830
];
2931

0 commit comments

Comments
 (0)