Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
firanka
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
firanka
Commits
eda3be19
Commit
eda3be19
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
passes tests
parent
7163e784
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
firanka/series/range.py
+29
-25
29 additions, 25 deletions
firanka/series/range.py
setup.py
+0
-2
0 additions, 2 deletions
setup.py
tests/test_series/test_range.py
+1
-1
1 addition, 1 deletion
tests/test_series/test_range.py
with
30 additions
and
28 deletions
firanka/series/range.py
+
29
−
25
View file @
eda3be19
...
...
@@ -4,10 +4,20 @@ import six
import
logging
import
re
from
satella.coding
import
for_argument
import
functools
logger
=
logging
.
getLogger
(
__name__
)
def
pre_range
(
fun
):
@functools.wraps
(
fun
)
def
inner
(
self
,
arg
,
*
args
,
**
kwargs
):
if
not
isinstance
(
arg
,
Range
):
arg
=
Range
(
arg
)
return
fun
(
self
,
arg
,
*
args
,
**
kwargs
)
return
inner
class
Range
(
object
):
"""
Range of real numbers
...
...
@@ -68,45 +78,39 @@ class Range(object):
'
>
'
if
self
.
rend_inclusive
else
'
)
'
,
)
@pre_range
def
intersection
(
self
,
y
):
if
not
isinstance
(
y
,
Range
):
y
=
Range
(
y
)
print
(
str
(
self
),
str
(
y
))
if
self
.
start
>
y
.
start
:
return
y
.
intersection
(
self
)
x
=
self
assert
self
.
start
<=
y
.
start
# Check for intersection being impossible
if
(
x
.
stop
<
y
.
start
)
or
(
x
.
start
>
y
.
stop
)
or
\
(
x
.
stop
==
y
.
start
and
not
x
.
rend_inclusive
and
not
y
.
lend_inclusive
)
or
\
(
x
.
start
==
x
.
stop
and
not
x
.
lend_inclusive
and
not
y
.
rend_inclusive
):
if
(
self
.
stop
<
y
.
start
)
or
(
y
.
stop
<
y
.
start
):
return
EMPTY_RANGE
# Check for range extension
if
(
x
.
start
==
y
.
stop
)
and
(
x
.
lend_inclusive
or
y
.
lend_inclusive
):
return
Range
(
y
.
start
,
x
.
stop
,
y
.
lend_inclusive
,
x
.
rend_inclusive
)
if
(
x
.
start
==
y
.
stop
)
and
(
x
.
lend_inclusive
or
y
.
lend_inclusive
):
return
Range
(
y
.
start
,
x
.
stop
,
y
.
lend_inclusive
,
x
.
rend_inclusive
)
if
self
.
stop
==
y
.
start
and
not
(
self
.
rend_inclusive
or
y
.
lend_inclusive
):
return
EMPTY_RANGE
if
x
.
start
==
y
.
start
:
start
=
x
.
start
lend_inclusive
=
x
.
lend_inclusive
or
y
.
lend_inclusive
if
self
.
start
==
y
.
start
:
start
=
self
.
start
lend_inclusive
=
self
.
lend_inclusive
or
y
.
lend_inclusive
else
:
p
=
x
if
x
.
start
>
y
.
start
else
y
start
=
p
.
start
lend_inclusive
=
p
.
lend_inclusive
start
=
y
.
start
lend_inclusive
=
y
.
lend_inclusive
if
x
.
stop
==
y
.
stop
:
stop
=
x
.
stop
rend_inclusive
=
x
.
rend_inclusive
or
y
.
rend_inclusive
if
self
.
stop
==
y
.
stop
:
stop
=
self
.
stop
rend_inclusive
=
self
.
rend_inclusive
or
y
.
rend_inclusive
else
:
p
=
x
if
x
.
stop
<
y
.
stop
else
y
p
,
q
=
(
self
,
y
)
if
self
.
stop
<
y
.
stop
else
(
y
,
self
)
stop
=
p
.
stop
rend_inclusive
=
p
.
rend_inclusive
rend_inclusive
=
p
.
rend_inclusive
and
(
stop
in
q
)
return
Range
(
start
,
stop
,
lend_inclusive
,
rend_inclusive
)
@pre_range
def
__eq__
(
self
,
other
):
if
not
isinstance
(
other
,
Range
):
other
=
Range
(
other
)
return
self
.
start
==
other
.
start
and
self
.
stop
==
other
.
stop
and
self
.
lend_inclusive
==
other
.
lend_inclusive
and
self
.
rend_inclusive
==
other
.
rend_inclusive
def
__hash__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
0
−
2
View file @
eda3be19
# coding=UTF-8
from
setuptools
import
setup
,
find_packages
from
pip.req
import
parse_requirements
from
firanka
import
__version__
...
...
This diff is collapsed.
Click to expand it.
tests/test_series/test_range.py
+
1
−
1
View file @
eda3be19
...
...
@@ -9,7 +9,7 @@ class TestRange(unittest.TestCase):
self
.
assertFalse
(
Range
(
-
10
,
-
1
,
True
,
True
).
intersection
(
'
<2;3>
'
))
self
.
assertFalse
(
Range
(
-
10
,
-
1
,
True
,
False
).
intersection
(
'
(-1;3>
'
))
self
.
assert
Equ
als
(
Range
(
'
<-10;-1)
'
).
intersection
(
'
<-1;1>
'
)
,
'
<-1;1>
'
)
self
.
assert
F
als
e
(
Range
(
'
<-10;-1)
'
).
intersection
(
'
<-1;1>
'
))
def
test_str
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment