Download or view base32Test.frink in plain text format
/** Base 32 encoder/decoder test. See RFC 4648.
https://www.rfc-editor.org/rfc/rfc4648.html
*/
pairs = [["", ""],
["f", "MY======"],
["fo", "MZXQ===="],
["foo", "MZXW6==="],
["foob", "MZXW6YQ="],
["fooba", "MZXW6YTB"],
["foobar", "MZXW6YTBOI======"]]
enc = "UTF-8"
for [in, out] = pairs
{
test[in, out, enc]
}
text = "\u{1f431} This is a long stretch of text. \u{1f431}\u{1f431} Monkey"
len = length[text]
for s = 0 to len-1
{
str = left[text, s]
roundtripTest[str, enc]
str = right[text, s]
roundtripTest[str, enc]
}
roundtripTest[in, enc] :=
{
out = base32Encode[in, enc]
rein = base32Decode[out, enc]
if rein != in
println["Error in input roundtrip \"$in\" to \"$out\""]
reout = base32Encode[base32Decode[out, enc], enc]
if reout != out
println["Error in output roundtrip \"$out\" to \"$in\""]
}
test[in, out, enc] :=
{
if base32Encode[in, enc] != out
println["Error in encoding \"$in\" to \"$out\""]
if base32Decode[out, enc] != in
println["Error in decoding \"$out\" to \"$in\""]
roundtripTest[in, enc]
}
Download or view base32Test.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen, eliasen@mindspring.com