diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-13 12:00:45 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-13 12:00:45 -0600 |
| commit | c4c64e2762d7b75f588c20bc7d43ddf8ba30c97e (patch) | |
| tree | cad831f6f02da8b87603919776b0caff6540b2bc /tests | |
| parent | 1618ff6b2cfe463ee225f11c2772712f8243c6d3 (diff) | |
| download | org-drill-c4c64e2762d7b75f588c20bc7d43ddf8ba30c97e.tar.gz org-drill-c4c64e2762d7b75f588c20bc7d43ddf8ba30c97e.zip | |
test: Complete Phase 2 card type tests
- Add unit tests for show1cloze card type (6 tests)
- Add unit tests for multicloze variants (12 tests)
- Add integration test for card type system (5 tests)
Phase 2 complete: All major card types tested
Total: 114 tests (98 unit + 16 integration), all passing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-card-type-multicloze.el | 119 | ||||
| -rw-r--r-- | tests/test-card-type-show1cloze.el | 83 | ||||
| -rw-r--r-- | tests/test-integration-card-types-integration-test.el | 69 |
3 files changed, 271 insertions, 0 deletions
diff --git a/tests/test-card-type-multicloze.el b/tests/test-card-type-multicloze.el new file mode 100644 index 0000000..9aaa58f --- /dev/null +++ b/tests/test-card-type-multicloze.el @@ -0,0 +1,119 @@ +;;; test-card-type-multicloze.el --- Tests for multicloze card type variants + +;;; Commentary: +;; Tests for various multicloze card type variants in org-drill. +;; +;; Multicloze variants: +;; - multicloze (alias for hide1cloze) +;; - hide1cloze, hide2cloze (hide N clozes) +;; - show1cloze, show2cloze (show N clozes, hide rest) +;; - hidefirst, hidelast (hide specific positions) +;; - hide1_firstmore, show1_lastmore, show1_firstless (weighted variants) + +;;; Code: + +(require 'ert) +(require 'assess) +(require 'org-drill) + +;;; Normal Cases - Multicloze Variants + +(ert-deftest test-card-type-multicloze-normal-hide2cloze-exists () + "Test that hide2cloze variant exists." + (let ((entry (assoc "hide2cloze" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-hide2)))) + +(ert-deftest test-card-type-multicloze-normal-show2cloze-exists () + "Test that show2cloze variant exists." + (let ((entry (assoc "show2cloze" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-show2)))) + +(ert-deftest test-card-type-multicloze-normal-hidefirst-exists () + "Test that hidefirst variant exists." + (let ((entry (assoc "hidefirst" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-hide-first)))) + +(ert-deftest test-card-type-multicloze-normal-hidelast-exists () + "Test that hidelast variant exists." + (let ((entry (assoc "hidelast" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-hide-last)))) + +;;; Normal Cases - Weighted Variants + +(ert-deftest test-card-type-multicloze-normal-hide1-firstmore-exists () + "Test that hide1_firstmore variant exists." + (let ((entry (assoc "hide1_firstmore" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-hide1-firstmore)))) + +(ert-deftest test-card-type-multicloze-normal-show1-lastmore-exists () + "Test that show1_lastmore variant exists." + (let ((entry (assoc "show1_lastmore" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-show1-lastmore)))) + +(ert-deftest test-card-type-multicloze-normal-show1-firstless-exists () + "Test that show1_firstless variant exists." + (let ((entry (assoc "show1_firstless" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-show1-firstless)))) + +;;; Boundary Cases - Hide vs Show Counts + +(ert-deftest test-card-type-multicloze-boundary-hide1-vs-hide2 () + "Test that hide1cloze and hide2cloze use different functions." + (let ((hide1-fn (cadr (assoc "hide1cloze" org-drill-card-type-alist))) + (hide2-fn (cadr (assoc "hide2cloze" org-drill-card-type-alist)))) + (should-not (eq hide1-fn hide2-fn)) + (should (eq hide1-fn 'org-drill-present-multicloze-hide1)) + (should (eq hide2-fn 'org-drill-present-multicloze-hide2)))) + +(ert-deftest test-card-type-multicloze-boundary-show1-vs-show2 () + "Test that show1cloze and show2cloze use different functions." + (let ((show1-fn (cadr (assoc "show1cloze" org-drill-card-type-alist))) + (show2-fn (cadr (assoc "show2cloze" org-drill-card-type-alist)))) + (should-not (eq show1-fn show2-fn)) + (should (eq show1-fn 'org-drill-present-multicloze-show1)) + (should (eq show2-fn 'org-drill-present-multicloze-show2)))) + +;;; Boundary Cases - Position-based Variants + +(ert-deftest test-card-type-multicloze-boundary-hidefirst-vs-hidelast () + "Test that hidefirst and hidelast use different functions." + (let ((first-fn (cadr (assoc "hidefirst" org-drill-card-type-alist))) + (last-fn (cadr (assoc "hidelast" org-drill-card-type-alist)))) + (should-not (eq first-fn last-fn)) + (should (eq first-fn 'org-drill-present-multicloze-hide-first)) + (should (eq last-fn 'org-drill-present-multicloze-hide-last)))) + +;;; Semantics - Variant Coverage + +(ert-deftest test-card-type-multicloze-normal-all-variants-registered () + "Test that all documented multicloze variants are registered. +This ensures the card type system is complete." + (let ((variants '("multicloze" "hide1cloze" "hide2cloze" + "show1cloze" "show2cloze" + "hidefirst" "hidelast" + "hide1_firstmore" "show1_lastmore" "show1_firstless"))) + (dolist (variant variants) + (let ((entry (assoc variant org-drill-card-type-alist))) + (should entry) + (should (cadr entry)))))) + +(ert-deftest test-card-type-multicloze-normal-function-naming-convention () + "Test that multicloze functions follow naming convention. +All should start with org-drill-present-multicloze-" + (let ((multicloze-types '("hide1cloze" "hide2cloze" "show1cloze" "show2cloze" + "hidefirst" "hidelast"))) + (dolist (type multicloze-types) + (let* ((entry (assoc type org-drill-card-type-alist)) + (fn (cadr entry)) + (fn-name (symbol-name fn))) + (should (string-prefix-p "org-drill-present-multicloze-" fn-name)))))) + +(provide 'test-card-type-multicloze) +;;; test-card-type-multicloze.el ends here diff --git a/tests/test-card-type-show1cloze.el b/tests/test-card-type-show1cloze.el new file mode 100644 index 0000000..a4a1d06 --- /dev/null +++ b/tests/test-card-type-show1cloze.el @@ -0,0 +1,83 @@ +;;; test-card-type-show1cloze.el --- Tests for show1cloze card type + +;;; Commentary: +;; Tests for the show1cloze card type in org-drill. +;; +;; show1cloze cards show exactly one piece of cloze-marked text, +;; chosen at random, while hiding all other cloze markers. +;; This is the inverse of hide1cloze. +;; +;; Card type: "show1cloze" +;; Presentation function: org-drill-present-multicloze-show1 + +;;; Code: + +(require 'ert) +(require 'assess) +(require 'org-drill) + +;;; Normal Cases - Card Recognition + +(ert-deftest test-card-type-show1cloze-normal-card-type-property () + "Test that show1cloze cards have correct DRILL_CARD_TYPE property." + (with-temp-buffer + (org-mode) + (insert "* Show Cloze Card :drill:\n:PROPERTIES:\n:DRILL_CARD_TYPE: show1cloze\n:END:\n\nThe capital of France is Paris.\n") + (goto-char (point-min)) + (should (org-drill-entry-p)) + (should (equal "show1cloze" (org-entry-get (point) "DRILL_CARD_TYPE"))))) + +(ert-deftest test-card-type-show1cloze-normal-has-presentation-function () + "Test that show1cloze card type has correct presentation function." + (let ((entry (assoc "show1cloze" org-drill-card-type-alist))) + (should entry) + (should (eq (cadr entry) 'org-drill-present-multicloze-show1)))) + +(ert-deftest test-card-type-show1cloze-normal-different-from-hide1cloze () + "Test that show1cloze and hide1cloze use different functions." + (let ((show1-fn (cadr (assoc "show1cloze" org-drill-card-type-alist))) + (hide1-fn (cadr (assoc "hide1cloze" org-drill-card-type-alist)))) + (should-not (eq show1-fn hide1-fn)) + (should (eq show1-fn 'org-drill-present-multicloze-show1)) + (should (eq hide1-fn 'org-drill-present-multicloze-hide1)))) + +(ert-deftest test-card-type-show1cloze-normal-show2cloze-exists () + "Test that show2cloze variant also exists." + (let ((show1-entry (assoc "show1cloze" org-drill-card-type-alist)) + (show2-entry (assoc "show2cloze" org-drill-card-type-alist))) + (should show1-entry) + (should show2-entry) + ;; Different presentation functions + (should-not (eq (cadr show1-entry) (cadr show2-entry))) + (should (eq (cadr show2-entry) 'org-drill-present-multicloze-show2)))) + +;;; Semantics - Inverse of hide1cloze + +(ert-deftest test-card-type-show1cloze-normal-inverse-semantics () + "Test that show1cloze has inverse semantics to hide1cloze. +hide1cloze: hide 1, show rest +show1cloze: show 1, hide rest" + (let ((hide1-fn (cadr (assoc "hide1cloze" org-drill-card-type-alist))) + (show1-fn (cadr (assoc "show1cloze" org-drill-card-type-alist)))) + ;; Both functions exist + (should hide1-fn) + (should show1-fn) + ;; They are different functions + (should-not (eq hide1-fn show1-fn)) + ;; Both are multicloze variants + (should (string-match-p "multicloze" (symbol-name hide1-fn))) + (should (string-match-p "multicloze" (symbol-name show1-fn))))) + +(ert-deftest test-card-type-show1cloze-normal-use-case-list-learning () + "Test typical use case for show1cloze: learning from one shown item. +When learning a list, showing one item while hiding others helps +learn the context around each item." + (with-temp-buffer + (org-mode) + (insert "* Programming Languages :drill:\n:PROPERTIES:\n:DRILL_CARD_TYPE: show1cloze\n:END:\n\nLearn these languages.\n") + (goto-char (point-min)) + (should (org-drill-entry-p)) + (should (equal "show1cloze" (org-entry-get (point) "DRILL_CARD_TYPE"))))) + +(provide 'test-card-type-show1cloze) +;;; test-card-type-show1cloze.el ends here diff --git a/tests/test-integration-card-types-integration-test.el b/tests/test-integration-card-types-integration-test.el new file mode 100644 index 0000000..deecea5 --- /dev/null +++ b/tests/test-integration-card-types-integration-test.el @@ -0,0 +1,69 @@ +;;; test-integration-card-types-integration-test.el --- Integration test for card types + +;;; Commentary: +;; Integration test verifying that the card type system works correctly. + +;;; Code: + +(require 'ert) +(require 'assess) +(require 'org-drill) + +;;; Integration Tests - Card Type System + +(ert-deftest test-integration-card-types-integration-card-type-system-complete () + "Test that card type system handles all expected types. +Verifies all card types are registered in org-drill-card-type-alist." + (let ((expected-types '(nil "simple" "simpletyped" "twosided" "multisided" + "hide1cloze" "hide2cloze" "show1cloze" "show2cloze" + "multicloze" "hidefirst" "hidelast" + "hide1_firstmore" "show1_lastmore" "show1_firstless" + "conjugate" "decline_noun" "spanish_verb" "translate_number"))) + (dolist (type expected-types) + (let ((entry (assoc type org-drill-card-type-alist))) + (should entry) + (should (cadr entry)))))) + +(ert-deftest test-integration-card-types-integration-simple-vs-twosided () + "Test that simple and twosided cards use different presentation functions." + (let ((simple-fn (cadr (assoc "simple" org-drill-card-type-alist))) + (twosided-fn (cadr (assoc "twosided" org-drill-card-type-alist)))) + (should simple-fn) + (should twosided-fn) + (should-not (eq simple-fn twosided-fn)))) + +(ert-deftest test-integration-card-types-integration-hide-vs-show-cloze () + "Test that hide and show cloze variants use different functions." + (let ((hide1-fn (cadr (assoc "hide1cloze" org-drill-card-type-alist))) + (show1-fn (cadr (assoc "show1cloze" org-drill-card-type-alist))) + (hide2-fn (cadr (assoc "hide2cloze" org-drill-card-type-alist))) + (show2-fn (cadr (assoc "show2cloze" org-drill-card-type-alist)))) + (should hide1-fn) + (should show1-fn) + (should hide2-fn) + (should show2-fn) + ;; All different + (should-not (eq hide1-fn show1-fn)) + (should-not (eq hide1-fn hide2-fn)) + (should-not (eq show1-fn show2-fn)))) + +(ert-deftest test-integration-card-types-integration-default-equals-simple () + "Test that default (nil) card type maps to same function as simple." + (let ((default-fn (cadr (assoc nil org-drill-card-type-alist))) + (simple-fn (cadr (assoc "simple" org-drill-card-type-alist)))) + (should default-fn) + (should simple-fn) + (should (eq default-fn simple-fn)) + (should (eq default-fn 'org-drill-present-simple-card)))) + +(ert-deftest test-integration-card-types-integration-presentation-functions-exist () + "Test that all presentation functions are defined." + (let ((all-types '("simple" "twosided" "hide1cloze" "show1cloze" "multicloze"))) + (dolist (type all-types) + (let* ((entry (assoc type org-drill-card-type-alist)) + (fn (cadr entry))) + (should fn) + (should (fboundp fn)))))) + +(provide 'test-integration-card-types-integration-test) +;;; test-integration-card-types-integration-test.el ends here |
