Skip to content

Commit fd006da

Browse files
tqa236yawpitch
authored andcommitted
Add test template for atbash cipher (#2123)
* Add test template for atbash cipher * Change variable name * Fix assert type * User assertEqual everywhere
1 parent da481fe commit fd006da

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.header() }}
3+
4+
class {{ exercise | camel_case }}Test(unittest.TestCase):
5+
{% for case in cases -%}
6+
{% for subcase in case["cases"] -%}
7+
def test_{{ subcase["description"] | to_snake }}(self):
8+
{% set value = subcase["input"]["phrase"] -%}
9+
{% set expected = subcase["expected"] -%}
10+
self.assertEqual({{ subcase["property"] }}("{{ value }}"), "{{ expected }}")
11+
{% endfor %}
12+
13+
{% endfor %}
14+
15+
{{ macros.footer() }}

exercises/atbash-cipher/atbash_cipher_test.py

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,63 @@
22

33
from atbash_cipher import decode, encode
44

5-
65
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
76

8-
class AtbashCipherTest(unittest.TestCase):
9-
def test_encode_no(self):
10-
self.assertMultiLineEqual(encode("no"), "ml")
117

8+
class AtbashCipherTest(unittest.TestCase):
129
def test_encode_yes(self):
13-
self.assertMultiLineEqual(encode("yes"), "bvh")
10+
self.assertEqual(encode("yes"), "bvh")
1411

15-
def test_encode_OMG(self):
16-
self.assertMultiLineEqual(encode("OMG"), "lnt")
12+
def test_encode_no(self):
13+
self.assertEqual(encode("no"), "ml")
14+
15+
def test_encode_omg(self):
16+
self.assertEqual(encode("OMG"), "lnt")
1717

18-
def test_encode_O_M_G(self):
19-
self.assertMultiLineEqual(encode("O M G"), "lnt")
18+
def test_encode_spaces(self):
19+
self.assertEqual(encode("O M G"), "lnt")
2020

21-
def test_encode_long_word(self):
22-
self.assertMultiLineEqual(encode("mindblowingly"), "nrmwy oldrm tob")
21+
def test_encode_mindblowingly(self):
22+
self.assertEqual(encode("mindblowingly"), "nrmwy oldrm tob")
2323

2424
def test_encode_numbers(self):
25-
self.assertMultiLineEqual(
26-
encode("Testing, 1 2 3, testing."), "gvhgr mt123 gvhgr mt")
25+
self.assertEqual(encode("Testing,1 2 3, testing."), "gvhgr mt123 gvhgr mt")
2726

28-
def test_encode_sentence(self):
29-
self.assertMultiLineEqual(
30-
encode("Truth is fiction."), "gifgs rhurx grlm")
27+
def test_encode_deep_thought(self):
28+
self.assertEqual(encode("Truth is fiction."), "gifgs rhurx grlm")
3129

32-
def test_encode_all_things(self):
33-
plaintext = "The quick brown fox jumps over the lazy dog."
34-
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
35-
self.assertMultiLineEqual(encode(plaintext), ciphertext)
30+
def test_encode_all_the_letters(self):
31+
self.assertEqual(
32+
encode("The quick brown fox jumps over the lazy dog."),
33+
"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt",
34+
)
3635

37-
def test_decode_word(self):
38-
self.assertMultiLineEqual(decode("vcvix rhn"), "exercism")
36+
def test_decode_exercism(self):
37+
self.assertEqual(decode("vcvix rhn"), "exercism")
3938

40-
def test_decode_sentence(self):
41-
self.assertMultiLineEqual(
39+
def test_decode_a_sentence(self):
40+
self.assertEqual(
4241
decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"),
43-
"anobstacleisoftenasteppingstone")
42+
"anobstacleisoftenasteppingstone",
43+
)
4444

4545
def test_decode_numbers(self):
46-
self.assertMultiLineEqual(
47-
decode("gvhgr mt123 gvhgr mt"), "testing123testing")
46+
self.assertEqual(decode("gvhgr mt123 gvhgr mt"), "testing123testing")
4847

4948
def test_decode_all_the_letters(self):
50-
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
51-
plaintext = "thequickbrownfoxjumpsoverthelazydog"
52-
self.assertMultiLineEqual(decode(ciphertext), plaintext)
49+
self.assertEqual(
50+
decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"),
51+
"thequickbrownfoxjumpsoverthelazydog",
52+
)
5353

5454
def test_decode_with_too_many_spaces(self):
55-
self.assertMultiLineEqual(decode("vc vix r hn"), "exercism")
55+
self.assertEqual(decode("vc vix r hn"), "exercism")
5656

5757
def test_decode_with_no_spaces(self):
58-
ciphertext = "zmlyhgzxovrhlugvmzhgvkkrmthglmv"
59-
plaintext = "anobstacleisoftenasteppingstone"
60-
self.assertMultiLineEqual(decode(ciphertext), plaintext)
61-
62-
# additional track specific test
63-
def test_encode_decode(self):
64-
self.assertMultiLineEqual(
65-
decode(encode("Testing, 1 2 3, testing.")), "testing123testing")
58+
self.assertEqual(
59+
decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv"), "anobstacleisoftenasteppingstone"
60+
)
6661

6762

68-
if __name__ == '__main__':
63+
if __name__ == "__main__":
6964
unittest.main()

0 commit comments

Comments
 (0)