This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
morji.test
800 lines (738 loc) · 30.1 KB
/
morji.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
# vim:ft=tcl
namespace eval morji {
variable TEST 1
namespace eval test {}
}
source -encoding utf-8 morji.tcl
package require tcltest
namespace import ::tcltest::*
############################# Tests #############################################
namespace eval morji::test {
test before_init {namespace variables} {
return $morji::markup::CLOZE
} -result 0
test tables {normal init} -setup {
morji::init_state
} -body {
foreach table {cards tags fact_tags facts} {
set ret [db eval {SELECT name FROM sqlite_master WHERE type='table' AND name=$table}]
if {$ret eq ""} {
return "table $table does not exist"
}
}
return ok
} -cleanup {
db close
} -result ok
test add_oneside_fact {add oneside fact} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes oneside mytag]
foreach tag {mytag all} {
if {![db exists {SELECT 1 FROM tags WHERE name=$tag}]} {
return "tag not found: $tag"
}
}
if {![db exists {SELECT 1 FROM cards WHERE fact_uid=$uid}]} {
return "no card"
}
db eval {SELECT * FROM cards WHERE fact_uid=$uid} {
foreach {field value} [list last_rep {} next_rep {} easiness 2.5 reps 0 fact_data {}] {
if {[set $field] ne $value} {
return "bad $field: [set $field] (expected $value)"
}
}
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
foreach field {question answer notes} {
if {[set $field] ne $field} {
return "bad $field: [set $field]"
}
}
if {$type ne "oneside"} {
return "bad type: $type"
}
}
return ok
} -cleanup {
db close
} -result ok
test add_twoside_fact {add twoside fact} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes twoside mytag]
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 2} {
return "incorrect number of cards: $count (expected 2)"
}
set data R
db eval {SELECT * FROM cards WHERE fact_uid=$uid} {
foreach {field value} [list last_rep {} next_rep {} easiness 2.5 reps 0 fact_data $data] {
if {[set $field] ne $value} {
return "bad $field: [set $field] (expected $value)"
}
}
set data P
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
if {$type ne "twoside"} {
return "bad type: $type"
}
}
return ok
} -cleanup {
db close
} -result ok
test add_cloze_fact {add cloze fact} -setup {
morji::init_state
} -body {
set uid [morji::add_fact {[cloze a b] and [cloze c d] and [cloze e f]} {} notes cloze mytag]
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 3} {
return "incorrect number of cards: $count (expected 2)"
}
set data {{0 a b} {1 c d} {2 e f}}
set i 0
db eval {SELECT * FROM cards WHERE fact_uid=$uid} {
foreach {field value} [list last_rep {} next_rep {} easiness 2.5 reps 0 fact_data [lindex $data $i]] {
if {[set $field] ne $value} {
return "bad $field: [set $field] (expected $value)"
}
}
incr i
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
if {$type ne "cloze"} {
return "bad type: $type"
}
}
return ok
} -cleanup {
db close
} -result ok
test update_oneside_fact-1 {update oneside fact} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes oneside mytag]
morji::update_fact $uid question_updated answer_updated notes_updated oneside {mytag newtag}
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 1} {
return "bad count: $count"
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
foreach field {question answer notes} {
if {[set $field] ne "${field}_updated"} {
return "bad $field: [set $field] (expected ${field}_updated)"
}
}
if {$type ne "oneside"} {
return "bad type: $type (expected oneside)";
}
}
return ok
} -cleanup {
db close
} -result ok
test update_oneside_fact-2 {update one side fact (type changed to twoside)} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes oneside mytag]
morji::update_fact $uid question_updated answer_updated notes_updated twoside {mytag newtag}
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 2} {
return "bad count: $count"
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
if {$type ne "twoside"} {
return "bad type: $type (expected twoside)";
}
}
set data R
db eval {SELECT * FROM cards WHERE fact_uid=$uid} {
if {$fact_data ne $data} {
return "bad fact_data: $fact_data (expected $data)"
}
set data P
}
return ok
} -cleanup {
db close
} -result ok
test update_twoside_fact-1 {update twoside fact} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes twoside mytag]
morji::update_fact $uid question_updated answer_updated notes_updated twoside {mytag newtag}
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 2} {
return "bad count: $count"
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
foreach field {question answer notes} {
if {[set $field] ne "${field}_updated"} {
return "bad $field: [set $field] (expected ${field}_updated)"
}
}
if {$type ne "twoside"} {
return "bad type: $type (expected twoside)";
}
}
return ok
} -cleanup {
db close
} -result ok
test update_twoside_fact-2 {update twoside fact (change type to oneside)} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes twoside mytag]
morji::update_fact $uid question_updated answer_updated notes_updated oneside {mytag newtag}
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$uid}]
if {$count != 1} {
return "bad count: $count"
}
db eval {SELECT * FROM facts WHERE uid=$uid} {
foreach field {question answer notes} {
if {[set $field] ne "${field}_updated"} {
return "bad $field: [set $field] (expected ${field}_updated)"
}
}
if {$type ne "oneside"} {
return "bad type: $type (expected oneside)";
}
}
db eval {SELECT fact_data FROM cards WHERE fact_uid=$uid} {
if {$fact_data ne ""} {
return "bad fact_data: $fact_data"
}
}
return ok
} -cleanup {
db close
} -result ok
test update_tags {update tags} -setup {
morji::init_state
} -body {
set uid [morji::add_fact question answer notes oneside mytag]
proc new_tags {uid tags expected} {
morji::update_fact $uid question answer notes oneside $tags
set tags [db eval {SELECT name FROM tags, fact_tags WHERE tags.uid = fact_tags.tag_uid AND fact_tags.fact_uid=$uid}]
set tags [lsort $tags]
if {$tags ne $expected} {
return "bad tags: $tags (expected: $expected)"
}
set tags_all [lsort [db eval {SELECT name FROM tags}]]
if {$tags ne $tags_all} {
return "orphaned tags: $tags_all should be $tags"
}
return ok
}
foreach {tags expected} {
{mytag newtag} {all mytag newtag}
{mytag} {all mytag}
{mytag all all} {all mytag}
{mytag mytag} {all mytag}
{} {all}
{newtag othertag othertag} {all newtag othertag}
} {
set ret [new_tags $uid $tags $expected]
if {$ret ne "ok"} {
return $ret
}
}
return ok
} -cleanup {
db close
} -result ok -returnCodes 2
test update_cloze_fact-1 {update cloze fact} -setup {
morji::init_state
} -body {
set test_uid [morji::add_fact {[cloze a b], [cloze c d], [cloze e f]} {} notes cloze mytag]
proc test_update_cloze {test_uid clozes expected} {
morji::update_fact $test_uid $clozes {} notes cloze mytag
set count [db eval {SELECT count(*) FROM cards WHERE fact_uid=$test_uid}]
#puts "cards: [db eval {SELECT uid, fact_data FROM cards WHERE fact_uid=$test_uid}]"
if {$count != [llength $expected]} {
return "bad count: $count (expected [llength $expected])"
}
set i 0
db eval {SELECT * FROM facts WHERE uid=$test_uid} {
if {$type ne "cloze"} {
return "bad type: $type (expected cloze)";
}
set data $expected
db eval {SELECT * FROM cards WHERE fact_uid=$test_uid} {
foreach {field value} [list last_rep {} next_rep {} easiness 2.5 reps 0] {
if {[set $field] ne $value} {
return "bad $field for card $uid: [set $field] (expected $value)"
}
}
set found [lsearch -exact [lmap cloze $expected {lindex $cloze 0}] [lindex $fact_data 0]]
set expected_fact_data [lrange [lindex $expected $found] 1 2]
if {[lrange $fact_data 1 2] ne $expected_fact_data} {
return "bad fact_data for card $uid: $fact_data (expected $expected_fact_data)"
}
}
}
return ok
}
foreach {clozes expected} {
{[cloze a b], [cloze cc d], [cloze e f]} {{0 a b} {1 cc d} {2 e f}}
{[cloze a b], [cloze cc d]} {{0 a b} {1 cc d}}
{[cloze a b], [cloze ee f], [cloze cc d]} {{0 a b} {1 ee f} {2 cc d}}
{[cloze a b], [cloze ee f], [cloze cc d], [cloze xx y], [cloze zz y]} {{0 a b} {1 ee f} {2 cc d} {3 xx y} {4 zz y}}
{[cloze a b]} {{0 a b}}
{[cloze a b], [cloze c d]} {{0 a b} {1 c d}}
{[cloze c d], [cloze a b]} {{0 c d} {1 a b}}
} {
set ret [test_update_cloze $test_uid $clozes $expected]
if {$ret ne "ok"} {
return "$ret for {$clozes} and expected {$expected}"
}
}
return ok
} -cleanup {
db close
} -result ok
test update_cloze_fact-2 {update cloze fact} -setup {
morji::init_state
} -body {
set test_uid [morji::add_fact {[cloze a b], [cloze c d]} {} notes cloze mytag]
morji::update_fact $test_uid {[cloze c d], [cloze a b]} {} notes cloze mytag
set data [db eval {SELECT fact_data FROM cards}]
return $data
} -cleanup {
db close
} -result {{1 a b} {0 c d}}
test update_cloze_fact-3 {update cloze fact} -setup {
morji::init_state
} -body {
set test_uid [morji::add_fact {[cloze a b]} {} notes cloze mytag]
morji::update_fact $test_uid {[cloze c d], [cloze a b]} {} notes cloze mytag
set data [db eval {SELECT fact_data FROM cards}]
return $data
} -cleanup {
db close
} -result {{1 a b} {0 c d}}
test update_cloze_fact-4 {update cloze fact} -setup {
morji::init_state
} -body {
set test_uid [morji::add_fact {[cloze a b], [cloze c d]} {} notes cloze mytag]
morji::update_fact $test_uid {[cloze c d]} {} notes cloze mytag
set data [db onecolumn {SELECT uid FROM cards}]
return $data
} -cleanup {
db close
} -result 2
test update_cloze_fact-5 {update cloze fact} -setup {
morji::init_state
} -body {
set test_uid [morji::add_fact {[cloze a b], [cloze c d]} {} notes cloze mytag]
morji::update_fact $test_uid {[cloze a b], [cloze e f], [cloze c d]} {} notes cloze mytag
set data [db eval {SELECT uid, fact_data FROM cards}]
return $data
} -cleanup {
db close
} -result {1 {0 a b} 2 {2 c d} 3 {1 e f}}
test delete_fact-1 {delete fact} -setup {
morji::init_state
morji::add_fact question1 answer1 notes1 oneside mytag1
morji::add_fact question2 answer2 notes2 oneside mytag2
} -body {
morji::delete_fact 1
if {[db exists {SELECT 1 FROM facts WHERE uid=1}]} {
return "fact 1 not removed"
}
if {![db exists {SELECT 1 FROM facts WHERE uid=2}]} {
return "fact 2 removed"
}
return ok
} -cleanup {
db close
} -result ok
test delete_fact-2 {delete fact} -setup {
morji::init_state
morji::add_fact question1 answer1 notes1 oneside mytag1
morji::add_fact question2 answer2 notes2 oneside mytag2
} -body {
morji::delete_fact 2
if {![db exists {SELECT 1 FROM facts WHERE uid=1}]} {
return "fact 1 removed"
}
if {[db exists {SELECT 1 FROM facts WHERE uid=2}]} {
return "fact 2 not removed"
}
return ok
} -cleanup {
db close
} -result ok
test get_clozes-1 {get clozes} -body {
morji::get_clozes {[cloze a b] [cloze c d] [cloze e {f g}]}
} -result {{[cloze a b]} {[cloze c d]} {[cloze e {f g}]}}
test get_clozes-2 {get clozes} -body {
morji::get_clozes {[cloze a b] [cloze "c" d] [cloze e {f g}]}
} -result {{[cloze a b]} {[cloze "c" d]} {[cloze e {f g}]}}
test substcmd {substcmd} -body {
set x 3
morji::substcmd {$x/[string cat 4 2]/\n}
} -result {$x/42/\n}
test start_of_day-1 {start of day} -body {
set day 86400
for {set i 0} {$i < 300} {incr i} {
set morji::START_TIME [clock add [clock seconds] [expr {int(rand() * 2 * $day)}] seconds]
if {!([morji::start_of_day] >= [clock add $morji::START_TIME -1 day])} {
return "start of day too little for $morji::START_TIME"
}
}
return ok
} -result ok
test start_of_day-2 {start of day} -body {
set day 86400
for {set i 0} {$i < 300} {incr i} {
set morji::START_TIME [clock add [clock seconds] [expr {int(rand() * 2 * $day)}] seconds]
if {!([morji::start_of_day] <= $morji::START_TIME)} {
return "start of day too big for $morji::START_TIME"
}
}
return ok
} -result ok
test scheduling-1 {scheduling} -setup {
morji::init_state
set day 86400
set morji::START_TIME $day
set i 0
db transaction {
for {set i 0} {$i < 100} {incr i} {
morji::add_fact "What is the answer n°\[em $i\]?" "This is the answer n°\[em $i\]" notes oneside english
}
}
set i 0
db transaction {
for {set i 0} {$i < 100} {incr i} {
morji::add_fact "hitz \[em $i\]" "valsi \[em $i\]" notes twoside lojban
}
}
} -body {
db transaction {
set j 0
while {$j < 400} {
for {set i [expr {$j * 5 + 1}]} {$i < 300 && $i <= ($j+1) * 5 && $i > $j * 5} {incr i} {
set r [expr {rand()}]
set reps_before [db eval {SELECT reps FROM cards WHERE uid=$i}]
if {$r < 0.03} {
morji::schedule_card $i hard
db eval {SELECT last_rep, next_rep FROM cards WHERE uid=$i} break
if {$next_rep - $last_rep > 3*$day || $next_rep - $last_rep < 1*$day} {
return "bad first schedule for hard card"
}
} elseif {$r < 0.05} {
morji::schedule_card $i easy
db eval {SELECT last_rep, next_rep FROM cards WHERE uid=$i} break
if {$next_rep - $last_rep > 8*$day || $next_rep - $last_rep < 6*$day} {
return "bad first schedule for easy card"
}
} else {
morji::schedule_card $i good
db eval {SELECT last_rep, next_rep FROM cards WHERE uid=$i} break
if {$next_rep - $last_rep > 3*$day || $next_rep - $last_rep < 1*$day} {
return "bad first schedule for good card"
}
}
set reps_after [db eval {SELECT reps FROM cards WHERE uid=$i}]
if {!($r < 0.05 && $r >= 0.03) && $reps_after != $reps_before + 1} {
return "bad reps after first schedule"
}
if {($r < 0.05 && $r >= 0.03) && $reps_after != $reps_before + 2} {
return "bad reps after first easy schedule"
}
db eval {SELECT last_rep, next_rep, reps FROM cards WHERE uid=$i} {
set interval($i) [expr {$next_rep-$last_rep}]
}
}
set morji::START_TIME [clock add $morji::START_TIME 1 day]
set cards [morji::get_today_cards]
lappend cards {*}[morji::get_forgotten_cards]
set count 0
foreach uid $cards {
incr count
set r [expr {rand()}]
set reps_before [db onecolumn {SELECT reps FROM cards WHERE uid=$uid}]
if {$r < 0.03} {
morji::schedule_card $uid hard
} elseif {$r < 0.05} {
morji::schedule_card $uid easy
} elseif {$r < 0.07} {
morji::schedule_card $uid again
} else {
morji::schedule_card $uid good
}
set reps_after [db onecolumn {SELECT reps FROM cards WHERE uid=$uid}]
if {$r >= 0.05 && $r < 0.07} {
if {$reps_after != 0} {
return "bad reps for again: $reps_after"
}
} elseif {$reps_after != $reps_before + 1} {
return "bad reps: $reps_before -> $reps_after"
}
db eval {SELECT last_rep, next_rep, reps, easiness, fact_data FROM cards WHERE uid=$uid} {
set new_interval($uid) [expr {$next_rep-$last_rep}]
if {$new_interval($uid) == $interval($uid)} {
break
}
set new_interval_days [expr {double($new_interval($uid))/$day}]
set interval_days [expr {double($interval($uid))/$day}]
set adjusted_max_interval [expr {(($interval($uid)+1*$day)*$easiness)}]
set max_interval [expr {$adjusted_max_interval+max($adjusted_max_interval*$easiness*0.05,4*$day)}]
set max_interval_days [expr {double($max_interval)/$day}]
set min_interval [expr {($interval($uid)*$easiness)-max($interval($uid)*$easiness*0.05,3*$day)}]
set min_interval_days [expr {double($max_interval)/$day}]
if {$interval($uid) > 0 && $reps > 2 && $new_interval_days >= 12 && !($new_interval($uid) <= $max_interval)} {
return "bad interval: $easiness $reps $new_interval_days/$interval_days $max_interval_days (too large)"
}
if {$interval($uid) > 0 && $reps > 2 && $new_interval($uid) < 12 * $day &&
abs($new_interval($uid) - $interval($uid) - 6 * $day) > 3 * $day} {
return "bad interval: $new_interval_days-$interval_days-6 days (expected <= 3 days)"
}
if {$interval($uid) > 0 && $reps > 2 && $new_interval_days >= 12 && !($new_interval($uid) >= $min_interval)} {
return "bad interval: $easiness $reps $new_interval_days/$interval_days $min_interval_days (too little)"
}
if {$interval($uid) > 0 && $reps == 2 && $interval($uid) < 5 && ($new_interval_days < 4 || $new_interval_days > 8)} {
return "bad interval: $new_interval_days (expected >= 4 and <= 8)"
}
set interval($uid) $new_interval($uid)
}
}
incr j
}
}
return ok
} -cleanup {
db close
} -result ok
test scheduling-2 {scheduling: interval noise} -body {
set day 86400
for {set i 0} {$i <= 10} {incr i} {
set noise [morji::interval_noise [expr {$i * $day}]]
if {$noise > 1} {
return "bad noise: $noise (expected <= 1)"
}
}
return ok
} -result ok
test scheduling-3 {scheduling: interval noise} -body {
set day 86400
for {set i 11} {$i <= 20} {incr i} {
set noise [morji::interval_noise [expr {$i * $day}]]
if {$noise > 2} {
return "bad noise: $noise (expected <= 2)"
}
}
return ok
} -result ok
test scheduling-4 {scheduling: interval noise} -body {
set day 86400
for {set i 21} {$i <= 60} {incr i} {
set noise [morji::interval_noise [expr {$i * $day}]]
if {$noise > 3} {
return "bad noise: $noise (expected <= 3)"
}
}
return ok
} -result ok
test scheduling-5 {scheduling: interval noise} -body {
set day 86400
for {set i 61} {$i <= 100} {incr i} {
set noise [morji::interval_noise [expr {$i * $day}]]
if {$noise > $i * 0.05} {
return "bad noise: $noise (too large)"
}
}
return ok
} -result ok
test scheduling-6 {scheduling late} -setup {
morji::init_state
set day 86400
set morji::START_TIME $day
morji::add_fact question answer notes oneside english
} -body {
morji::schedule_card 1 good
db eval {SELECT next_rep FROM cards WHERE uid=1} break
set morji::START_TIME $next_rep
morji::schedule_card 1 good
db eval {SELECT last_rep, next_rep FROM cards WHERE uid=1} break
set morji::START_TIME $next_rep
set olast_rep $last_rep
set morji::START_TIME [clock add $morji::START_TIME 3 days]
morji::schedule_card 1 hard
db eval {SELECT last_rep, next_rep FROM cards WHERE uid=1} break
expr {abs($next_rep-$last_rep)-abs($morji::START_TIME-$olast_rep) < 1.5 * $day}
} -cleanup {
db close
} -result 1
test parse_card-1 {parse card} -body {
morji::parse_card {@Question: question}
} -result {question {} {} {} {}}
test parse_card-2 {parse card} -body {
morji::parse_card {@Answer: answer}
} -result {{} answer {} {} {}}
test parse_card-3 {parse card} -body {
morji::parse_card {@Notes: notes}
} -result {{} {} notes {} {}}
test parse_card-4 {parse card} -body {
morji::parse_card {@Type: oneside}
} -result {{} {} {} oneside {}}
test parse_card-5 {parse card} -body {
morji::parse_card {@Tags: mytag}
} -result {{} {} {} {} mytag}
test parse_card-6 {parse card} -body {
morji::parse_card {@Question: question @Tags: mytag @Answer: the answer}
} -result {question {the answer} {} {} mytag}
test put_text-1 {put text} -body {
morji::put_text text
} -output "text\n"
proc bold {text} {
return "[::term::ansi::code::ctrl::sda_bold]$text[::term::ansi::code::ctrl::sda_nobold]"
}
test put_text-2 {put text} -body {
morji::put_text {text [em emphasis]}
} -output "text [bold emphasis]\n"
test put_draw_line-1 {draw line} -body {
morji::draw_line
} -match regexp -output {─}
test put_help-1 {put help} -body {
morji::put_keys_help
} -match regexp -output {Keys [(]on current card[)]}
test put_help-2 {put initial help} -body {
morji::put_initial_schedule_prompt_help
} -match regexp -output {grade card memorization}
test put_help-3 {put context independent help} -body {
morji::put_context_independent_keys_help
} -match regexp -output {show this help}
test put_bracket-1 {put bracket} -body {
morji::markup::lbracket
} -result {[}
test put_bracket-2 {put bracket} -body {
morji::markup::rbracket
} -result {]}
test put_cloze-1 {put cloze} -body {
set morji::markup::CLOZE 0
morji::markup::cloze cloze hint
} -result "[bold "\[hint\]"]"
test put_cloze-2 {put cloze} -body {
set morji::markup::CLOZE 0
morji::markup::cloze cloze
} -result "[bold \[…\]]"
test put_cloze-3 {put cloze} -body {
set morji::markup::CLOZE -42
morji::markup::cloze cloze hint
} -result "\[cloze cloze [bold hint]\]"
test put_cloze-4 {put cloze} -body {
set morji::markup::CLOZE 1
morji::markup::cloze cloze hint
} -result "cloze"
test show_fact-1 {show fact} -setup {
morji::init_state
morji::add_fact "What is the \[lbracket\]important\[rbracket\] n°\[em 1\] answer?" "The answer n°\[em 1\]" notes oneside english
} -body {
morji::show_fact 1 {mytag}
return ok
} -cleanup {
db close
} -result ok -match regexp -output "Question:.*important.*\n.*Answer:.*answer.*Tags:.*mytag"
test show_fact-2 {show fact} -setup {
morji::init_state
set uid [morji::add_fact {[cloze a b], [cloze c d], [cloze e f]} {} notes cloze mytag]
} -body {
morji::show_fact 1 {mytag}
return ok
} -cleanup {
db close
} -result ok -match regexp -output {Question:.*cloze.*b.*cloze.*c.*cloze.*e.*Notes:.*notes.*Type:.*cloze.*Tags:.*mytag}
test show_cards_scheduled_next_week-1 {show scheduled cards} -setup {
morji::init_state
} -body {
morji::show_cards_scheduled_next_days 7
return ok
} -cleanup {
db close
} -result ok -match regexp -output "Cards scheduled for next 7 days\[^\d\]*0 0 0 0 0 0 0\n"
test show_statistics-1 {show statistics} -setup {
morji::init_state
} -body {
morji::show_statistics
return ok
} -cleanup {
db close
} -result ok -match regexp -output ".*Cards not memorized.*0.*Memorized cards.*0"
test screen_start-1 {put screen start} -body {
morji::put_screen_start
return ok
} -result ok -match regexp -output "help"
test put_card_fields-1 {put card fields} -body {
morji::put_card_fields stdout question answer notes type mytag
return ok
} -result ok -output "@Question: question\n@Answer: answer\n@Notes: notes\n@Type: type\n@Tags: mytag\n"
test rename_tag-1 {rename tag} -setup {
morji::init_state
morji::add_fact "question" "answer" notes oneside {english lojban}
} -body {
morji::rename_tag lojban gismu
morji::get_tags
} -cleanup {
db close
} -result "all english gismu"
test fmt-1 {format paragraph} -body {
morji::fmt "
\033\[33m\033\[33mword word word word word word word word word \033\[33mword \033\[33mword
word word word word word word word word word word word word
word"
} -result "\033\[33m\033\[33mword word word word word word word word word \033\[33mword \033\[33mword
word word word word word word word word word word word
word word"
test fmt-2 {format paragraph} -body {
morji::fmt ""
} -result {}
test import_tsv_facts-1 {import tab separated value file} -setup {
morji::init_state
} -body {
morji::import_tsv_facts test_facts.tsv
foreach uid {1 2 3} values {
{question answer notes oneside}
{question2 answer2 notes2 twoside}
{{[cloze word hint]} {} notes3 cloze}} {
db eval {SELECT * FROM facts WHERE uid=$uid} break
foreach k {question answer notes type} v $values {
if {[set $k] ne $v} {
return "[set $k]:$v"
}
}
}
return ok
} -cleanup {
db close
} -result ok -output "Added 3 new facts.\n"
test import_tsv_facts-2 {import tab separated value file} -setup {
morji::init_state
} -body {
morji::import_tsv_facts test_facts.tsv
foreach tag {myonesides mytwosides myclozes} n {1 2 3} {
if {![db exists {SELECT 1 FROM tags, fact_tags WHERE name=$tag AND fact_uid=$n AND tag_uid=uid}]} {
return "tag $tag not found for fact $n"
}
}
return ok
} -cleanup {
db close
} -result ok -output "Added 3 new facts.\n"
test check_database {check database} -setup {
morji::init_state
morji::add_fact "question" "answer" notes oneside {english lojban}
morji::add_fact question answer notes twoside mytag
morji::add_fact {[cloze a b], [cloze c d], [cloze e f]} {} notes cloze mytag
} -body {
if {![morji::check_database]} {
return "invalid database"
}
return ok
} -result ok
}
namespace delete morji::test