-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress_test.py
executable file
·66 lines (60 loc) · 2.3 KB
/
stress_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016, 2018, Joshua Saxby <joshua.a.saxby@gmail.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
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]')