Skip to content

Commit fab965c

Browse files
authored
Merge pull request #197 from mcaci/caesar-test
add tests for Caesar cipher
2 parents e6864ff + 7baf3b5 commit fab965c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
File renamed without changes.

ciphers/caesar/caesar_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
var caesarTestData = []struct {
8+
description string
9+
input string
10+
key int
11+
expected string
12+
}{
13+
{
14+
"Basic caesar encryption with letter 'a'",
15+
"a",
16+
3,
17+
"d",
18+
},
19+
{
20+
"Basic caesar encryption wrap around alphabet on letter 'z'",
21+
"z",
22+
3,
23+
"c",
24+
},
25+
{
26+
"Encrypt a simple string with ceasar encryiption",
27+
"hello",
28+
3,
29+
"khoor",
30+
},
31+
{
32+
"Encrypt a simple string with key 13",
33+
"hello",
34+
13,
35+
"uryyb",
36+
},
37+
{
38+
"Encrypt a simple string with key -13",
39+
"hello",
40+
-13,
41+
"uryyb",
42+
},
43+
{
44+
"With key of 26 output should be the same as the input",
45+
"no change",
46+
26,
47+
"no change",
48+
},
49+
{
50+
"Encrpyt sentence with key 10",
51+
"the quick brown fox jumps over the lazy dog.",
52+
10,
53+
"dro aesmu lbygx pyh tewzc yfob dro vkji nyq.",
54+
},
55+
}
56+
57+
func TestCeasarCipher(t *testing.T) {
58+
for _, test := range caesarTestData {
59+
t.Run(test.description, func(t *testing.T) {
60+
actual := caesarCipher(test.input, test.key)
61+
if actual != test.expected {
62+
t.Logf("FAIL: %s", test.description)
63+
t.Fatalf("With input string '%s' and key '%d' was expecting '%s' but actual was '%s'",
64+
test.input, test.key, test.expected, actual)
65+
}
66+
})
67+
}
68+
}

0 commit comments

Comments
 (0)