-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathtest-curve.js
71 lines (60 loc) · 2.46 KB
/
test-curve.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Copyright 2015 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Curves, bezierCurve, getCurve} from '../../src/curve';
describe('Curve', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox;
});
afterEach(() => {
sandbox.restore();
});
it('bezierCurve', () => {
let curve = bezierCurve(0.75, 0, 0.75, 0.9);
expect(curve(0.2)).to.be.closeTo(0.024374631, 1e-6);
expect(curve(0.6)).to.be.closeTo(0.317459494, 1e-6);
expect(curve(0.9)).to.be.closeTo(0.905205002, 1e-6);
curve = bezierCurve(0, 0, 0.58, 1);
expect(curve(0.2)).to.be.closeTo(0.308366667, 1e-6);
expect(curve(0.6)).to.be.closeTo(0.785139061, 1e-6);
expect(curve(0.9)).to.be.closeTo(0.982973389, 1e-6);
});
it('getCurve on common curves', () => {
// Null case.
expect(getCurve(null)).to.equal(null);
expect(getCurve(undefined)).to.equal(null);
// Function is passed through.
const func = () => {};
expect(getCurve(func)).to.equal(func);
// String is translated.
expect(getCurve('linear')).to.equal(Curves.LINEAR);
expect(getCurve('ease')).to.equal(Curves.EASE);
expect(getCurve('ease-in')).to.equal(Curves.EASE_IN);
expect(getCurve('ease-out')).to.equal(Curves.EASE_OUT);
expect(getCurve('ease-in-out')).to.equal(Curves.EASE_IN_OUT);
});
it('getCurve on cubic-bezier curves', () => {
expect(getCurve('cubic-bezier(1)')).to.equal(null);
expect(getCurve('cubic-bezier(a)')).to.equal(null);
expect(getCurve('cubic-bezier(0.4, 0, 0.2)')).to.equal(null);
expect(getCurve('cubic-bezier(0.4, 0, 0.2, a)')).to.equal(null);
const curveExpected = bezierCurve(0.4, 0, 0.2, 1);
const curveGet = getCurve('cubic-bezier(0.4, 0, 0.2, 1)');
expect(curveExpected(0.2)).to.be.closeTo(curveGet(0.2), 1e-6);
expect(curveExpected(0.6)).to.be.closeTo(curveGet(0.6), 1e-6);
expect(curveExpected(0.9)).to.be.closeTo(curveGet(0.9), 1e-6);
});
});