Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add stress tests #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]')