Skip to content
Snippets Groups Projects
Commit 0c442a57 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

refactor

parent 9bcc5df0
No related branches found
No related tags found
No related merge requests found
......@@ -119,9 +119,7 @@ You can create Ranges as follows:
Range(-5, 5, True, False) == Range('<-5;5)')
```
First boolean argument signifies whether the interval is left-closed,
and second whether it is right-closed.
For more information [use the source](firanka/ranges.py#L33)
Range's are immutable and hashable. They can be sliced:
```python
......
......@@ -31,6 +31,16 @@ class Range(object):
self.right_inc)
def __init__(self, *args):
"""
Create like:
* Range('<a;b>')
* Range(a, b, is_left_closed_, is_right_closed)
* Range(a, b) - will have both sides closed, unless one is inf
* Range(slice(a, b)) - will have both sides closed, unless one is None
:param args:
"""
if len(args) == 1:
rs, = args
if isinstance(rs, type(self)):
......@@ -48,6 +58,9 @@ class Range(object):
start, stop = rs[1:-1].split(';')
args = float(start), float(stop), rs[0] == '<', rs[-1] == '>'
elif len(args) == 2:
args = args[0], args[1], not math.isinf(args[0]), not math.isinf(args[1])
q = lambda a, b, args: args[a] and math.isinf(args[b])
if q(2, 0, args) or q(3, 1, args):
......
# coding=UTF-8
from __future__ import absolute_import
from .base import FunctionSeries, DiscreteSeries, Series
from .linear import LinearInterpolationSeries, SCALAR_LINEAR_INTERPOLATOR
from .interpolations import LinearInterpolationSeries, SCALAR_LINEAR_INTERPOLATOR
from .modulo import ModuloSeries
__all__ = [
......
File moved
......@@ -38,7 +38,7 @@ class TestRange(unittest.TestCase):
def test_str_and_repr_and_bool(self):
p = Range(-1, 1, True, True)
self.assertEqual(eval(repr(p)), p)
self.assertEqual(str(Range(-1, 1, True, True)), '<-1;1>')
self.assertEqual(str(Range(-1, 1)), '<-1;1>')
def test_constructor(self):
self.assertRaises(ValueError, lambda: Range('#2;3>'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment