|
5 | 5 | * @copyright 2014-2015 Gaetan Renaudeau. MIT License.
|
6 | 6 | * @noflow
|
7 | 7 | * @emails oncall+react_native
|
| 8 | + * @format |
8 | 9 | */
|
9 | 10 |
|
10 |
| -/* eslint-disable */ |
11 |
| - |
12 | 11 | 'use strict';
|
13 | 12 |
|
14 | 13 | var bezier = require('bezier');
|
15 | 14 |
|
16 |
| -var identity = function (x) { return x; }; |
| 15 | +var identity = function(x) { |
| 16 | + return x; |
| 17 | +}; |
17 | 18 |
|
18 |
| -function assertClose (a, b, precision = 3) { |
| 19 | +function assertClose(a, b, precision = 3) { |
19 | 20 | expect(a).toBeCloseTo(b, precision);
|
20 | 21 | }
|
21 | 22 |
|
22 |
| -function makeAssertCloseWithPrecision (precision) { |
23 |
| - return function (a, b) { |
| 23 | +function makeAssertCloseWithPrecision(precision) { |
| 24 | + return function(a, b) { |
24 | 25 | assertClose(a, b, precision);
|
25 | 26 | };
|
26 | 27 | }
|
27 | 28 |
|
28 |
| -function allEquals (be1, be2, samples, assertion) { |
29 |
| - if (!assertion) assertion = assertClose; |
30 |
| - for (var i=0; i<=samples; ++i) { |
| 29 | +function allEquals(be1, be2, samples, assertion) { |
| 30 | + if (!assertion) { |
| 31 | + assertion = assertClose; |
| 32 | + } |
| 33 | + for (var i = 0; i <= samples; ++i) { |
31 | 34 | var x = i / samples;
|
32 | 35 | assertion(be1(x), be2(x));
|
33 | 36 | }
|
34 | 37 | }
|
35 | 38 |
|
36 |
| -function repeat (n) { |
37 |
| - return function (f) { |
38 |
| - for (var i=0; i<n; ++i) f(i); |
| 39 | +function repeat(n) { |
| 40 | + return function(f) { |
| 41 | + for (var i = 0; i < n; ++i) { |
| 42 | + f(i); |
| 43 | + } |
39 | 44 | };
|
40 | 45 | }
|
41 | 46 |
|
42 |
| -describe('bezier', function(){ |
43 |
| - it('should be a function', function(){ |
| 47 | +describe('bezier', function() { |
| 48 | + it('should be a function', function() { |
44 | 49 | expect(typeof bezier === 'function').toBe(true);
|
45 | 50 | });
|
46 |
| - it('should creates an object', function(){ |
| 51 | + it('should creates an object', function() { |
47 | 52 | expect(typeof bezier(0, 0, 1, 1) === 'function').toBe(true);
|
48 | 53 | });
|
49 |
| - it('should fail with wrong arguments', function () { |
50 |
| - expect(function () { bezier(0.5, 0.5, -5, 0.5); }).toThrow(); |
51 |
| - expect(function () { bezier(0.5, 0.5, 5, 0.5); }).toThrow(); |
52 |
| - expect(function () { bezier(-2, 0.5, 0.5, 0.5); }).toThrow(); |
53 |
| - expect(function () { bezier(2, 0.5, 0.5, 0.5); }).toThrow(); |
| 54 | + it('should fail with wrong arguments', function() { |
| 55 | + expect(function() { |
| 56 | + bezier(0.5, 0.5, -5, 0.5); |
| 57 | + }).toThrow(); |
| 58 | + expect(function() { |
| 59 | + bezier(0.5, 0.5, 5, 0.5); |
| 60 | + }).toThrow(); |
| 61 | + expect(function() { |
| 62 | + bezier(-2, 0.5, 0.5, 0.5); |
| 63 | + }).toThrow(); |
| 64 | + expect(function() { |
| 65 | + bezier(2, 0.5, 0.5, 0.5); |
| 66 | + }).toThrow(); |
54 | 67 | });
|
55 |
| - describe('linear curves', function () { |
56 |
| - it('should be linear', function () { |
| 68 | + describe('linear curves', function() { |
| 69 | + it('should be linear', function() { |
57 | 70 | allEquals(bezier(0, 0, 1, 1), bezier(1, 1, 0, 0), 100);
|
58 | 71 | allEquals(bezier(0, 0, 1, 1), identity, 100);
|
59 | 72 | });
|
60 | 73 | });
|
61 |
| - describe('common properties', function () { |
62 |
| - it('should be the right value at extremes', function () { |
63 |
| - repeat(10)(function () { |
64 |
| - var a = Math.random(), b = 2*Math.random()-0.5, c = Math.random(), d = 2*Math.random()-0.5; |
| 74 | + describe('common properties', function() { |
| 75 | + it('should be the right value at extremes', function() { |
| 76 | + repeat(10)(function() { |
| 77 | + var a = Math.random(), |
| 78 | + b = 2 * Math.random() - 0.5, |
| 79 | + c = Math.random(), |
| 80 | + d = 2 * Math.random() - 0.5; |
65 | 81 | var easing = bezier(a, b, c, d);
|
66 | 82 | expect(easing(0)).toBe(0);
|
67 | 83 | expect(easing(1)).toBe(1);
|
68 | 84 | });
|
69 | 85 | });
|
70 | 86 |
|
71 |
| - it('should approach the projected value of its x=y projected curve', function () { |
72 |
| - repeat(10)(function () { |
73 |
| - var a = Math.random(), b = Math.random(), c = Math.random(), d = Math.random(); |
| 87 | + it('should approach the projected value of its x=y projected curve', function() { |
| 88 | + repeat(10)(function() { |
| 89 | + var a = Math.random(), |
| 90 | + b = Math.random(), |
| 91 | + c = Math.random(), |
| 92 | + d = Math.random(); |
74 | 93 | var easing = bezier(a, b, c, d);
|
75 | 94 | var projected = bezier(b, a, d, c);
|
76 |
| - var composed = function (x) { return projected(easing(x)); }; |
| 95 | + var composed = function(x) { |
| 96 | + return projected(easing(x)); |
| 97 | + }; |
77 | 98 | allEquals(identity, composed, 100, makeAssertCloseWithPrecision(2));
|
78 | 99 | });
|
79 | 100 | });
|
80 | 101 | });
|
81 |
| - describe('two same instances', function () { |
82 |
| - it('should be strictly equals', function () { |
83 |
| - repeat(10)(function () { |
84 |
| - var a = Math.random(), b = 2*Math.random()-0.5, c = Math.random(), d = 2*Math.random()-0.5; |
| 102 | + describe('two same instances', function() { |
| 103 | + it('should be strictly equals', function() { |
| 104 | + repeat(10)(function() { |
| 105 | + var a = Math.random(), |
| 106 | + b = 2 * Math.random() - 0.5, |
| 107 | + c = Math.random(), |
| 108 | + d = 2 * Math.random() - 0.5; |
85 | 109 | allEquals(bezier(a, b, c, d), bezier(a, b, c, d), 100, 0);
|
86 | 110 | });
|
87 | 111 | });
|
88 | 112 | });
|
89 |
| - describe('symetric curves', function () { |
90 |
| - it('should have a central value y~=0.5 at x=0.5', function () { |
91 |
| - repeat(10)(function () { |
92 |
| - var a = Math.random(), b = 2*Math.random()-0.5, c = 1-a, d = 1-b; |
| 113 | + describe('symetric curves', function() { |
| 114 | + it('should have a central value y~=0.5 at x=0.5', function() { |
| 115 | + repeat(10)(function() { |
| 116 | + var a = Math.random(), |
| 117 | + b = 2 * Math.random() - 0.5, |
| 118 | + c = 1 - a, |
| 119 | + d = 1 - b; |
93 | 120 | var easing = bezier(a, b, c, d);
|
94 | 121 | assertClose(easing(0.5), 0.5, 2);
|
95 | 122 | });
|
96 | 123 | });
|
97 |
| - it('should be symetrical', function () { |
98 |
| - repeat(10)(function () { |
99 |
| - var a = Math.random(), b = 2*Math.random()-0.5, c = 1-a, d = 1-b; |
| 124 | + it('should be symetrical', function() { |
| 125 | + repeat(10)(function() { |
| 126 | + var a = Math.random(), |
| 127 | + b = 2 * Math.random() - 0.5, |
| 128 | + c = 1 - a, |
| 129 | + d = 1 - b; |
100 | 130 | var easing = bezier(a, b, c, d);
|
101 |
| - var sym = function (x) { return 1 - easing(1-x); }; |
| 131 | + var sym = function(x) { |
| 132 | + return 1 - easing(1 - x); |
| 133 | + }; |
102 | 134 | allEquals(easing, sym, 100, makeAssertCloseWithPrecision(2));
|
103 | 135 | });
|
104 | 136 | });
|
|
0 commit comments