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

Function TestEncrypt

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

Source from the content-addressed store, hash-verified

32}
33
34func TestEncrypt(t *testing.T) {
35 fn := func(text string, keyWord string) (bool, error) {
36 encrypt, err := Encrypt([]rune(text), keyWord)
37 if err != nil && !errors.Is(err, ErrNoTextToEncrypt) && !errors.Is(err, ErrKeyMissing) {
38 t.Error("Unexpected error ", err)
39 }
40 return text == string(encrypt), err
41 }
42 for _, s := range texts {
43 if check, err := fn(s, getRandomString()); check || err != nil {
44 t.Error("String ", s, " not encrypted")
45 }
46 }
47 if _, err := fn(getRandomString(), ""); err == nil {
48 t.Error("Error! empty string encryption")
49 }
50}
51
52func TestDecrypt(t *testing.T) {
53 for _, s := range texts {

Callers

nothing calls this directly

Calls 2

getRandomStringFunction · 0.85
EncryptFunction · 0.70

Tested by

no test coverage detected