test: exhaustively test single-digit base62 de- and encoding

This commit is contained in:
Oneric 2025-10-25 00:00:00 +00:00
commit 37149fea2c

19
test.sh
View file

@ -61,17 +61,26 @@ exc=0
res="$("$SHINYR" api2db 17n42DGM5Tflk9n8mt7Fhc9 2>&1)" || exc="$?"
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'too big'
# exhausitively test base62s individual char decoding (and hex encoding)
prefix="00000000-0000-0000-0000-0000000000"
# exhausitively test base62s individual char de- and encoding
prefix_de="00000000-0000-0000-0000-0000000000"
prefix_en="2d227003d8d2af8" # = 62^11 > 2^64
exval=0
for i in {0..9} {A..Z} {a..z} ; do
TCUR="base62 decode $i"
expected="$(printf '%s%02x' "$prefix" "$exval")"
TCUR="base62 decode $i -> $exval"
expected="$(printf '%s%02x' "$prefix_de" "$exval")"
res="$("$SHINYR" api2db "$i")"
[ "$res" = "$expected" ]
# need to use input ≥ 2^64 to avoid decimal legacy-id output
TCUR="base62 encode $exval -> $i"
input="$(printf '%s%02x' "$prefix_en" "$exval")"
expected="10000000000${i}"
res="$("$SHINYR" db2api "$input")"
[ "$res" = "$expected" ]
exval="$((exval + 1))"
done
TCUR="META: decoder test iterates everything"
TCUR="META: de/encoder test iterates everything"
[ "$exval" -eq 62 ]
# common among time (success) tests