Skip to content

Commit

Permalink
fix [Improve Practice Exercise] Atbash Cipher exercism#386 (exercism#403
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kmarker1101 authored Jun 15, 2024
1 parent ef5dce3 commit 787cfaa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
3 changes: 2 additions & 1 deletion exercises/practice/atbash-cipher/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"canweriotnow"
],
"contributors": [
"vermiculus"
"vermiculus",
"kmarker1101"
],
"files": {
"solution": [
Expand Down
4 changes: 4 additions & 0 deletions exercises/practice/atbash-cipher/.meta/example.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
36 changes: 28 additions & 8 deletions exercises/practice/atbash-cipher/atbash-cipher-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions exercises/practice/atbash-cipher/atbash-cipher.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
;;; Code:
)

(defun decode (plaintext)
"Decode atbash-cipher encoding to PLAINTEXT."
;;; Code:
)


(provide 'atbash-cipher)
;;; atbash-cipher.el ends here

0 comments on commit 787cfaa

Please sign in to comment.