(t *testing.T)
| 70 | } |
| 71 | |
| 72 | func TestPolybiusEncrypt(t *testing.T) { |
| 73 | t.Parallel() |
| 74 | cases := []struct { |
| 75 | name string |
| 76 | text string |
| 77 | want string |
| 78 | }{ |
| 79 | { |
| 80 | name: "correct encryption", text: "HogeFugaPiyoSpam", want: "OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG", |
| 81 | }, |
| 82 | { |
| 83 | name: "invalid encryption", text: "hogz", want: "failed encipher: 'Z' does not exist in keys", |
| 84 | }, |
| 85 | } |
| 86 | // initialize |
| 87 | const ( |
| 88 | size = 5 |
| 89 | characters = "HogeF" |
| 90 | key = "abcdefghijklmnopqrstuvwxy" |
| 91 | ) |
| 92 | p, err := NewPolybius(key, size, characters) |
| 93 | if err != nil { |
| 94 | t.Fatalf("failed NewPolybius: %v", err) |
| 95 | } |
| 96 | for _, tc := range cases { |
| 97 | t.Run(tc.name, func(t *testing.T) { |
| 98 | encrypted, err := p.Encrypt(tc.text) |
| 99 | if err != nil { |
| 100 | if err.Error() != tc.want { |
| 101 | t.Errorf("failed Encrypt: %v", err) |
| 102 | } |
| 103 | } else if encrypted != tc.want { |
| 104 | t.Errorf("Encrypt: %v, want: %v", encrypted, tc.want) |
| 105 | } |
| 106 | }) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func TestPolybiusDecrypt(t *testing.T) { |
| 111 | t.Parallel() |
nothing calls this directly
no test coverage detected