Skip to content

Commit 9c2d084

Browse files
authored
atbash-cipher: Sync tests with problem specifications (#730)
* update .toml file with latest descriptions * implement tests * update starter file with proper function templates * update example solution * update contributors * remove the last two tests [no important files changed]
1 parent 17031f9 commit 9c2d084

File tree

5 files changed

+119
-51
lines changed

5 files changed

+119
-51
lines changed

exercises/practice/atbash-cipher/.meta/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"kytrinyx",
1111
"mathias",
1212
"sjwarner-bp",
13-
"yurrriq"
13+
"yurrriq",
14+
"tasxatzial"
1415
],
1516
"files": {
1617
"solution": [
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns atbash-cipher
2-
(:require [clojure.string :as str]))
2+
(:require [clojure.set]
3+
[clojure.string :as str]))
34

45
(def ^:private letters
56
(map char
@@ -9,14 +10,25 @@
910
(apply hash-map
1011
(interleave letters (reverse letters))))
1112

13+
(def ^:private from-cipher
14+
(clojure.set/map-invert to-cipher))
15+
1216
(defn- sanitize
1317
[plaintext]
1418
(str/replace (str/lower-case plaintext) #"\W" ""))
1519

16-
(defn- cipher
20+
(defn- remove-spaces
21+
[ciphertext]
22+
(str/replace ciphertext #" " ""))
23+
24+
(defn- cipher-char
1725
[plain-char]
1826
(or (to-cipher plain-char) plain-char))
1927

28+
(defn- plain-char
29+
[cipher-char]
30+
(or (from-cipher cipher-char) cipher-char))
31+
2032
(defn- to-chunks
2133
[character-list]
2234
(map #(apply str %) (partition 5 5 "" character-list)))
@@ -25,6 +37,13 @@
2537
[plaintext]
2638
(->> plaintext
2739
sanitize
28-
(map cipher)
40+
(map cipher-char)
2941
to-chunks
3042
(str/join " ")))
43+
44+
(defn decode
45+
[ciphertext]
46+
(->> ciphertext
47+
remove-spaces
48+
(map plain-char)
49+
(apply str)))
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,54 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[2f47ebe1-eab9-4d6b-b3c6-627562a31c77]
6-
description = "encode yes"
13+
description = "encode -> encode yes"
714

815
[b4ffe781-ea81-4b74-b268-cc58ba21c739]
9-
description = "encode no"
16+
description = "encode -> encode no"
1017

1118
[10e48927-24ab-4c4d-9d3f-3067724ace00]
12-
description = "encode OMG"
19+
description = "encode -> encode OMG"
1320

1421
[d59b8bc3-509a-4a9a-834c-6f501b98750b]
15-
description = "encode spaces"
22+
description = "encode -> encode spaces"
1623

1724
[31d44b11-81b7-4a94-8b43-4af6a2449429]
18-
description = "encode mindblowingly"
25+
description = "encode -> encode mindblowingly"
1926

2027
[d503361a-1433-48c0-aae0-d41b5baa33ff]
21-
description = "encode numbers"
28+
description = "encode -> encode numbers"
2229

2330
[79c8a2d5-0772-42d4-b41b-531d0b5da926]
24-
description = "encode deep thought"
31+
description = "encode -> encode deep thought"
2532

2633
[9ca13d23-d32a-4967-a1fd-6100b8742bab]
27-
description = "encode all the letters"
34+
description = "encode -> encode all the letters"
2835

2936
[bb50e087-7fdf-48e7-9223-284fe7e69851]
30-
description = "decode exercism"
37+
description = "decode -> decode exercism"
3138

3239
[ac021097-cd5d-4717-8907-b0814b9e292c]
33-
description = "decode a sentence"
40+
description = "decode -> decode a sentence"
3441

3542
[18729de3-de74-49b8-b68c-025eaf77f851]
36-
description = "decode numbers"
43+
description = "decode -> decode numbers"
3744

3845
[0f30325f-f53b-415d-ad3e-a7a4f63de034]
39-
description = "decode all the letters"
46+
description = "decode -> decode all the letters"
4047

4148
[39640287-30c6-4c8c-9bac-9d613d1a5674]
42-
description = "decode with too many spaces"
49+
description = "decode -> decode with too many spaces"
50+
include = false
4351

4452
[b34edf13-34c0-49b5-aa21-0768928000d5]
45-
description = "decode with no spaces"
53+
description = "decode -> decode with no spaces"
54+
include = false
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
(ns atbash-cipher)
22

3-
(defn encode [] ;; <- arglist goes here
4-
;; your code goes here
5-
)
3+
(defn encode
4+
[s]
5+
;; function body
6+
)
7+
8+
(defn decode
9+
[s]
10+
;; function body
11+
)
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,63 @@
11
(ns atbash-cipher-test
2-
(:require [clojure.test :refer [deftest is]]
2+
(:require [clojure.test :refer [deftest testing is]]
33
atbash-cipher))
44

5-
(deftest encode-no
6-
(is (= "ml" (atbash-cipher/encode "no"))))
7-
8-
(deftest encode-yes
9-
(is (= "bvh" (atbash-cipher/encode "yes"))))
10-
11-
(deftest encode-OMG
12-
(is (= "lnt" (atbash-cipher/encode "OMG"))))
13-
14-
(deftest encode-O-M-G
15-
(is (= "lnt" (atbash-cipher/encode "O M G"))))
16-
17-
(deftest encode-long-word
18-
(is (= "nrmwy oldrm tob" (atbash-cipher/encode "mindblowingly"))))
19-
20-
(deftest encode-numbers
21-
(is (= "gvhgr mt123 gvhgr mt"
22-
(atbash-cipher/encode "Testing, 1 2 3, testing."))))
23-
24-
(deftest encode-sentence
25-
(is (= "gifgs rhurx grlm" (atbash-cipher/encode "Truth is fiction."))))
26-
27-
(deftest encode-all-the-things
28-
(let [plaintext "The quick brown fox jumps over the lazy dog."
29-
cipher "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"]
30-
(is (= cipher (atbash-cipher/encode plaintext)))))
5+
(deftest encode_test_1
6+
(testing "encode -> encode yes"
7+
(is (= "bvh"
8+
(atbash-cipher/encode "yes")))))
9+
10+
(deftest encode_test_2
11+
(testing "encode -> encode no"
12+
(is (= "ml"
13+
(atbash-cipher/encode "no")))))
14+
15+
(deftest encode_test_3
16+
(testing "encode -> encode OMG"
17+
(is (= "lnt"
18+
(atbash-cipher/encode "OMG")))))
19+
20+
(deftest encode_test_4
21+
(testing "encode -> encode spaces"
22+
(is (= "lnt"
23+
(atbash-cipher/encode "O M G")))))
24+
25+
(deftest encode_test_5
26+
(testing "encode -> encode mindblowingly"
27+
(is (= "nrmwy oldrm tob"
28+
(atbash-cipher/encode "mindblowingly")))))
29+
30+
(deftest encode_test_6
31+
(testing "encode -> encode numbers"
32+
(is (= "gvhgr mt123 gvhgr mt"
33+
(atbash-cipher/encode "Testing, 1 2 3, testing.")))))
34+
35+
(deftest encode_test_7
36+
(testing "encode -> encode deep thought"
37+
(is (= "gifgs rhurx grlm"
38+
(atbash-cipher/encode "Truth is fiction.")))))
39+
40+
(deftest encode_test_8
41+
(testing "encode -> encode all the letters"
42+
(is (= "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
43+
(atbash-cipher/encode "The quick brown fox jumps over the lazy dog.")))))
44+
45+
(deftest decode_test_1
46+
(testing "decode -> decode exercism"
47+
(is (= "exercism"
48+
(atbash-cipher/decode "vcvix rhn")))))
49+
50+
(deftest decode_test_2
51+
(testing "decode -> decode a sentence"
52+
(is (= "anobstacleisoftenasteppingstone"
53+
(atbash-cipher/decode "zmlyh gzxov rhlug vmzhg vkkrm thglm v")))))
54+
55+
(deftest decode_test_3
56+
(testing "decode -> decode numbers"
57+
(is (= "testing123testing"
58+
(atbash-cipher/decode "gvhgr mt123 gvhgr mt")))))
59+
60+
(deftest decode_test_4
61+
(testing "decode -> decode all the letters"
62+
(is (= "thequickbrownfoxjumpsoverthelazydog"
63+
(atbash-cipher/decode "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")))))

0 commit comments

Comments
 (0)