From e0ee206df991dd3f502dbffafe19180da531312c Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Fri, 12 Feb 2016 09:35:52 -0800 Subject: [PATCH] added tests for all current transposition ciphers --- psyfer/transposition_test.go | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 psyfer/transposition_test.go diff --git a/psyfer/transposition_test.go b/psyfer/transposition_test.go new file mode 100644 index 0000000..3127ec9 --- /dev/null +++ b/psyfer/transposition_test.go @@ -0,0 +1,111 @@ +package psyfer + +import "testing" + +func TestTransposeRailFence(t *testing.T) { + input := "helloworld" + expected := "hloolelwrd" + actual := TransposeRailFence(input) + if expected != actual { + t.Errorf( + "failed TransposeRailFence:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "123456" + expected = "135246" + actual = TransposeRailFence(input) + if expected != actual { + t.Errorf( + "failed TransposeRailFence:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "1" + expected = "1" + actual = TransposeRailFence(input) + if expected != actual { + t.Errorf( + "failed TransposeRailFence:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "" + expected = "" + actual = TransposeRailFence(input) + if expected != actual { + t.Errorf( + "failed TransposeRailFence:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } +} + +func TestTransposeSplit(t *testing.T) { + input := "helloworld" + expected := "hweolrllod" + actual := TransposeSplit(input) + if expected != actual { + t.Errorf( + "failed TransposeSplit:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "1234567" + expected = "1425367" + actual = TransposeSplit(input) + if expected != actual { + t.Errorf( + "failed TransposeSplit:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "123" + expected = "123" + actual = TransposeSplit(input) + if expected != actual { + t.Errorf( + "failed TransposeSplit:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "1" + expected = "1" + actual = TransposeSplit(input) + if expected != actual { + t.Errorf( + "failed TransposeSplit:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } + input = "" + expected = "" + actual = TransposeSplit(input) + if expected != actual { + t.Errorf( + "failed TransposeSplit:\n\texpected: % x\n\t actual: % x", + expected, + actual, + ) + } +} + +func TestTransposeRandom(t *testing.T) { + input := "123456789abcdefghijklmnopqrstuvwxyz" + actual := TransposeSplit(input) + if input == actual { + t.Errorf( + "failed TransposeRandom:\n\texpected: something random\n\t actual: % x", + input, + actual, + ) + } +}