1+ import { createEmptyCard } from 'ts-fsrs' ;
2+ import { FlashlyCard , createFlashlyCard } from '../src/models/card' ;
3+ import { QuizConfig , QuizQuestion , checkAnswer } from '../src/models/quiz' ;
4+ import { TraditionalQuizGenerator } from '../src/quiz/traditional-quiz-generator' ;
5+
6+ describe ( 'Match quiz support' , ( ) => {
7+ it ( 'generates a match question when enabled' , ( ) => {
8+ const generator = new TraditionalQuizGenerator ( ) ;
9+ const cards : FlashlyCard [ ] = [
10+ createFlashlyCard ( 'Term 1' , 'Definition 1' , 'test1.md' , 1 , createEmptyCard ( new Date ( ) ) ) ,
11+ createFlashlyCard ( 'Term 2' , 'Definition 2' , 'test2.md' , 2 , createEmptyCard ( new Date ( ) ) ) ,
12+ createFlashlyCard ( 'Term 3' , 'Definition 3' , 'test3.md' , 3 , createEmptyCard ( new Date ( ) ) ) ,
13+ createFlashlyCard ( 'Term 4' , 'Definition 4' , 'test4.md' , 4 , createEmptyCard ( new Date ( ) ) )
14+ ] ;
15+
16+ const config : QuizConfig = {
17+ questionCount : 1 ,
18+ includeMultipleChoice : false ,
19+ includeFillBlank : false ,
20+ includeTrueFalse : false ,
21+ includeMatch : true ,
22+ useAI : false
23+ } ;
24+
25+ const questions = generator . generateQuestions ( cards , config ) ;
26+
27+ expect ( questions ) . toHaveLength ( 1 ) ;
28+ expect ( questions [ 0 ] . type ) . toBe ( 'match' ) ;
29+ expect ( Array . isArray ( questions [ 0 ] . correctAnswer ) ) . toBe ( true ) ;
30+ if ( Array . isArray ( questions [ 0 ] . correctAnswer ) ) {
31+ expect ( questions [ 0 ] . correctAnswer ) . toHaveLength ( 4 ) ;
32+ expect ( questions [ 0 ] . correctAnswer [ 0 ] ) . toHaveProperty ( 'left' ) ;
33+ expect ( questions [ 0 ] . correctAnswer [ 0 ] ) . toHaveProperty ( 'right' ) ;
34+ }
35+ } ) ;
36+
37+ it ( 'scores match answers independent of order' , ( ) => {
38+ const question : QuizQuestion = {
39+ id : 'q-match' ,
40+ type : 'match' ,
41+ prompt : 'Match pairs' ,
42+ correctAnswer : [
43+ { left : 'A' , right : '1' } ,
44+ { left : 'B' , right : '2' }
45+ ]
46+ } ;
47+
48+ expect ( checkAnswer ( question , [
49+ { left : 'B' , right : '2' } ,
50+ { left : 'A' , right : '1' }
51+ ] ) ) . toBe ( true ) ;
52+
53+ expect ( checkAnswer ( question , [
54+ { left : 'A' , right : '1' } ,
55+ { left : 'B' , right : '3' }
56+ ] ) ) . toBe ( false ) ;
57+ } ) ;
58+ } ) ;
0 commit comments