diff --git a/README.md b/README.md index 97a694c52df255a5904797f687e584af5f18c393..f982022ad8050b2d8f54a134fd999773a3bb9ea5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/firanka/ranges.py b/firanka/ranges.py index a2b2ae17e7812aab1dc9aa98975cdacbf60a2d0b..b0b57fb48ea6eaf9c52bb5518141019956ef539a 100644 --- a/firanka/ranges.py +++ b/firanka/ranges.py @@ -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): diff --git a/firanka/series/__init__.py b/firanka/series/__init__.py index 0a890c4bc87fe8e89dd9da02722949ef27565205..59a5abc47844b6908fbd8c71d2603dc019c6c702 100644 --- a/firanka/series/__init__.py +++ b/firanka/series/__init__.py @@ -1,7 +1,7 @@ # 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__ = [ diff --git a/firanka/series/linear.py b/firanka/series/interpolations.py similarity index 100% rename from firanka/series/linear.py rename to firanka/series/interpolations.py diff --git a/tests/test_range.py b/tests/test_range.py index 5463f9001db84be63bf273a431c9a343b048493a..f95cb6f87be4ef26798cca987d9d7a0762fcd349 100644 --- a/tests/test_range.py +++ b/tests/test_range.py @@ -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>'))