added tests for all current transposition ciphers

This commit is contained in:
Derek McQuay 2016-02-12 09:35:52 -08:00
parent 3a3d52aca1
commit e0ee206df9

View File

@ -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,
)
}
}