Skip to content

Commit ccdf1d7

Browse files
committed
Add atbash-cipher decode tests
These tests were never implemented (but were listed in the tests.toml file as if they had been).
1 parent 615668c commit ccdf1d7

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

exercises/practice/atbash-cipher/.meta/example.lisp

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(defpackage :atbash-cipher
22
(:use :common-lisp)
3-
(:export :encode))
3+
(:export :encode :decode))
44

55
(in-package :atbash-cipher)
66

@@ -22,6 +22,11 @@
2222

2323
(defun lookup-char (c) (cdr (assoc c +key+)))
2424

25+
(defun normalize (str)
26+
(remove-if-not #'alphanumericp (string-downcase str)))
27+
2528
(defun encode (plaintext)
26-
(let ((filtered (remove-if-not #'alphanumericp (string-downcase plaintext))))
27-
(to-string (group (map 'list #'lookup-char filtered)))))
29+
(to-string (group (map 'list #'lookup-char (normalize plaintext)))))
30+
31+
(defun decode (ciphertext)
32+
(map 'string #'lookup-char (normalize ciphertext)))

exercises/practice/atbash-cipher/atbash-cipher-test.lisp

+33-7
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,56 @@
1515
;; Define and enter a new FiveAM test-suite
1616
(def-suite* atbash-cipher-suite)
1717

18-
(test encode-no (is (equal "ml" (atbash-cipher:encode "no"))))
18+
(def-suite* encode :in atbash-cipher-suite)
1919

2020
(test encode-yes (is (equal "bvh" (atbash-cipher:encode "yes"))))
2121

22+
(test encode-no (is (equal "ml" (atbash-cipher:encode "no"))))
23+
2224
(test encode-omg (is (equal "lnt" (atbash-cipher:encode "OMG"))))
2325

24-
(test encode-o-m-g (is (equal "lnt" (atbash-cipher:encode "O M G"))))
26+
(test encode-spaces (is (equal "lnt" (atbash-cipher:encode "O M G"))))
2527

26-
(test encode-long-word
27-
(is (equal "nrmwy oldrm tob" (atbash-cipher:encode "mindblowingly"))))
28+
(test encode-mindblowingly
29+
(is (equal "nrmwy oldrm tob" (atbash-cipher:encode "mindblowingly"))))
2830

2931
(test encode-numbers
3032
(is
3133
(equal "gvhgr mt123 gvhgr mt"
3234
(atbash-cipher:encode "Testing, 1 2 3, testing."))))
3335

34-
(test encode-sentence
35-
(is (equal "gifgs rhurx grlm" (atbash-cipher:encode "Truth is fiction."))))
36+
(test encode-deep-thought
37+
(is (equal "gifgs rhurx grlm" (atbash-cipher:encode "Truth is fiction."))))
3638

37-
(test encode-all-the-things
39+
(test encode-all-the-letters
3840
(let ((plaintext "The quick brown fox jumps over the lazy dog.")
3941
(cipher "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"))
4042
(is (equal cipher (atbash-cipher:encode plaintext)))))
4143

44+
(def-suite* decode :in atbash-cipher-suite)
45+
46+
(test decode-exercism
47+
(is (equal "exercism" (atbash-cipher:decode "vcvix rhn"))))
48+
49+
(test decode-a-sentence
50+
(is (equal "anobstacleisoftenasteppingstone"
51+
(atbash-cipher:decode "zmlyh gzxov rhlug vmzhg vkkrm thglm v"))))
52+
53+
(test decode-numbers
54+
(is (equal "testing123testing" (atbash-cipher:decode "gvhgr mt123 gvhgr mt"))))
55+
56+
(test decode-all-the-letters
57+
(is (equal "thequickbrownfoxjumpsoverthelazydog"
58+
(atbash-cipher:decode "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"))))
59+
60+
(test decode-with-too-many-spaces
61+
(is (equal "exercism"
62+
(atbash-cipher:decode "vc vix r hn"))))
63+
64+
(test decode-with-no-spaces
65+
(is (equal "anobstacleisoftenasteppingstone"
66+
(atbash-cipher:decode "zmlyhgzxovrhlugvmzhgvkkrmthglmv"))))
67+
4268
(defun run-tests (&optional (test-or-suite 'atbash-cipher-suite))
4369
"Provides human readable results of test run. Default to entire suite."
4470
(run! test-or-suite))
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(defpackage :atbash-cipher
22
(:use :cl)
3-
(:export :encode))
3+
(:export :encode :decode))
44

55
(in-package :atbash-cipher)
66

77
(defun encode (plaintext))
8+
9+
(defun decode (ciphertext))

0 commit comments

Comments
 (0)