From 85b6a2f2b972a4d757ce881049ea089941cfd955 Mon Sep 17 00:00:00 2001 From: nik gaffney Date: Mon, 11 Jan 2021 13:08:32 +0100 Subject: [PATCH] =?UTF-8?q?=E4=B7=91=20Repair?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Successful progress is indicated for those who properly repair what has been spoiled. --- i-ching.el | 3 +- tests.el | 98 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/i-ching.el b/i-ching.el index 8098d7f..a16c410 100644 --- a/i-ching.el +++ b/i-ching.el @@ -525,7 +525,8 @@ c.f. ‘The Superior man’ (Legge, Wilhem), ‘Noble young one’ (Hatcher), 't "The name of Hexagram NUMBER based on it's unicode name." (let* ((hexagrams i-ching-hexagram-summary) (unicode-name (nth 4 (alist-get number hexagrams)))) - (capitalize (seq-drop unicode-name 13)))) + (when unicode-name + (capitalize (seq-drop unicode-name 13))))) (defun i-ching-describe-hexagram (point mark) "Show the name of a HEXAGRAM (between POINT and MARK) based on it's unicode name." diff --git a/tests.el b/tests.el index 166fc9c..9527cd7 100644 --- a/tests.el +++ b/tests.el @@ -4,41 +4,99 @@ (require 'i-ching) -(ert-deftest qrnd () - (should (numberp (i-ching-q64))) - (should (< 0 (i-ching-q64))) - (should (>= 64 (i-ching-q64)))) +(ert-deftest i-ching-qrnd () + (should (numberp (i-ching-q64))) + (should (< 0 (i-ching-q64))) + (should (>= 64 (i-ching-q64)))) -(ert-deftest rrnd () - (should (numberp (i-ching-r64))) - (should (< 0 (i-ching-r64))) - (should (>= 64 (i-ching-r64)))) +(ert-deftest i-ching-rrnd () + (should (numberp (i-ching-r64))) + (should (< 0 (i-ching-r64))) + (should (>= 64 (i-ching-r64)))) + +(ert-deftest i-ching-random () + (should (numberp (i-ching-random 'quantum))) + (should (numberp (i-ching-random 'atmospheric))) + (should (numberp (i-ching-random 'pseudo)))) (ert-deftest i-ching-n2h () - (should (string= "䷁" (i-ching-number-to-hexagram 2))) - (should (string= "䷩" (i-ching-number-to-hexagram 42))) - (should (string= nil (i-ching-number-to-hexagram 65)))) + (should (string= "䷁" (i-ching-number-to-hexagram 2))) + (should (string= "䷩" (i-ching-number-to-hexagram 42))) + (should (string= nil (i-ching-number-to-hexagram 65)))) (ert-deftest i-ching-h2n () - (should (eql 2 (i-ching-hexagram-to-number "䷁"))) - (should (eql 40 (i-ching-hexagram-to-number "䷧"))) - (should (eql nil (i-ching-hexagram-to-number "NOT")))) + (should (eql 2 (i-ching-hexagram-to-number "䷁"))) + (should (eql 40 (i-ching-hexagram-to-number "䷧"))) + (should-not (i-ching-hexagram-to-number "NOT"))) (ert-deftest i-ching-b2h () - (string= "䷧" (i-ching-binary-to-hexagram #b010100))) + (string= "䷧" (i-ching-binary-to-hexagram #b010100))) -(ert-deftest i-ching-name () - (string= "HEXAGRAM FOR BEFORE COMPLETION" (i-ching-number-to-unicode-name 64))) + +(ert-deftest i-ching-names () + (should-not (i-ching-number-to-name 65)) + (should (string= "HEXAGRAM FOR BEFORE COMPLETION" + (i-ching-number-to-unicode-name 64))) + (should (string= "Before Completion" + (i-ching-number-to-name 64)))) + +(ert-deftest i-ching-descriptions () + (should (stringp (i-ching-number-to-description 43))) + (should (stringp (i-ching-number-to-judgment 27))) + (should (stringp (i-ching-number-to-image 13))) + (should-not (stringp (i-ching-number-to-description 65))) + (should-not (stringp (i-ching-number-to-judgment 65))) + (should-not (stringp (i-ching-number-to-image 65)))) + +(ert-deftest i-ching-all-descriptions () + (dotimes (i 63) + (should-not (seq-empty-p (i-ching-number-to-unicode-name (1+ i)))) + (should-not (seq-empty-p (i-ching-number-to-description (1+ i)))) + (should-not (seq-empty-p (i-ching-number-to-judgment (1+ i)))) + (should-not (seq-empty-p (i-ching-number-to-image (1+ i)))) + (should-not (seq-empty-p (i-ching-number-to-name (1+ i)))) + (should (stringp (i-ching-number-to-unicode-name (1+ i)))) + (should (stringp (i-ching-number-to-description (1+ i)))) + (should (stringp (i-ching-number-to-judgment (1+ i)))) + (should (stringp (i-ching-number-to-image (1+ i)))) + (should (stringp (i-ching-number-to-name (1+ i)))))) + +(ert-deftest i-ching-interprets () + (should (stringp (i-ching-interpretation 49))) + (should-not (seq-empty-p (i-ching-interpretation 49)))) + +(ert-deftest i-ching-queries () + (should (stringp (i-ching-query-string))) + (should (stringp (i-ching-query-string '3-coins)))) (ert-deftest i-ching-castings () - (should (stringp (i-ching-cast 'yarrow-stalks))) - (should (stringp (i-ching-cast '3-coins))) - (should (stringp (i-ching-cast)))) + (should (stringp (i-ching-cast 'yarrow-stalks))) + (should (stringp (i-ching-cast '3-coins))) + (should (stringp (i-ching-cast)))) ;; (i-ching-query '6-bit) ;; (i-ching-query '3-coins) ;; (i-ching-query 'yarrow-stalks) +;; interactive testing + +(ert-deftest i-ching-query-6bit () + (should (with-simulated-input + "testing SPC circumstances RET" + (i-ching-query '6-bit)))) + +(ert-deftest i-ching-query-3coin () + (should (with-simulated-input + "testing SPC circumstances RET" + (i-ching-query '3-coins)))) + +(ert-deftest i-ching-query-yarrow () + (should (with-simulated-input + "testing SPC circumstances RET" + (i-ching-query 'yarrow-stalks)))) + +;; run them... + (ert t) ;;; tests.el ends here