From 787cfaaf6620a042b6299b658620da4f5157fa8c Mon Sep 17 00:00:00 2001 From: Kevin Marker Date: Fri, 14 Jun 2024 19:48:57 -0500 Subject: [PATCH] fix [Improve Practice Exercise] Atbash Cipher #386 (#403) --- .../practice/atbash-cipher/.meta/config.json | 3 +- .../practice/atbash-cipher/.meta/example.el | 4 +++ .../atbash-cipher/atbash-cipher-test.el | 36 ++++++++++++++----- .../practice/atbash-cipher/atbash-cipher.el | 6 ++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/exercises/practice/atbash-cipher/.meta/config.json b/exercises/practice/atbash-cipher/.meta/config.json index 1c24ea9a..7bcaa351 100644 --- a/exercises/practice/atbash-cipher/.meta/config.json +++ b/exercises/practice/atbash-cipher/.meta/config.json @@ -3,7 +3,8 @@ "canweriotnow" ], "contributors": [ - "vermiculus" + "vermiculus", + "kmarker1101" ], "files": { "solution": [ diff --git a/exercises/practice/atbash-cipher/.meta/example.el b/exercises/practice/atbash-cipher/.meta/example.el index a133fcf4..3fb8eaba 100644 --- a/exercises/practice/atbash-cipher/.meta/example.el +++ b/exercises/practice/atbash-cipher/.meta/example.el @@ -12,6 +12,10 @@ "Encode PLAINTEXT to atbash-cipher encoding." (to-string (group (to-cipher-seq plaintext)))) +(defun decode (ciphertext) + "Decode CIPHERTEXT from atbash-cipher encoding." + (to-string (cleanup-ciphered-seq (cl-map 'list #'encipher ciphertext)))) + (defun to-string (seq) "Convert SEQ of characters to a string." (cl-concatenate 'string seq)) diff --git a/exercises/practice/atbash-cipher/atbash-cipher-test.el b/exercises/practice/atbash-cipher/atbash-cipher-test.el index 01f449ab..d923ba50 100644 --- a/exercises/practice/atbash-cipher/atbash-cipher-test.el +++ b/exercises/practice/atbash-cipher/atbash-cipher-test.el @@ -7,37 +7,57 @@ (require 'cl-lib) (load-file "atbash-cipher.el") + (declare-function encode "atbash-cipher.el" (plaintext)) +(declare-function decode "atbash-cipher.el" (plaintext)) (ert-deftest encode-no () - (should (equal "ml" (encode "no")))) + (should (string= "ml" (encode "no")))) (ert-deftest encode-yes () - (should (equal "bvh" (encode "yes")))) + (should (string= "bvh" (encode "yes")))) (ert-deftest encode-OMG () - (should (equal "lnt" (encode "OMG")))) + (should (string= "lnt" (encode "OMG")))) (ert-deftest encode-O-M-G () - (should (equal "lnt" (encode "O M G")))) + (should (string= "lnt" (encode "O M G")))) (ert-deftest encode-long-word () - (should (equal "nrmwy oldrm tob" + (should (string= "nrmwy oldrm tob" (encode "mindblowingly")))) (ert-deftest encode-numbers () - (should (equal "gvhgr mt123 gvhgr mt" + (should (string= "gvhgr mt123 gvhgr mt" (encode "Testing, 1 2 3, testing.")))) (ert-deftest encode-sentence () - (should (equal "gifgs rhurx grlm" + (should (string= "gifgs rhurx grlm" (encode "Truth is fiction.")))) (ert-deftest encode-all-the-things () (let ((plaintext "The quick brown fox jumps over the lazy dog.") (ciphertext "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")) - (should (equal ciphertext + (should (string= ciphertext (encode plaintext))))) +(ert-deftest decode-exercism () + (should (string= "exercism" (decode "vcvix rhn")))) + +(ert-deftest decode-a-sentence () + (should (string= "anobstacleisoftenasteppingstone" (decode "zmlyh gzxov rhlug vmzhg vkkrm thglm v")))) + +(ert-deftest decode-numbers () + (should (string= "testing123testing" (decode "gvhgr mt123 gvhgr mt")))) + +(ert-deftest decode-all-the-letters () + (should (string= "thequickbrownfoxjumpsoverthelazydog" (decode "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")))) + +(ert-deftest decode-with-two-many-spaces () + (should (string= "exercism" (decode "vc vix r hn")))) + +(ert-deftest decode-with-no-spaces () + (should (string= "anobstacleisoftenasteppingstone" (decode "zmlyhgzxovrhlugvmzhgvkkrmthglmv")))) + (provide 'atbash-cipher-test) ;;; atbash-cipher-test.el ends here diff --git a/exercises/practice/atbash-cipher/atbash-cipher.el b/exercises/practice/atbash-cipher/atbash-cipher.el index 3017d19d..e2148961 100644 --- a/exercises/practice/atbash-cipher/atbash-cipher.el +++ b/exercises/practice/atbash-cipher/atbash-cipher.el @@ -7,5 +7,11 @@ ;;; Code: ) +(defun decode (plaintext) + "Decode atbash-cipher encoding to PLAINTEXT." + ;;; Code: +) + + (provide 'atbash-cipher) ;;; atbash-cipher.el ends here