Skip to content

Commit 5bd8f5a

Browse files
authored
Merge pull request #38 from saxbophone/josh/29-stress-tests
Add stress tests
2 parents 04665f9 + 894c87a commit 5bd8f5a

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ install:
1010
- make install-deps
1111
script:
1212
- make
13+
- make stress-test

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ clean:
1313
rm -rf basest.egg-info build dist
1414

1515
lint:
16-
flake8 basest tests setup.py
16+
flake8 basest tests setup.py stress_test.py
1717
isort -rc -c basest tests
18-
isort -c setup.py
18+
isort -c setup.py stress_test.py
1919

2020
test:
2121
coverage run --source='basest' tests/__main__.py
@@ -25,5 +25,8 @@ cover:
2525

2626
tests: clean lint test cover
2727

28+
stress-test:
29+
python stress_test.py
30+
2831
package:
2932
python setup.py sdist bdist_wheel

stress_test.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
from __future__ import (
4+
absolute_import, division, print_function, unicode_literals
5+
)
6+
7+
import random
8+
import sys
9+
10+
from basest.core import best_ratio, decode_raw, encode_raw
11+
12+
13+
def test_partial_input_with_larger_input_bases():
14+
# input bases in range 3..256
15+
for input_base in range(3, 256 + 1):
16+
# output bases in range 2..256
17+
for output_base in range(2, 256 + 1):
18+
# only continue if output base is not larger than input base
19+
if not (output_base > input_base):
20+
# get an encoding ratio to use
21+
ratio = best_ratio(
22+
input_base,
23+
[output_base],
24+
range(1, 10 + 1)
25+
)[1]
26+
# explore the whole input window
27+
for input_window in range(1, ratio[0] + 1):
28+
'''
29+
generate some random data, as many items as the partial
30+
window input size that we're exploring
31+
'''
32+
input_data = [
33+
random.randint(0, input_base - 1)
34+
for _ in range(input_window)
35+
]
36+
# encode the data
37+
encoded_data = encode_raw(
38+
input_base, output_base,
39+
ratio[0], ratio[1],
40+
input_data
41+
)
42+
# decode the data
43+
decoded_data = decode_raw(
44+
output_base, input_base,
45+
ratio[1], ratio[0],
46+
encoded_data
47+
)
48+
# check what we got back is the same as the original
49+
assert decoded_data == input_data
50+
51+
52+
if __name__ == '__main__':
53+
for test_function in [
54+
test_partial_input_with_larger_input_bases
55+
]:
56+
print("Running '{}'".format(test_function.__name__), end='...')
57+
sys.stdout.flush()
58+
test_function()
59+
print('[DONE]')

0 commit comments

Comments
 (0)