Skip to content

Commit

Permalink
Merge pull request #38 from saxbophone/josh/29-stress-tests
Browse files Browse the repository at this point in the history
Add stress tests
  • Loading branch information
saxbophone committed Oct 30, 2018
2 parents 04665f9 + 894c87a commit 5bd8f5a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ install:
- make install-deps
script:
- make
- make stress-test
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,5 +25,8 @@ cover:

tests: clean lint test cover

stress-test:
python stress_test.py

package:
python setup.py sdist bdist_wheel
59 changes: 59 additions & 0 deletions stress_test.py
Original file line number Diff line number Diff line change
@@ -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]')

0 comments on commit 5bd8f5a

Please sign in to comment.