1 | import test from 'ava';
|
2 | import { getConfig } from '../config';
|
3 | import checkAnswer from '../check-answer';
|
4 | import checkAnswerCorrectness from '../check-answer-correctness';
|
5 | const config = getConfig({
|
6 | ref: 'microlearning',
|
7 | version: 'latest'
|
8 | });
|
9 |
|
10 | function checkBothMethods(t, expected, question, givenAnswer) {
|
11 | t.is(checkAnswerCorrectness(config, question, givenAnswer).isCorrect, expected);
|
12 | t.is(checkAnswer(config, question, givenAnswer), expected);
|
13 | }
|
14 |
|
15 | test("should return the value of `isCorrect` in checkAnswerCorrectness's result (basic)", t => {
|
16 | const question = {
|
17 | type: 'basic',
|
18 | content: {
|
19 | answers: [['guillaume tell'], ['tell'], ['guillaume'], ['tel']],
|
20 | maxTypos: undefined
|
21 | }
|
22 | };
|
23 | checkBothMethods(t, true, question, ['guillaume tell']);
|
24 | checkBothMethods(t, true, question, ['guillaume']);
|
25 | checkBothMethods(t, true, question, ['tell']);
|
26 | checkBothMethods(t, true, question, ['GUILLaume']);
|
27 | checkBothMethods(t, true, question, ['guillaume']);
|
28 | checkBothMethods(t, false, question, ['guilluaem']);
|
29 | checkBothMethods(t, true, question, ['XXXXguillaumeXXXX']);
|
30 | checkBothMethods(t, true, question, ['XXXXguILLAumeXXXX']);
|
31 | checkBothMethods(t, false, question, ['XXXXXXguillaume']);
|
32 | checkBothMethods(t, false, question, ['guillaumeXXXXXX']);
|
33 | });
|
34 | test("should return the value of `isCorrect` in checkAnswerCorrectness's result (qcm)", t => {
|
35 | const question = {
|
36 | type: 'qcm',
|
37 | content: {
|
38 | choices: [],
|
39 | answers: [['answer1', 'answer3'], ['answer2', 'answer4'], ['answer1', 'answer4']]
|
40 | }
|
41 | };
|
42 | checkBothMethods(t, true, question, ['answer1', 'answer3']);
|
43 | checkBothMethods(t, true, question, ['answer2', 'answer4']);
|
44 | checkBothMethods(t, true, question, ['answer1', 'answer4']);
|
45 | checkBothMethods(t, true, question, ['answer4', 'answer1']);
|
46 | checkBothMethods(t, false, question, ['answer1', 'answer2']);
|
47 | });
|
48 | test("should return the value of `isCorrect` in checkAnswerCorrectness's result (qcmDrag, matchOrder=true)", t => {
|
49 | const question = {
|
50 | type: 'qcmDrag',
|
51 | content: {
|
52 | matchOrder: true,
|
53 | answers: [['answer1', 'answer3'], ['answer2', 'answer4'], ['answer1', 'answer4']]
|
54 | }
|
55 | };
|
56 | checkBothMethods(t, true, question, ['answer1', 'answer3']);
|
57 | checkBothMethods(t, true, question, ['answer2', 'answer4']);
|
58 | checkBothMethods(t, true, question, ['answer1', 'answer4']);
|
59 | checkBothMethods(t, false, question, ['answer4', 'answer1']);
|
60 | checkBothMethods(t, false, question, ['answer1', 'answer2']);
|
61 | });
|
62 | test("should return the value of `isCorrect` in checkAnswerCorrectness's result (qcmDrag, matchOrder=false)", t => {
|
63 | const question = {
|
64 | type: 'qcmDrag',
|
65 | content: {
|
66 | matchOrder: false,
|
67 | answers: [['answer1', 'answer3'], ['answer2', 'answer4'], ['answer1', 'answer4']]
|
68 | }
|
69 | };
|
70 | checkBothMethods(t, true, question, ['answer1', 'answer3']);
|
71 | checkBothMethods(t, true, question, ['answer2', 'answer4']);
|
72 | checkBothMethods(t, true, question, ['answer1', 'answer4']);
|
73 | checkBothMethods(t, true, question, ['answer4', 'answer1']);
|
74 | checkBothMethods(t, false, question, ['answer1', 'answer2']);
|
75 | });
|
76 | test("should return the value of `isCorrect` in checkAnswerCorrectness's result (slider)", t => {
|
77 | const question = {
|
78 | type: 'slider',
|
79 | content: {
|
80 | matchOrder: false,
|
81 | answers: [['100'], ['200'], ['300']]
|
82 | }
|
83 | };
|
84 | checkBothMethods(t, true, question, ['100']);
|
85 | checkBothMethods(t, true, question, ['200']);
|
86 | checkBothMethods(t, true, question, ['300']);
|
87 | checkBothMethods(t, false, question, ['400']);
|
88 | checkBothMethods(t, false, question, ['101']);
|
89 | checkBothMethods(t, false, question, ['foo']);
|
90 | });
|
91 | test('should return true when the question has an unknown type', t => {
|
92 | const question = {
|
93 | type: 'unknown',
|
94 | content: {
|
95 | answers: []
|
96 | }
|
97 | };
|
98 |
|
99 | checkBothMethods(t, true, question, []);
|
100 | });
|
101 |
|
\ | No newline at end of file |