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

tests

parent eda3be19
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,11 @@ from __future__ import print_function, absolute_import, division ...@@ -3,7 +3,11 @@ from __future__ import print_function, absolute_import, division
import six import six
import logging import logging
logger = logging.getLogger(__name__)
from .exceptions import OutOfRangeError, EmptyDomainError from .exceptions import OutOfRangeError, EmptyDomainError
from .range import Range
__all__ = [
'OutOfRangeError',
'EmptyDomainError',
'Range'
]
...@@ -5,6 +5,7 @@ import logging ...@@ -5,6 +5,7 @@ import logging
import re import re
from satella.coding import for_argument from satella.coding import for_argument
import functools import functools
import math
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -25,8 +26,8 @@ class Range(object): ...@@ -25,8 +26,8 @@ class Range(object):
def __init__(self, *args): def __init__(self, *args):
if len(args) == 1: if len(args) == 1:
rs, = args rs, = args
assert rs.startswith('<') or rs.startswith('(') assert rs[0] in '<('
assert rs.endswith('>') or rs.endswith(')') assert rs[-1] in '>)'
lend_inclusive = rs[0] == '<' lend_inclusive = rs[0] == '<'
rend_inclusive = rs[-1] == '>' rend_inclusive = rs[-1] == '>'
...@@ -41,6 +42,11 @@ class Range(object): ...@@ -41,6 +42,11 @@ class Range(object):
else: else:
start, stop, lend_inclusive, rend_inclusive = args start, stop, lend_inclusive, rend_inclusive = args
if lend_inclusive and math.isinf(start):
raise ValueError('Greater or equal with infinity!')
if rend_inclusive and math.isinf(stop):
raise ValueError('Greater or equal with infinity!')
self.start = start self.start = start
self.stop = stop self.stop = stop
self.lend_inclusive = lend_inclusive self.lend_inclusive = lend_inclusive
......
...@@ -13,4 +13,13 @@ class TestRange(unittest.TestCase): ...@@ -13,4 +13,13 @@ class TestRange(unittest.TestCase):
def test_str(self): def test_str(self):
self.assertEqual(str(Range(-1, 1, True, True)), '<-1;1>') self.assertEqual(str(Range(-1, 1, True, True)), '<-1;1>')
\ No newline at end of file
def test_contains(self):
self.assertFalse(-1 in Range('<-10;-1)'))
self.assertTrue(-10 in Range('<-10;-1)'))
self.assertFalse(-10 in Range('(-10;-1>'))
self.assertTrue(-1 in Range('(-10;-1>'))
self.assertTrue(-5 in Range('(-10;-1>'))
self.assertFalse(-20 in Range('(-10;-1>'))
self.assertFalse(1 in Range('(-10;-1>'))
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