5 changed files with 92 additions and 92 deletions
@ -1,35 +1,51 @@ |
|||||||
import { getNonIntersectedSpans } from '../../src/utils/spans'; |
import { cutSpanWithSpans } from '../../src/utils/spans'; |
||||||
|
|
||||||
import 'jest'; |
import 'jest'; |
||||||
|
|
||||||
describe('getNonIntersectedSpans', function() { |
|
||||||
|
function cutSpan(from: number, to: number, cuts: [number, number][]): [number, number][] { |
||||||
let spanBorders = [3, 5, 6, 8, 10, 20]; |
return cutSpanWithSpans( |
||||||
|
{ from: from, to: to }, |
||||||
it('functional test', function() {
|
cuts.map(([from, to]) => ({ from, to })) |
||||||
expect(getNonIntersectedSpans(4, 11, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
).map(({ from, to }) => [from, to]); |
||||||
expect(getNonIntersectedSpans(5, 11, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
} |
||||||
expect(getNonIntersectedSpans(4, 10, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
|
||||||
expect(getNonIntersectedSpans(5, 10, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
describe('cutSpanWithSpans', function() { |
||||||
expect(getNonIntersectedSpans(4, 20, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
|
||||||
expect(getNonIntersectedSpans(4, 21, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}, {from: 20, to: 21}]); |
it('should find spans in simple non-intersected borders', function() { |
||||||
expect(getNonIntersectedSpans(2, 20, spanBorders)).toEqual([{from: 2, to: 3}, {from: 5, to: 6}, {from: 8, to: 10}]); |
let cutSpans = [[3, 5], [6, 8], [10, 20]] as [number, number][]; |
||||||
expect(getNonIntersectedSpans(2, 21, spanBorders)).toEqual([{from: 2, to: 3}, {from: 5, to: 6}, {from: 8, to: 10}, {from: 20, to: 21}]); |
|
||||||
expect(getNonIntersectedSpans(3, 11, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
expect(cutSpan(4, 11, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
expect(getNonIntersectedSpans(3, 20, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
expect(cutSpan(5, 11, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
expect(getNonIntersectedSpans(3, 20, spanBorders)).toEqual([{from: 5, to: 6}, {from: 8, to: 10}]); |
expect(cutSpan(4, 10, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
expect(getNonIntersectedSpans(4, 7, [3, 5, 6, 8])).toEqual([{from: 5, to: 6}]); |
expect(cutSpan(5, 10, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
|
expect(cutSpan(4, 20, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
|
expect(cutSpan(4, 21, cutSpans)).toEqual([[5, 6], [8, 10], [20, 21]]); |
||||||
|
expect(cutSpan(2, 20, cutSpans)).toEqual([[2, 3], [5, 6], [8, 10]]); |
||||||
|
expect(cutSpan(2, 21, cutSpans)).toEqual([[2, 3], [5, 6], [8, 10], [20, 21]]); |
||||||
|
expect(cutSpan(3, 11, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
|
expect(cutSpan(3, 20, cutSpans)).toEqual([[5, 6], [8, 10]]); |
||||||
|
expect(cutSpan(4, 7, [[3, 5], [6, 8]])).toEqual([[5, 6]]); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should handle empty input spans list case', function() { |
||||||
|
expect(cutSpan(4, 10, [])).toEqual([[4, 10]]); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should handle case when from and to are inside of one big span', function() { |
||||||
|
expect(cutSpan(4, 10, [[1, 20]])).toEqual([]); |
||||||
|
expect(cutSpan(4, 10, [[1, 10]])).toEqual([]); |
||||||
|
expect(cutSpan(4, 10, [[4, 20]])).toEqual([]); |
||||||
|
expect(cutSpan(4, 10, [[4, 10]])).toEqual([]); |
||||||
}); |
}); |
||||||
|
|
||||||
it('empty borders list', function() { |
it('should be ready to get not-sorted cuts', function() { |
||||||
expect(getNonIntersectedSpans(4, 10, [])).toEqual([]); |
expect(cutSpan(0, 20, [[3, 5], [1, 2]])).toEqual([[0, 1], [2, 3], [5, 20]]); |
||||||
|
expect(cutSpan(0, 20, [[3, 5], [1, 2], [0.1, 0.5]])).toEqual([[0, 0.1], [0.5, 1], [2, 3], [5, 20]]); |
||||||
}); |
}); |
||||||
|
|
||||||
it('all in span', function() { |
it('should be ready to get overlayed cuts', function() { |
||||||
expect(getNonIntersectedSpans(4, 10, [1, 20])).toEqual([]); |
expect(cutSpan(0, 20, [[3, 5], [4, 10]])).toEqual([[0,3], [10, 20]]); |
||||||
expect(getNonIntersectedSpans(4, 10, [1, 10])).toEqual([]); |
|
||||||
expect(getNonIntersectedSpans(4, 10, [4, 20])).toEqual([]); |
|
||||||
expect(getNonIntersectedSpans(4, 10, [4, 10])).toEqual([]); |
|
||||||
}); |
}); |
||||||
|
|
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue