Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix [Improve Practice Exercise] Atbash Cipher #386 #403

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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