Skip to content

Commit

Permalink
䷓ Contemplation
Browse files Browse the repository at this point in the history
  • Loading branch information
zzkt committed Nov 13, 2024
1 parent 0870cb1 commit e4339cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions i-ching.el
Original file line number Diff line number Diff line change
Expand Up @@ -865,17 +865,21 @@ Provided by Randomness and Integrity Services Ltd. via https://www.random.org/"
The hexagram can be entered as a string, or by number."
(interactive "sHexagram number? " hexagram)
(let ((hexagram-number
(pcase hexagram
((pred numberp) hexagram)
((pred i-ching-hexagram-p)
(i-ching-hexagram-to-number hexagram))
(_ (error "Not a hexagram symbol or number")))))
(cond
((i-ching-hexagram-p hexagram)
(i-ching-hexagram-to-number hexagram))
((numberp hexagram) hexagram)
((stringp hexagram)
(if (numberp (string-to-number hexagram))
(string-to-number hexagram)))
(t (error "Not a hexagram symbol or number")))))
(format "%s\n\n%s\n\nJudgment: %s\n\nImage: %s\n\n"
(i-ching-number-to-hexagram hexagram-number)
(i-ching-number-to-description hexagram-number)
(i-ching-number-to-judgment hexagram-number)
(i-ching-number-to-image hexagram-number))))


;; querying the I Ching

;;;###autoload
Expand Down
6 changes: 5 additions & 1 deletion tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@

(ert-deftest i-ching-interprets ()
(should (stringp (i-ching-interpretation 49)))
(should-not (seq-empty-p (i-ching-interpretation 49))))
(should (stringp (i-ching-interpretation "23")))
(should (stringp (i-ching-interpretation "")))
(should-not (seq-empty-p (i-ching-interpretation 49)))
(should-not (seq-empty-p (i-ching-interpretation "23")))
(should-not (seq-empty-p (i-ching-interpretation ""))))

(ert-deftest i-ching-queries ()
(should (stringp (i-ching-query-string)))
Expand Down

0 comments on commit e4339cb

Please sign in to comment.