Closed saxbophone closed 6 years ago
I wrote a quick stress-test right now:
import random
from basest.core import best_ratio, encode_raw, decode_raw
# stress test of Basest
# input bases in range 3..256
for input_base in range(3, 256 + 1):
# output bases in range 2..256
for output_base in range(2, 256 + 1):
# only continue if output base is not larger than input base
if not (output_base > input_base):
# get an encoding ratio to use
_, ratio = best_ratio(input_base, [output_base], range(1, 10 + 1))
# explore the whole input window
for input_window in range(1, ratio[0] + 1):
# generate some random data, half as many items as the input ratio
input_data = [random.randint(0, input_base - 1) for _ in range(input_window)]
# encode the data
encoded_data = encode_raw(
input_base, output_base,
ratio[0], ratio[1],
input_data
)
# decode the data
decoded_data = decode_raw(
output_base, input_base,
ratio[1], ratio[0],
encoded_data
)
# check what we got back is the same as the original
assert decoded_data == input_data
# display some stuff
print(input_data, encoded_data)
I haven't found a nice way of integrating this (and any future) stress-tests into the project yet, so I will not block the public release on this. I will put the test code file in the project tree on its own, pending complete integration into the build process.
Or maybe I can do this simply by putting the stress-test code into a file in the project root and adding commands to the Makefile to run that as the stress-test..?
Write some more comprehensive stress-tests which check that the encoder and decoder functions successfully handle many different unusual output bases, including with partial input to check that padding works successfully across any output base.