Skip to content

Commit 3e03c9d

Browse files
committed
-
1 parent 6218c4b commit 3e03c9d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

source_py3/python_toolbox/sequence_tools/canonical_slice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, slice_, iterable_or_length=None, offset=0):
3131
If `stop` is `None`, it will be set to `infinity` (if the `step` is
3232
positive) or `0` (if the `step` is negative.)
3333
If `step` is `None`, it will be changed to the default `1`.
34+
3435
'''
3536
from python_toolbox import sequence_tools
3637

source_py3/python_toolbox/sequence_tools/cute_range.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,22 @@ class CuteRange(CuteSequence):
8787
allows you to use floating-point numbers (or decimals), and it allows you
8888
to use infinite numbers to produce infinite ranges.
8989
90-
blocktododoc add examples
90+
Examples:
91+
92+
CuteRange(float('inf')) is an infinite range starting at zero and never
93+
ending.
94+
95+
CuteRange(7, float('inf')) is an infinite range starting at 7 and never
96+
ending. (Like `itertools.count(7)` except it has all the amenities of a
97+
sequence, you can get items using list notation, you can slice it, you
98+
can get index numbers of items, etc.)
99+
100+
CuteRange(-1.6, 7.3) is the finite range of numbers `(-1.6, -0.6, 0.4,
101+
1.4, 2.4, 3.4, 4.4, 5.4, 6.4)`.
102+
103+
CuteRange(10.4, -float('inf'), -7.1) is the infinite range of numbers
104+
`(10.4, 3.3, -3.8, -10.9, -18.0, -25.1, ... )`.
105+
91106
'''
92107
def __init__(self, *args):
93108
self.start, self.stop, self.step = parse_range_args(*args)
@@ -194,5 +209,5 @@ def index(self, i):
194209
else:
195210
raise ValueError
196211

197-
is_infinity = caching.CachedProperty(lambda self: self.length == infinity)
212+
is_infinite = caching.CachedProperty(lambda self: self.length == infinity)
198213

source_py3/test_python_toolbox/test_sequence_tools/test_cute_range.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
infinity = float('inf')
1010

1111

12+
def test():
13+
assert CuteRange(10.4, -float('inf'), -7.1)[:5] == (
14+
10.4,
15+
3.3,
16+
-3.8,
17+
-10.9,
18+
-18.0,
19+
-25.1
20+
)
21+
22+
23+
1224
def test_finite():
1325
finite_range_arguments_tuples = (
1426
(10,), (3,), (20, 30), (20, 30, 2), (20, 30, -2)

0 commit comments

Comments
 (0)