blob: 931fdcb7d36594c5d48c182473927ecc4ce25d55 (
about) (
plain)
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
|
;;; gnosis-algorithm.el --- Gnosis testing module -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Thanos Apollo
;; Author: Thanos Apollo <[email protected]>
;; Keywords: extensions
;; URL: https://git.thanosapollo.org/gnosis
;; Version: 0.0.1
;; Package-Requires: ((emacs "27.2") (compat "29.1.4.2"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Development module for gnosis, make testing of gnosis
;; easier by creating a testing environment with random inputs.
;;; Code:
(add-to-list 'load-path ".")
(require 'ert)
(require 'gnosis)
(defvar gnosis-test-tags '("anatomy" "thoracic" "serratus-anterior"
"biochemistry" "informatics" "amino-acids"
"microbiology" "gram-positive" "gram-negative"
"fungi" "parasites"))
(defvar gnosis-test-image "anatomy/typic-vertebra-superior-01.png"
"Random image for testing")
(defun gnosis-test-random-items (list x)
"Select X random items from LIST."
(let ((shuffled-list (copy-sequence list))
selected-items)
(dotimes (_ x)
(let* ((index (random (length shuffled-list)))
(item (nth index shuffled-list)))
(setq selected-items (cons item selected-items))
(setq shuffled-list (append (butlast shuffled-list index) (nthcdr (1+ index) shuffled-list)))))
selected-items))
(defun gnosis-test-add-fields (&optional num deck)
"Add random inputs to test.
NUM: Number of random inputs to add.
DECK: Deck to add the inputs to."
(let ((num (or num (string-to-number (read-string "Number of random inputs: "))))
(testing-deck (or deck "testing")))
(unless (gnosis-get 'name 'decks `(= name ,testing-deck))
(gnosis-add-deck testing-deck))
(when (y-or-n-p "Add MCQ type?")
(emacsql-with-transaction gnosis-db
(dotimes (_ num)
(gnosis-add-note--mcq :deck testing-deck
:question "A *37-year-old* man is admitted to the
emergency department after a severe car crash. /After/ examining the
patient the emergency medicine physician concludes *that* the serratus
anterior muscle is damaged. ~Which~ of the following nerves innervates
the =serratus anterior muscle=?"
:choices '("Long thoracic" "Axillary" "Spinal accessory" "Dorsal scapular" "Thoracodorsal")
:correct-answer 1
:extra "The long thoracic is the only nerve that
innervates the serratus anterior. The axillary nerve innervates the
deltoid, the spinal accessory nerve innervates the sternocleidomastoid
and trapezius, the dorsal scapular nerve supplies the rhomboid muscles
and levator scapulae, and the latissimus dorsi is the muscle supplied
by the thoracodorsal nerve."
:images (cons gnosis-test-image gnosis-test-image)
:tags (gnosis-test-random-items gnosis-test-tags 2))))
(when (y-or-n-p "Add Basic type questions?")
(dotimes (_ num)
(gnosis-add-note--basic :deck testing-deck
:question "A question"
:hint "hint"
:answer "answer"
:extra "extra"
:images (cons gnosis-test-image gnosis-test-image)
:tags (gnosis-test-random-items gnosis-test-tags 2))))
(when (y-or-n-p "Add single Cloze type?")
(dotimes (_ num)
;; TODO: Update tests for include hints.
(gnosis-add-note--cloze :deck testing-deck
:note "this is a {c1:note}"
:tags (gnosis-test-random-items gnosis-test-tags 2)
:images (cons gnosis-test-image gnosis-test-image)
:extra "extra")))
(when (y-or-n-p "Add multimple Clozes note?")
(dotimes (_ num)
(gnosis-add-note--cloze :deck testing-deck
:note "this is a {c1:note}, a note with multiple {c1:clozes::what}"
:tags (gnosis-test-random-items gnosis-test-tags 2)
:images (cons gnosis-test-image gnosis-test-image)
:extra "extra")))
(when (y-or-n-p "Add y-or-n note type?")
(dotimes (_ num)
(gnosis-add-note--y-or-n :deck testing-deck
:question "Is Codeine recommended in breastfeeding mothers?"
:hint "hint"
:answer 110
:extra "extra"
:images (cons gnosis-test-image gnosis-test-image)
:tags (gnosis-test-random-items gnosis-test-tags 2)))))))
(defun gnosis-test-start (&optional note-num)
"Begin/End testing env.
If ask nil, leave testing env"
(interactive)
(let* ((ask (y-or-n-p "Start development env (n for exit)?"))
(testing-dir (expand-file-name "testing" gnosis-dir))
(testing-db (expand-file-name "testing.db" testing-dir)))
(if ask
(progn
(unless (file-exists-p testing-dir)
(make-directory testing-dir))
(when (file-exists-p testing-db)
(delete-file testing-db))
(setf gnosis-db (emacsql-sqlite-open testing-db))
(setf gnosis-testing t)
(gnosis-db-init)
(gnosis-test-add-fields note-num)
(message "Adding testing values...")
(message "Development env is ready for testing."))
(setf gnosis-db (emacsql-sqlite-open (expand-file-name "gnosis.db" gnosis-dir)))
(setf gnosis-testing nil)
(message "Exited development env."))))
(ert-deftest gnosis-test-algorithm-next-interval-proto ()
"Test next interval for proto values."
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success t
:successful-reviews 0
:amnesia 0.5
:proto '(1 2 3)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 1)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success t
:successful-reviews 1
:amnesia 0.5
:proto '(1 2 3)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 2)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success t
:successful-reviews 2
:amnesia 0.5
:proto '(1 2 3)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 3)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success t
:successful-reviews 3
:amnesia 0.5
:proto '(1 2 3 70)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 70)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 2.0
:success t
:successful-reviews 4
:amnesia 0.5
:proto '(1 2 3 70)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 2)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 3.0
:success t
:successful-reviews 5
:amnesia 0.5
:proto '(1 2 3 70)
:c-fails 0
:lethe 3)
(gnosis-algorithm-date 3))))
(ert-deftest gnosis-test-algorithm-next-interval-lethe ()
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success nil
:successful-reviews 0
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 3)
(gnosis-algorithm-date)))
(should (equal (gnosis-algorithm-next-interval :last-interval 0
:gnosis-synolon 1.3
:success nil
:successful-reviews 0
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date)))
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 20.0
:success nil
:successful-reviews 2
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 5)))
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 20.0
:success nil
:successful-reviews 2
:amnesia 0.5
:proto '(1 2 3)
:c-fails 5
:lethe 4)
(gnosis-algorithm-date))))
(ert-deftest gnosis-test-algorithm-next-interval-success ()
"Test next interval for successful non-proto recalls."
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 2.0
:success t
:successful-reviews 5
:amnesia 0.5
:proto '(1 2 3)
:c-fails 500
:lethe 4)
(gnosis-algorithm-date 20)))
(should (equal (gnosis-algorithm-next-interval :last-interval 3
:gnosis-synolon 1.3
:success t
:successful-reviews 5
:amnesia 0.5
:proto '(1 2 3)
:c-fails 300
:lethe 4)
(gnosis-algorithm-date 4))))
(ert-deftest gnosis-test-algorithm-next-interval-amnesia ()
"Test next interval for failed non-proto recalls."
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 5)))
(should (equal (gnosis-algorithm-next-interval :last-interval 3
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 2)))
(should (equal (gnosis-algorithm-next-interval :last-interval 2
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.5
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 1)))
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.3
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 3)))
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.2
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date 2)))
(should (equal (gnosis-algorithm-next-interval :last-interval 10
:gnosis-synolon 1.3
:success nil
:successful-reviews 3
:amnesia 0.0
:proto '(1 2 3)
:c-fails 3
:lethe 4)
(gnosis-algorithm-date))))
(ert-deftest gnosis-test-algorithm-next-gnosis-synolon ()
"Test algorithm for gnosis synolon (totalis)."
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.35 0.30 1.30)
:success t
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 1
:c-failures 0)
'(0.35 0.30 1.65)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 1.30)
:success t
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 1
:c-failures 0)
'(0.45 0.30 1.75)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 2.0)
:success nil
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 1
:c-failures 0)
'(0.45 0.30 1.70)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success nil
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 1
:c-failures 0)
'(0.45 0.30 3.2))))
(ert-deftest gnosis-test-algorithm-test-epignosis ()
"Test epignosis during anagnosis events."
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success t
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 3
:c-failures 0)
'(0.75 0.30 3.95)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success t
:epignosis 0.2
:agnoia 0.2
:anagnosis 3
:c-successes 3
:c-failures 0)
'(0.65 0.30 3.95)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success t
:epignosis 0.2
:agnoia 0.2
:anagnosis 4
:c-successes 3
:c-failures 0)
'(0.45 0.30 3.95))))
(ert-deftest gnosis-test-algorithm-test-agnoia ()
"Test epignosis during anagnosis events."
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success nil
:epignosis 0.3
:agnoia 0.2
:anagnosis 3
:c-successes 0
:c-failures 3)
'(0.45 0.5 3.2)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success nil
:epignosis 0.3
:agnoia 0.3
:anagnosis 3
:c-successes 0
:c-failures 3)
'(0.45 0.6 3.2)))
(should (equal (gnosis-algorithm-next-gnosis
:gnosis '(0.45 0.30 3.5)
:success nil
:epignosis 0.3
:agnoia 0.3
:anagnosis 4
:c-successes 0
:c-failures 3)
'(0.45 0.3 3.2))))
(ert-run-tests-batch-and-exit)
(provide 'gnosis-test)
;;; gnosis-test.el ends here
|