forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.segment.tests.js
53 lines (42 loc) · 2.36 KB
/
helpers.segment.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const {_boundSegment} = Chart.helpers;
describe('helpers.segments', function() {
describe('_boundSegment', function() {
const points = [{x: 10, y: 1}, {x: 20, y: 2}, {x: 30, y: 3}];
const segment = {start: 0, end: 2, loop: false};
it('should not find segment from before the line', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 5, end: 9.99999})).toEqual([]);
});
it('should not find segment from after the line', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 30.00001, end: 800})).toEqual([]);
});
it('should find segment when starting before line', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 5, end: 15})).toEqual([{start: 0, end: 1, loop: false}]);
});
it('should find segment directly on point', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 10, end: 10})).toEqual([{start: 0, end: 0, loop: false}]);
});
it('should find segment from range between points', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 11, end: 14})).toEqual([{start: 0, end: 1, loop: false}]);
});
it('should find segment from point between points', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 22, end: 22})).toEqual([{start: 1, end: 2, loop: false}]);
});
it('should find whole segment', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 0, end: 50})).toEqual([{start: 0, end: 2, loop: false}]);
});
it('should find correct segment from near points', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 10.001, end: 29.999})).toEqual([{start: 0, end: 2, loop: false}]);
});
it('should find segment from after the line', function() {
expect(_boundSegment(segment, points, {property: 'x', start: 25, end: 35})).toEqual([{start: 1, end: 2, loop: false}]);
});
it('should find multiple segments', function() {
const points2 = [{x: 0, y: 100}, {x: 1, y: 50}, {x: 2, y: 70}, {x: 4, y: 80}, {x: 5, y: -100}];
expect(_boundSegment({start: 0, end: 4, loop: false}, points2, {property: 'y', start: 60, end: 60})).toEqual([
{start: 0, end: 1, loop: false},
{start: 1, end: 2, loop: false},
{start: 3, end: 4, loop: false},
]);
});
});
});