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

Function TestBase64EncodeDecodeInverse

conversion/base64_test.go:93–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestBase64EncodeDecodeInverse(t *testing.T) {
94 testCases := []struct {
95 in string
96 }{
97 {"Hello World!"}, // multiple of 3 byte length (multiple of 24-bits)
98 {"Hello World!a"}, // multiple of 3 byte length + 1
99 {"Hello World!ab"}, // multiple of 3 byte length + 2
100 {""}, // empty byte slice
101 {"6"}, // short text
102 {"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."}, // Long text
103 }
104
105 for _, tc := range testCases {
106 result := string(Base64Decode(Base64Encode([]byte(tc.in))))
107 if result != tc.in {
108 t.Fatalf("Base64Decode(Base64Encode(%s)) = %s, want %s", tc.in, result, tc.in)
109 }
110 }
111}
112
113func FuzzBase64Encode(f *testing.F) {
114 f.Add([]byte("hello"))

Callers

nothing calls this directly

Calls 2

Base64DecodeFunction · 0.85
Base64EncodeFunction · 0.85

Tested by

no test coverage detected