From 3507805c293289c2f414cd04ed39a3b699298a05 Mon Sep 17 00:00:00 2001 From: Andriy Oblivantsev Date: Tue, 7 Feb 2023 05:31:13 +0000 Subject: [PATCH] Refactor codec test --- pkg/deesee/codec_test.go | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/pkg/deesee/codec_test.go b/pkg/deesee/codec_test.go index 5a393d5..33ff5d6 100644 --- a/pkg/deesee/codec_test.go +++ b/pkg/deesee/codec_test.go @@ -4,32 +4,25 @@ 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!"}, + for _, tc := range []struct { + name, A, B string + key int + }{ + {"Test encrypt-decrypt: Simple text", + "clark", "hqfwp", 5}, + {"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) { - enc := Encrypt(tt.A, tt.key) - if enc != tt.B { - t.Errorf("Encrypt() = %v, want %v", enc, tt.B) + t.Run(tc.name, func(t *testing.T) { + if enc := Encrypt(tc.A, tc.key); enc != tc.B { + t.Errorf("Encrypt() = %v, want %v", enc, tc.B) } - dec := Decrypt(enc, tt.key) - if dec != tt.A { - t.Errorf("Decrypt() = %v, want %v", dec, tt.A) + + if dec := Decrypt(tc.B, tc.key); dec != tc.A { + t.Errorf("Decrypt() = %v, want %v", dec, tc.A) } }) }