Just to be sure that the function Utils.spans.cutSpanWithSpans works as it should, few more tests added: It will help in future if we want to improve the performance.
I believe that Span should represent a discrete structure, which is a countable set, integer segment , subset of Z
Also, I propose to stop using word "Span" without clear math definition. So I an going to rename Utils.spans.cutSpanWithSpans accordingly.
If we cut [z, z] and [x, y] from [a, b] , then we get [[a, z - 1], [z + 1, x - 1]]
So when we want to get cut [x, x] from [a, b] where a < x < b, then we should return split [a, x - 1] and [x + 1, b]
This PR changes the behavior of cutSpanWithSpans and renames it to cutSegmentWithSegments
Changes
New class IntegerSegment -- it is like segment, but integer
New class IntegerSegmentsSet -- can eat IntegerSegments and has set operations. For now implemented operations necessary for cutSegmentWithSegments
New tests:
One-point cut
If we cut [1, 10] with [5, 5] , we should get spans [1, 4] and [6, 10]
Infinite spans
If we cut [0, Infinity] with [5, 10], we should get [0, 4] and [11, Infinity]
If we cut [1, 6] with [0, Infinity], we should get []
If we cut [0, 6] with [1, Infinity], we should get [0, 0]
If we cut [-Infinity, Infinity] with [-Infinity, Infinity] we should get []
Overlapping cuts
There are many combinations where cuts include each other or could be sorted wrong.
Many new combinations added. Including infinite case.
Just to be sure that the function
Utils.spans.cutSpanWithSpans
works as it should, few more tests added: It will help in future if we want to improve the performance.I believe that
Span
should represent a discrete structure, which is a countable set, integer segment , subset of Z Also, I propose to stop using word "Span" without clear math definition. So I an going to renameUtils.spans.cutSpanWithSpans
accordingly.If we cut
[z, z]
and[x, y]
from[a, b]
, then we get[[a, z - 1], [z + 1, x - 1]]
So when we want to get cut
[x, x]
from[a, b]
wherea < x < b
, then we should return split[a, x - 1]
and[x + 1, b]
This PR changes the behavior of
cutSpanWithSpans
and renames it tocutSegmentWithSegments
Changes
IntegerSegment
-- it is like segment, but integerIntegerSegmentsSet
-- can eat IntegerSegments and has set operations. For now implemented operations necessary forcutSegmentWithSegments
New tests:
One-point cut
If we cut
[1, 10]
with[5, 5]
, we should get spans[1, 4]
and[6, 10]
Infinite spans
If we cut
[0, Infinity]
with[5, 10]
, we should get[0, 4]
and[11, Infinity]
If we cut
[1, 6]
with[0, Infinity]
, we should get[]
If we cut
[0, 6]
with[1, Infinity]
, we should get[0, 0]
If we cut
[-Infinity, Infinity]
with[-Infinity, Infinity]
we should get[]
Overlapping cuts
There are many combinations where cuts include each other or could be sorted wrong. Many new combinations added. Including infinite case.