|
@@ -0,0 +1,85 @@
|
|
|
+package kata_test
|
|
|
+
|
|
|
+import (
|
|
|
+ "strings"
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ . "github.com/onsi/ginkgo"
|
|
|
+ . "github.com/onsi/gomega"
|
|
|
+
|
|
|
+ . "code.osinet.fr/fgm/codewars/kyu5/second_variation_on_caesar_cipher"
|
|
|
+)
|
|
|
+
|
|
|
+func doTest1(s string, shift int, exp []string) {
|
|
|
+ var ans = Encode(s, shift)
|
|
|
+ Expect(ans).To(Equal(exp))
|
|
|
+}
|
|
|
+func doTest2(arr []string, exp string) {
|
|
|
+ var ans = Decode(arr)
|
|
|
+ Expect(ans).To(Equal(exp))
|
|
|
+}
|
|
|
+
|
|
|
+var _ = Describe("Tests", func() {
|
|
|
+
|
|
|
+ It("should handle basic cases Encode", func() {
|
|
|
+ var u = "I should have known that you would have a perfect answer for me!!!"
|
|
|
+ var v = []string{"ijJ tipvme ibw", "f lopxo uibu z", "pv xpvme ibwf ", "b qfsgfdu botx", "fs gps nf!!!"}
|
|
|
+ doTest1(u, 1, v)
|
|
|
+
|
|
|
+ u = "abcdefghjuty12"
|
|
|
+ v = []string{"abbc", "defg", "hikv", "uz12"}
|
|
|
+ doTest1(u, 1, v)
|
|
|
+
|
|
|
+ })
|
|
|
+ It("should handle basic cases Decode", func() {
|
|
|
+ var u = "I should have known that you would have a perfect answer for me!!!"
|
|
|
+ var v = []string{"ijJ tipvme ibw", "f lopxo uibu z", "pv xpvme ibwf ", "b qfsgfdu botx", "fs gps nf!!!"}
|
|
|
+ doTest2(v, u)
|
|
|
+
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+func TestChunk(t *testing.T) {
|
|
|
+ checks := [...]struct{ len, four, last int }{
|
|
|
+ {45, 9, 9,},
|
|
|
+ {46, 10, 6},
|
|
|
+ {47, 10, 7},
|
|
|
+ {48, 10, 8},
|
|
|
+ {49, 10, 9},
|
|
|
+ {50, 10, 10},
|
|
|
+ {51, 11, 7},
|
|
|
+ {52, 11, 8},
|
|
|
+ {68, 14, 12},
|
|
|
+ }
|
|
|
+ for _, check := range checks {
|
|
|
+ s := strings.Repeat(" ", check.len)
|
|
|
+ actualFour := Chunk(s, 0)
|
|
|
+ actualLast := Chunk(s, 4)
|
|
|
+ if len(actualFour) != check.four {
|
|
|
+ t.Errorf("len %d four expected %d got %d", check.len, check.four, len(actualFour))
|
|
|
+ }
|
|
|
+ if len(actualLast) != check.last {
|
|
|
+ t.Errorf("len %d last expected %d got %d", check.len, check.last, len(actualLast))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestPrefix(t *testing.T) {
|
|
|
+ checks := [...]struct {
|
|
|
+ s string
|
|
|
+ shift int
|
|
|
+ expected string
|
|
|
+ }{
|
|
|
+ {"John", 1, "jk"},
|
|
|
+ {"Yann", 2, "ya"},
|
|
|
+ {"war", 4, "wa"},
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, check := range checks {
|
|
|
+ actual := string(Prefix(check.s, check.shift))
|
|
|
+ if actual != check.expected {
|
|
|
+ t.Errorf("%v by %d: expected %s, got %s", check.s, check.shift, check.expected, actual)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|