MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestDecrypt

Function TestDecrypt

cipher/transposition/transposition_test.go:52–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestDecrypt(t *testing.T) {
53 for _, s := range texts {
54 keyWord := getRandomString()
55 encrypt, errEncrypt := Encrypt([]rune(s), keyWord)
56 if errEncrypt != nil &&
57 !errors.Is(errEncrypt, ErrNoTextToEncrypt) &&
58 !errors.Is(errEncrypt, ErrKeyMissing) {
59 t.Error("Unexpected error ", errEncrypt)
60 }
61 if errEncrypt != nil {
62 t.Error(errEncrypt)
63 }
64 decrypt, errDecrypt := Decrypt([]rune(encrypt), keyWord)
65 if errDecrypt != nil &&
66 !errors.Is(errDecrypt, ErrNoTextToEncrypt) &&
67 !errors.Is(errDecrypt, ErrKeyMissing) {
68 t.Error("Unexpected error ", errDecrypt)
69 }
70 if errDecrypt != nil {
71 t.Error(errDecrypt)
72 }
73 if reflect.DeepEqual(encrypt, decrypt) {
74 t.Error("String ", s, " not encrypted")
75 }
76 if reflect.DeepEqual(encrypt, s) {
77 t.Error("String ", s, " not encrypted")
78 }
79 }
80}
81
82func TestEncryptDecrypt(t *testing.T) {
83 text := []rune("Test text for checking the algorithm")

Callers

nothing calls this directly

Calls 3

getRandomStringFunction · 0.85
EncryptFunction · 0.70
DecryptFunction · 0.70

Tested by

no test coverage detected