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

Function TestPolybiusDecrypt

cipher/polybius/polybius_test.go:110–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestPolybiusDecrypt(t *testing.T) {
111 t.Parallel()
112 cases := []struct {
113 name string
114 text string
115 want string
116 }{
117 {
118 name: "correct decryption", text: "OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG", want: "HOGEFUGAPIYOSPAM",
119 },
120 {
121 name: "invalid decryption(position of even number)", text: "hogz", want: "failed decipher: Z does not exist in characters",
122 },
123 {
124 name: "invalid decryption(position of odd number)", text: "hode", want: "failed decipher: D does not exist in characters",
125 },
126 {
127 name: "invalid text size which is odd", text: "hog", want: "failed decipher: the size of \"chars\" must be even",
128 },
129 }
130 // initialize
131 const (
132 size = 5
133 characters = "HogeF"
134 key = "abcdefghijklmnopqrstuvwxy"
135 )
136 p, err := NewPolybius(key, size, characters)
137 if err != nil {
138 t.Fatalf("failed NewPolybius: %v", err)
139 }
140 for _, tc := range cases {
141 t.Run(tc.name, func(t *testing.T) {
142 encrypted, err := p.Decrypt(tc.text)
143 if err != nil {
144 if err.Error() != tc.want {
145 t.Errorf("failed Encrypt: %v", err)
146 }
147 } else if encrypted != tc.want {
148 t.Errorf("Encrypt: %v, want: %v", encrypted, tc.want)
149 }
150 })
151 }
152}
153
154func FuzzPolybius(f *testing.F) {
155 const (

Callers

nothing calls this directly

Calls 2

DecryptMethod · 0.95
NewPolybiusFunction · 0.85

Tested by

no test coverage detected