Refactor codec test
This commit is contained in:
@@ -4,32 +4,25 @@ import "testing"
|
|||||||
|
|
||||||
// TestEncrypt tests the Encrypt and Decrypt function.
|
// TestEncrypt tests the Encrypt and Decrypt function.
|
||||||
func TestCryptDecrypt(t *testing.T) {
|
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.
|
// Run the test cases.
|
||||||
for _, tt := range []Case{
|
for _, tc := range []struct {
|
||||||
{"Test encrypt-decrypt: simple text",
|
name, A, B string
|
||||||
5, "clark", "hqfwp"},
|
key int
|
||||||
{"Test encrypt-decrypt: text with shifted outbounds chars",
|
}{
|
||||||
3, "cherry blossom", "fkhuub eorvvrp"},
|
{"Test encrypt-decrypt: Simple text",
|
||||||
{"Test encrypt-decrypt: text with shifted outbounds chars and non-letter chars",
|
"clark", "hqfwp", 5},
|
||||||
3, "cherry123 blossom!", "fkhuub123 eorvvrp!"},
|
{"Test encrypt-decrypt: Text with shifted outbounds chars",
|
||||||
|
"cherry blossom", "fkhuub eorvvrp", 3},
|
||||||
|
{"Test encrypt-decrypt: Text with shifted outbounds chars and non-letter chars",
|
||||||
|
"cherry123 blossom!", "fkhuub123 eorvvrp!", 3},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
enc := Encrypt(tt.A, tt.key)
|
if enc := Encrypt(tc.A, tc.key); enc != tc.B {
|
||||||
if enc != tt.B {
|
t.Errorf("Encrypt() = %v, want %v", enc, tc.B)
|
||||||
t.Errorf("Encrypt() = %v, want %v", enc, tt.B)
|
|
||||||
}
|
}
|
||||||
dec := Decrypt(enc, tt.key)
|
|
||||||
if dec != tt.A {
|
if dec := Decrypt(tc.B, tc.key); dec != tc.A {
|
||||||
t.Errorf("Decrypt() = %v, want %v", dec, tt.A)
|
t.Errorf("Decrypt() = %v, want %v", dec, tc.A)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user