Skip to content

Commit

Permalink
Attach algorithm class to cards
Browse files Browse the repository at this point in the history
  • Loading branch information
l3kn committed Mar 11, 2024
1 parent fb4dda5 commit 1c8e25f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
6 changes: 4 additions & 2 deletions org-fc-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ If point is not inside a flashcard entry, an error is raised."
:documentation "Title of the card.")
(algo
:initarg :algo
:type symbol
:type org-fc-algo
:documentation "Algorithm of the card.")
(type
:initarg :type
Expand Down Expand Up @@ -349,7 +349,9 @@ If point is not inside a flashcard entry, an error is raised."
;; NOTE: For compatibility with older versions of org-fc, a
;; card with no algorithm property set is assumed to use
;; the SM2 algorithm.
:algo (or (plist-get plist :algo) 'sm2)
:algo
(funcall (org-fc-algo-constructor
(or (plist-get plist :algo) 'sm2)) ())
:type (plist-get plist :type)
:cloze-type (plist-get plist :cloze-type)
:created (plist-get plist :created)
Expand Down
2 changes: 1 addition & 1 deletion org-fc-review.el
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ showing and rating the card."
;; If the card is marked as a demo card, don't log its reviews and
;; don't update its review data
(unless (member org-fc-demo-tag (org-get-tags))
(let ((algo (org-fc-algo-sm2)))
(let ((algo (oref (oref position card) algo)))
(org-fc-algo-update-review-data algo position rating delta)))))

(defun org-fc-review-reset ()
Expand Down
2 changes: 1 addition & 1 deletion tests/index/test.org
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ body
:PROPERTIES:
:FC_CREATED: 2020-07-08T12:18:45Z
:FC_TYPE: normal
:FC_ALGO: fsrs
:FC_ALGO: sm2
:ID: a7ed2686-73e6-4780-825d-78cf4b2e5374
:END:
:REVIEW_DATA:
Expand Down
4 changes: 2 additions & 2 deletions tests/org-fc-card-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(org-fc-test-fixture "erts/card_rate_normal.erts")
(lambda ()
(let* ((file (org-fc-file :path "mock-path"))
(card (org-fc-card :file file :id "mock-id"))
(card (org-fc-card :file file :id "mock-id" :algo (org-fc-algo-sm2)))
(position (org-fc-position :card card :name "front")))
(org-fc-test-with-overwrites
(org-fc-test-overwrite-fun
Expand Down Expand Up @@ -60,7 +60,7 @@
(org-fc-test-fixture "erts/card_rate_double.erts")
(lambda ()
(let* ((file (org-fc-file :path "mock-path"))
(card (org-fc-card :file file :id "mock-id"))
(card (org-fc-card :file file :id "mock-id" :algo (org-fc-algo-sm2)))
(position (org-fc-position :card card :name "front")))
(org-fc-test-with-overwrites
(org-fc-test-overwrite-fun
Expand Down
31 changes: 16 additions & 15 deletions tests/org-fc-indexer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
(org-fc-test-fixture "index/lowercase.org")))))

(ert-deftest org-fc-test-index ()
(org-fc-test-check-structure
'((:cards
((:id "edee8940-5c9a-4c70-b1c4-f45c194c0c97"
:tags ("fc" "tag1")
:title "Headline"
:algo sm2)
(:id "59b3b102-aebd-44ba-a1fd-6dc912c34fcf"
:tags ("fc" "tag2")
:title "Headline 2"
:algo sm2)
(:id "a7ed2686-73e6-4780-825d-78cf4b2e5374"
:tags ("fc" "tag3")
:title "Headline 3:not_a_tag:"
:algo fsrs))))
(org-fc-awk-index (list (org-fc-test-fixture "index/test.org")))))
(let ((algo (org-fc-algo-sm2)))
(org-fc-test-check-structure
`((:cards
((:id "edee8940-5c9a-4c70-b1c4-f45c194c0c97"
:tags ("fc" "tag1")
:title "Headline"
:algo ,algo)
(:id "59b3b102-aebd-44ba-a1fd-6dc912c34fcf"
:tags ("fc" "tag2")
:title "Headline 2"
:algo ,algo)
(:id "a7ed2686-73e6-4780-825d-78cf4b2e5374"
:tags ("fc" "tag3")
:title "Headline 3:not_a_tag:"
:algo ,algo))))
(org-fc-awk-index (list (org-fc-test-fixture "index/test.org"))))))

0 comments on commit 1c8e25f

Please sign in to comment.