|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("d3.ease"); |
|
8 |
|
9 suite.addBatch({ |
|
10 "ease": { |
|
11 topic: function() { |
|
12 return d3.ease; |
|
13 }, |
|
14 "supports linear easing": function(ease) { |
|
15 var e = ease("linear"); |
|
16 assert.inDelta(e(.5), .5, 1e-6); |
|
17 }, |
|
18 "supports polynomial easing": function(ease) { |
|
19 var e = ease("poly", 2); |
|
20 assert.inDelta(e(.5), .25, 1e-6); |
|
21 }, |
|
22 "supports quadratic easing": function(ease) { |
|
23 var e = ease("quad"); |
|
24 assert.inDelta(e(.5), .25, 1e-6); |
|
25 }, |
|
26 "supports cubic easing": function(ease) { |
|
27 var e = ease("cubic"); |
|
28 assert.inDelta(e(.5), .125, 1e-6); |
|
29 }, |
|
30 "supports sinusoidal easing": function(ease) { |
|
31 var e = ease("sin"); |
|
32 assert.inDelta(e(.5), 1 - Math.cos(Math.PI / 4), 1e-6); |
|
33 }, |
|
34 "supports exponential easing": function(ease) { |
|
35 var e = ease("exp"); |
|
36 assert.inDelta(e(.5), 0.03125, 1e-6); |
|
37 }, |
|
38 "supports circular easing": function(ease) { |
|
39 var e = ease("circle"); |
|
40 assert.inDelta(e(.5), 0.133975, 1e-6); |
|
41 }, |
|
42 "supports elastic easing": function(ease) { |
|
43 var e = ease("elastic"); |
|
44 assert.inDelta(e(.5), 0.976061, 1e-6); |
|
45 }, |
|
46 "supports back easing": function(ease) { |
|
47 var e = ease("back"); |
|
48 assert.inDelta(e(.5), -0.0876975, 1e-6); |
|
49 }, |
|
50 "supports bounce easing": function(ease) { |
|
51 var e = ease("bounce"); |
|
52 assert.inDelta(e(.5), 0.765625, 1e-6); |
|
53 }, |
|
54 "all easing functions return exactly 0 for t = 0": function(ease) { |
|
55 assert.equal(ease("linear")(0), 0); |
|
56 assert.equal(ease("poly", 2)(0), 0); |
|
57 assert.equal(ease("quad")(0), 0); |
|
58 assert.equal(ease("cubic")(0), 0); |
|
59 assert.equal(ease("sin")(0), 0); |
|
60 assert.equal(ease("exp")(0), 0); |
|
61 assert.equal(ease("circle")(0), 0); |
|
62 assert.equal(ease("elastic")(0), 0); |
|
63 assert.equal(ease("back")(0), 0); |
|
64 assert.equal(ease("bounce")(0), 0); |
|
65 }, |
|
66 "all easing functions return exactly 1 for t = 1": function(ease) { |
|
67 assert.equal(ease("linear")(1), 1); |
|
68 assert.equal(ease("poly", 2)(1), 1); |
|
69 assert.equal(ease("quad")(1), 1); |
|
70 assert.equal(ease("cubic")(1), 1); |
|
71 assert.equal(ease("sin")(1), 1); |
|
72 assert.equal(ease("exp")(1), 1); |
|
73 assert.equal(ease("circle")(1), 1); |
|
74 assert.equal(ease("elastic")(1), 1); |
|
75 assert.equal(ease("back")(1), 1); |
|
76 assert.equal(ease("bounce")(1), 1); |
|
77 }, |
|
78 "the -in suffix returns the identity": function(ease) { |
|
79 assert.inDelta(ease("linear-in")(.25), ease("linear")(.25), 1e-6); |
|
80 assert.inDelta(ease("quad-in")(.75), ease("quad")(.75), 1e-6); |
|
81 }, |
|
82 "the -out suffix returns the reverse": function(ease) { |
|
83 assert.inDelta(ease("sin-out")(.25), 1 - ease("sin-in")(.75), 1e-6); |
|
84 assert.inDelta(ease("bounce-out")(.25), 1 - ease("bounce-in")(.75), 1e-6); |
|
85 assert.inDelta(ease("elastic-out")(.25), 1 - ease("elastic-in")(.75), 1e-6); |
|
86 }, |
|
87 "the -in-out suffix returns the reflection": function(ease) { |
|
88 assert.inDelta(ease("sin-in-out")(.25), .5 * ease("sin-in")(.5), 1e-6); |
|
89 assert.inDelta(ease("bounce-in-out")(.25), .5 * ease("bounce-in")(.5), 1e-6); |
|
90 assert.inDelta(ease("elastic-in-out")(.25), .5 * ease("elastic-in")(.5), 1e-6); |
|
91 }, |
|
92 "the -out-in suffix returns the reverse reflection": function(ease) { |
|
93 assert.inDelta(ease("sin-out-in")(.25), .5 * ease("sin-out")(.5), 1e-6); |
|
94 assert.inDelta(ease("bounce-out-in")(.25), .5 * ease("bounce-out")(.5), 1e-6); |
|
95 assert.inDelta(ease("elastic-out-in")(.25), .5 * ease("elastic-out")(.5), 1e-6); |
|
96 }, |
|
97 "clamps input time": function(ease) { |
|
98 var e = ease("linear"); |
|
99 assert.inDelta(e(-1), 0, 1e-6); |
|
100 assert.inDelta(e(2), 1, 1e-6); |
|
101 }, |
|
102 "poly": { |
|
103 "supports an optional polynomial": function(ease) { |
|
104 var e = ease("poly", 1); |
|
105 assert.inDelta(e(.5), .5, 1e-6); |
|
106 var e = ease("poly", .5); |
|
107 assert.inDelta(e(.5), Math.SQRT1_2, 1e-6); |
|
108 } |
|
109 }, |
|
110 "elastic": { |
|
111 "supports an optional amplifier (>1)": function(ease) { |
|
112 var e = ease("elastic", 1.5); |
|
113 assert.inDelta(e(.5), 0.998519, 1e-6); |
|
114 }, |
|
115 "supports an optional amplifier (>1) and period (>0)": function(ease) { |
|
116 var e = ease("elastic", 1.5, .5); |
|
117 assert.inDelta(e(.5), 0.96875, 1e-6); |
|
118 } |
|
119 }, |
|
120 "back": { |
|
121 "supports an optional speed": function(ease) { |
|
122 var e = ease("back", 2); |
|
123 assert.inDelta(e(.5), -0.125, 1e-6); |
|
124 } |
|
125 } |
|
126 } |
|
127 }); |
|
128 |
|
129 suite.export(module); |