diff --git a/.travis.yml b/.travis.yml index 64297b9..1fa9128 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,3 +10,4 @@ install: - make install-deps script: - make + - make stress-test diff --git a/Makefile b/Makefile index ae3c05f..471233d 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,9 @@ clean: rm -rf basest.egg-info build dist lint: - flake8 basest tests setup.py + flake8 basest tests setup.py stress_test.py isort -rc -c basest tests - isort -c setup.py + isort -c setup.py stress_test.py test: coverage run --source='basest' tests/__main__.py @@ -25,5 +25,8 @@ cover: tests: clean lint test cover +stress-test: + python stress_test.py + package: python setup.py sdist bdist_wheel diff --git a/stress_test.py b/stress_test.py new file mode 100755 index 0000000..e2aa79f --- /dev/null +++ b/stress_test.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from __future__ import ( + absolute_import, division, print_function, unicode_literals +) + +import random +import sys + +from basest.core import best_ratio, decode_raw, encode_raw + + +def test_partial_input_with_larger_input_bases(): + # 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) + )[1] + # explore the whole input window + for input_window in range(1, ratio[0] + 1): + ''' + generate some random data, as many items as the partial + window input size that we're exploring + ''' + 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 + + +if __name__ == '__main__': + for test_function in [ + test_partial_input_with_larger_input_bases + ]: + print("Running '{}'".format(test_function.__name__), end='...') + sys.stdout.flush() + test_function() + print('[DONE]')