From 4faef5d27e09c7a494829efdf82e6237fb07d16d Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 30 Oct 2018 22:07:54 +0000 Subject: [PATCH 1/3] Add stress-test script and lint it --- Makefile | 4 ++-- stress_test.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100755 stress_test.py diff --git a/Makefile b/Makefile index ae3c05f..96933d2 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 diff --git a/stress_test.py b/stress_test.py new file mode 100755 index 0000000..f87da76 --- /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) + ) + # 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]') From 31153afa3a880ee7fd18fe7cb4ce91fdc5751d36 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 30 Oct 2018 22:45:19 +0000 Subject: [PATCH 2/3] Add stress tests to Makefile and Travis config file --- .travis.yml | 1 + Makefile | 3 +++ 2 files changed, 4 insertions(+) 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 96933d2..471233d 100644 --- a/Makefile +++ b/Makefile @@ -25,5 +25,8 @@ cover: tests: clean lint test cover +stress-test: + python stress_test.py + package: python setup.py sdist bdist_wheel From 894c87a7560b70f24f2be972001422fcb9f9b99a Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 30 Oct 2018 22:48:03 +0000 Subject: [PATCH 3/3] Fix a small linting error on Python2.7: ``` flake8 basest tests setup.py stress_test.py stress_test.py:34:29: F812 list comprehension redefines '_' from line 21 make: *** [lint] Error 1 ``` --- stress_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stress_test.py b/stress_test.py index f87da76..e2aa79f 100755 --- a/stress_test.py +++ b/stress_test.py @@ -18,11 +18,11 @@ def test_partial_input_with_larger_input_bases(): # 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( + 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): '''