diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-09-29 12:24:06 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-09-29 12:41:34 +0300 |
commit | e0e3e1717e3d33762ce61950504f9637a6e669ed (patch) | |
tree | bca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/prompt-toolkit/py2/tests/test_utils.py | |
parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) | |
download | ydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz |
add ydb deps
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/tests/test_utils.py')
-rw-r--r-- | contrib/python/prompt-toolkit/py2/tests/test_utils.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/python/prompt-toolkit/py2/tests/test_utils.py b/contrib/python/prompt-toolkit/py2/tests/test_utils.py new file mode 100644 index 0000000000..1e3d92cda6 --- /dev/null +++ b/contrib/python/prompt-toolkit/py2/tests/test_utils.py @@ -0,0 +1,39 @@ +from __future__ import unicode_literals + +from prompt_toolkit.utils import take_using_weights + +import itertools + + +def test_using_weights(): + def take(generator, count): + return list(itertools.islice(generator, 0, count)) + + # Check distribution. + data = take(take_using_weights(['A', 'B', 'C'], [5, 10, 20]), 35) + assert data.count('A') == 5 + assert data.count('B') == 10 + assert data.count('C') == 20 + + assert data == [ + 'A', 'B', 'C', 'C', 'B', 'C', 'C', 'A', 'B', 'C', 'C', 'B', 'C', + 'C', 'A', 'B', 'C', 'C', 'B', 'C', 'C', 'A', 'B', 'C', 'C', + 'B', 'C', 'C', 'A', 'B', 'C', 'C', 'B', 'C', 'C'] + + # Another order. + data = take(take_using_weights(['A', 'B', 'C'], [20, 10, 5]), 35) + assert data.count('A') == 20 + assert data.count('B') == 10 + assert data.count('C') == 5 + + # Bigger numbers. + data = take(take_using_weights(['A', 'B', 'C'], [20, 10, 5]), 70) + assert data.count('A') == 40 + assert data.count('B') == 20 + assert data.count('C') == 10 + + # Negative numbers. + data = take(take_using_weights(['A', 'B', 'C'], [-20, 10, 0]), 70) + assert data.count('A') == 0 + assert data.count('B') == 70 + assert data.count('C') == 0 |