MCPcopy
hub / github.com/TheAlgorithms/Go / FuzzTransposition

Function FuzzTransposition

cipher/transposition/transposition_test.go:103–133  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

101}
102
103func FuzzTransposition(f *testing.F) {
104 for _, transpositionTestInput := range texts {
105 f.Add(transpositionTestInput)
106 }
107 f.Fuzz(func(t *testing.T, input string) {
108 keyword := getRandomString()
109 message := []rune(input)
110 encrypted, err := Encrypt(message, keyword)
111 switch {
112 case err == nil:
113 case errors.Is(err, ErrKeyMissing),
114 errors.Is(err, ErrNoTextToEncrypt):
115 return
116 default:
117 t.Fatalf("unexpected error when encrypting string %q: %v", input, err)
118 }
119 decrypted, err := Decrypt([]rune(encrypted), keyword)
120 switch {
121 case err == nil:
122 case errors.Is(err, ErrKeyMissing),
123 errors.Is(err, ErrNoTextToEncrypt):
124 return
125 default:
126 t.Fatalf("unexpected error when decrypting string %q: %v", encrypted, err)
127 }
128
129 if !reflect.DeepEqual(message, decrypted) {
130 t.Fatalf("expected: %+v, got: %+v", message, []rune(decrypted))
131 }
132 })
133}

Callers

nothing calls this directly

Calls 4

getRandomStringFunction · 0.85
EncryptFunction · 0.70
DecryptFunction · 0.70
AddMethod · 0.65

Tested by

no test coverage detected