(f *testing.F)
| 101 | } |
| 102 | |
| 103 | func 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 | } |
nothing calls this directly
no test coverage detected