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

Function TestPolybiusEncrypt

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

Source from the content-addressed store, hash-verified

70}
71
72func 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
110func TestPolybiusDecrypt(t *testing.T) {
111 t.Parallel()

Callers

nothing calls this directly

Calls 2

EncryptMethod · 0.95
NewPolybiusFunction · 0.85

Tested by

no test coverage detected