@@ -7,6 +7,7 @@ const { executeSparqlQuery } = require('./generatorLogic/SparqlQuery')
7
7
const { bindCapitalsResults } = require ( './generatorLogic/BindResults' )
8
8
const { createMathQuestions, generateRandomMathQuestion } = require ( './generatorLogic/MathQuestions' )
9
9
const axios = require ( 'axios' ) ;
10
+ const uuid = require ( 'uuid' ) ;
10
11
11
12
let app ;
12
13
let mongoServer ;
@@ -178,4 +179,56 @@ it('should handle empty query result', () => {
178
179
expect ( capitalsMap . size ) . toBe ( 0 ) ;
179
180
} ) ;
180
181
182
+ it ( 'should generate a math question with valid operands and operator' , ( ) => {
183
+
184
+ const mathQuestion = generateRandomMathQuestion ( ) ;
185
+
186
+ expect ( mathQuestion ) . toHaveProperty ( 'uuid' ) ;
187
+ expect ( mathQuestion ) . toHaveProperty ( 'question' ) ;
188
+ expect ( mathQuestion ) . toHaveProperty ( 'correctAnswer' ) ;
189
+ expect ( mathQuestion ) . toHaveProperty ( 'incorrectAnswer1' ) ;
190
+ expect ( mathQuestion ) . toHaveProperty ( 'incorrectAnswer2' ) ;
191
+ expect ( mathQuestion ) . toHaveProperty ( 'incorrectAnswer3' ) ;
192
+
193
+ const [ operand1 , operator , operand2 ] = mathQuestion . question . split ( ' ' ) ;
194
+
195
+ expect ( parseInt ( operand1 ) ) . toBeGreaterThanOrEqual ( 1 ) ;
196
+ expect ( parseInt ( operand1 ) ) . toBeLessThanOrEqual ( 100 ) ;
197
+ expect ( parseInt ( operand2 ) ) . toBeGreaterThanOrEqual ( 1 ) ;
198
+ expect ( parseInt ( operand2 ) ) . toBeLessThanOrEqual ( 100 ) ;
199
+
200
+ expect ( [ '+' , '-' , '*' , '/' ] ) . toContain ( operator ) ;
201
+
202
+ const correctAnswer = eval ( mathQuestion . question ) ;
203
+ expect ( mathQuestion . correctAnswer ) . toEqual ( correctAnswer . toString ( ) ) ;
204
+
205
+ expect ( mathQuestion . incorrectAnswer1 ) . not . toEqual ( correctAnswer . toString ( ) ) ;
206
+ expect ( mathQuestion . incorrectAnswer2 ) . not . toEqual ( correctAnswer . toString ( ) ) ;
207
+ expect ( mathQuestion . incorrectAnswer3 ) . not . toEqual ( correctAnswer . toString ( ) ) ;
208
+ } ) ;
209
+
210
+ it ( 'should create math questions and return them' , async ( ) => {
211
+ const numberOfQuestions = 3 ;
212
+
213
+ const result = await createMathQuestions ( numberOfQuestions ) ;
214
+
215
+ expect ( Array . isArray ( result ) ) . toBe ( true ) ;
216
+ expect ( result . length ) . toBe ( 3 ) ;
217
+
218
+ result . forEach ( ( question ) => {
219
+ expect ( question ) . toHaveProperty ( 'correctAnswer' ) ;
220
+ expect ( question ) . toHaveProperty ( 'incorrectAnswer1' ) ;
221
+ expect ( question ) . toHaveProperty ( 'incorrectAnswer2' ) ;
222
+ expect ( question ) . toHaveProperty ( 'incorrectAnswer3' ) ;
223
+ expect ( question ) . toHaveProperty ( 'question' ) ;
224
+ expect ( question ) . toHaveProperty ( 'uuid' ) ;
225
+ expect ( typeof question . correctAnswer ) . toBe ( 'string' ) ;
226
+ expect ( typeof question . incorrectAnswer1 ) . toBe ( 'string' ) ;
227
+ expect ( typeof question . incorrectAnswer2 ) . toBe ( 'string' ) ;
228
+ expect ( typeof question . incorrectAnswer3 ) . toBe ( 'string' ) ;
229
+ expect ( typeof question . question ) . toBe ( 'string' ) ;
230
+ expect ( typeof question . uuid ) . toBe ( 'string' ) ;
231
+ } ) ;
232
+ } ) ;
233
+
181
234
} )
0 commit comments