Skip to content

Commit 0b2fb34

Browse files
committed
-
1 parent 5c2658c commit 0b2fb34

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

source_py3/python_toolbox/sequence_tools/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def __init__(self, slice_, iterable_or_length=None, offset=0):
401401

402402
class CuteSequenceMixin(misc_tools.AlternativeLengthMixin):
403403
def take_random(self):
404-
return self[random.randint(0, get_length(self))]
404+
return self[random.randint(0, get_length(self) - 1)]
405405
def __contains__(self, item):
406406
try: self.index(item)
407407
except ValueError: return False

source_py3/test_python_toolbox/test_combi/test_comb_space.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test():
4949
assert tuple(comb) == tuple(comb.uncombinationed)
5050
assert comb.is_combination
5151
assert not comb.uncombinationed.is_combination
52+
assert repr(comb_space) == '''<CombSpace: 'dumber', n_elements=2>'''
53+
assert repr(CombSpace(tuple(range(50, 0, -1)), 3)) == \
54+
'''<CombSpace: (50, 49, 48, 47, 46, 45, 44, 43, 42 ... ), n_elements=3>'''
55+
5256

5357

5458

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
from python_toolbox import cute_testing
5+
from python_toolbox import math_tools
6+
7+
from python_toolbox.combi import *
8+
9+
10+
def test():
11+
assert misc.get_short_factorial_string(7) == str(math_tools.factorial(7))
12+
assert misc.get_short_factorial_string(7, minus_one=True) == \
13+
str(math_tools.factorial(7) - 1)
14+
15+
assert misc.get_short_factorial_string(17) == '17!'
16+
assert misc.get_short_factorial_string(17, minus_one=True) == '17! - 1'
17+
18+
assert misc.get_short_factorial_string(float('inf')) == '''float('inf')'''
19+
assert misc.get_short_factorial_string(float('inf'),
20+
minus_one=True) == '''float('inf')'''

source_py3/test_python_toolbox/test_combi/test_selection_space.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,18 @@ def test():
1616

1717
assert (1, 6) not in selection_space
1818
assert 'foo' not in selection_space
19+
assert 7 not in selection_space
1920
assert (1, 3, 4) in selection_space
21+
assert selection_space
22+
assert repr(selection_space) == '<SelectionSpace: range(0, 5)>'
23+
assert {SelectionSpace(range(4)), SelectionSpace(range(4)),
24+
SelectionSpace(range(5)), SelectionSpace(range(4))} == \
25+
{SelectionSpace(range(4)), SelectionSpace(range(5))}
26+
27+
assert SelectionSpace(range(5)) == SelectionSpace(range(5))
28+
assert SelectionSpace(range(5)) != SelectionSpace(range(4))
29+
assert SelectionSpace(range(5)) != SelectionSpace(range(5, 0, -1))
30+
31+
32+
2033

0 commit comments

Comments
 (0)