37 lines
873 B
Go
37 lines
873 B
Go
package deesee
|
|
|
|
import "testing"
|
|
|
|
// TestEncrypt tests the Encrypt and Decrypt function.
|
|
func TestCryptDecrypt(t *testing.T) {
|
|
|
|
// Case is a struct to store test cases.
|
|
type Case struct {
|
|
name string
|
|
key int
|
|
A string
|
|
B string
|
|
}
|
|
|
|
// Run the test cases.
|
|
for _, tt := range []Case{
|
|
{"Test encrypt-decrypt: simple text",
|
|
5, "clark", "hqfwp"},
|
|
{"Test encrypt-decrypt: text with shifted outbounds chars",
|
|
3, "cherry blossom", "fkhuub eorvvrp"},
|
|
{"Test encrypt-decrypt: text with shifted outbounds chars and non-letter chars",
|
|
3, "cherry123 blossom!", "fkhuub123 eorvvrp!"},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
enc := Encrypt(tt.A, tt.key)
|
|
if enc != tt.B {
|
|
t.Errorf("Encrypt() = %v, want %v", enc, tt.B)
|
|
}
|
|
dec := Decrypt(enc, tt.key)
|
|
if dec != tt.A {
|
|
t.Errorf("Decrypt() = %v, want %v", dec, tt.A)
|
|
}
|
|
})
|
|
}
|
|
}
|