@@ -2,15 +2,10 @@ import { describe, expect, test } from 'vitest'
22import {
33 createSpring ,
44 springSettlingDuration ,
5- springValue ,
6- springVelocity ,
5+ evaluateSpring ,
6+ evaluateSpringVelocity ,
77} from '../../src/core/spring'
88
9- function toMostlyEqual ( actual : number , expected : number , tolerance = 0.000001 ) {
10- expect ( actual ) . toBeLessThan ( expected + tolerance )
11- expect ( actual ) . toBeGreaterThan ( expected - tolerance )
12- }
13-
149describe ( 'spring' , ( ) => {
1510 describe ( 'value constraints' , ( ) => {
1611 test ( 'return actual animating value when from and to are the same' , ( ) => {
@@ -20,7 +15,7 @@ describe('spring', () => {
2015 } )
2116
2217 expect (
23- springValue ( spring , {
18+ evaluateSpring ( spring , {
2419 from : 0 ,
2520 to : 0 ,
2621 initialVelocity : 1000 ,
@@ -36,25 +31,23 @@ describe('spring', () => {
3631 duration : 1000 ,
3732 } )
3833
39- toMostlyEqual (
40- springValue ( spring , {
34+ expect (
35+ evaluateSpring ( spring , {
4136 from : 100 ,
4237 to : 200 ,
4338 initialVelocity : 0 ,
4439 time : 0 ,
4540 } ) ,
46- 100 ,
47- )
41+ ) . toBeCloseTo ( 100 )
4842
49- toMostlyEqual (
50- springValue ( spring , {
43+ expect (
44+ evaluateSpring ( spring , {
5145 from : 0 ,
5246 to : 200 ,
5347 initialVelocity : 1000 ,
5448 time : 0 ,
5549 } ) ,
56- 0 ,
57- )
50+ ) . toBeCloseTo ( 0 )
5851 } )
5952
6053 test ( 'bounce = 0' , ( ) => {
@@ -63,25 +56,23 @@ describe('spring', () => {
6356 duration : 1000 ,
6457 } )
6558
66- toMostlyEqual (
67- springValue ( spring , {
59+ expect (
60+ evaluateSpring ( spring , {
6861 from : 100 ,
6962 to : 200 ,
7063 initialVelocity : 0 ,
7164 time : 0 ,
7265 } ) ,
73- 100 ,
74- )
66+ ) . toBeCloseTo ( 100 )
7567
76- toMostlyEqual (
77- springValue ( spring , {
68+ expect (
69+ evaluateSpring ( spring , {
7870 from : 0 ,
7971 to : 200 ,
8072 initialVelocity : 1000 ,
8173 time : 0 ,
8274 } ) ,
83- 0 ,
84- )
75+ ) . toBeCloseTo ( 0 )
8576 } )
8677
8778 test ( 'bounce < 0' , ( ) => {
@@ -90,25 +81,23 @@ describe('spring', () => {
9081 duration : 1000 ,
9182 } )
9283
93- toMostlyEqual (
94- springValue ( spring , {
84+ expect (
85+ evaluateSpring ( spring , {
9586 from : 100 ,
9687 to : 200 ,
9788 initialVelocity : 0 ,
9889 time : 0 ,
9990 } ) ,
100- 100 ,
101- )
91+ ) . toBeCloseTo ( 100 )
10292
103- toMostlyEqual (
104- springValue ( spring , {
93+ expect (
94+ evaluateSpring ( spring , {
10595 from : 0 ,
10696 to : 200 ,
10797 initialVelocity : 1000 ,
10898 time : 0 ,
10999 } ) ,
110- 0 ,
111- )
100+ ) . toBeCloseTo ( 0 )
112101 } )
113102 } )
114103 } )
@@ -120,25 +109,23 @@ describe('spring', () => {
120109 duration : 1000 ,
121110 } )
122111
123- toMostlyEqual (
124- springVelocity ( spring , {
112+ expect (
113+ evaluateSpringVelocity ( spring , {
125114 from : 100 ,
126115 to : 100 ,
127116 initialVelocity : 0 ,
128117 time : 0 ,
129118 } ) ,
130- 0 ,
131- )
119+ ) . toBeCloseTo ( 0 )
132120
133- toMostlyEqual (
134- springVelocity ( spring , {
121+ expect (
122+ evaluateSpringVelocity ( spring , {
135123 from : 100 ,
136124 to : 100 ,
137125 initialVelocity : 1000 ,
138126 time : 0 ,
139127 } ) ,
140- 1000 ,
141- )
128+ ) . toBeCloseTo ( 1000 )
142129 } )
143130
144131 describe ( 'velocity when time = 0 must mostly equal to initialVelocity value' , ( ) => {
@@ -148,25 +135,23 @@ describe('spring', () => {
148135 duration : 1000 ,
149136 } )
150137
151- toMostlyEqual (
152- springVelocity ( spring , {
138+ expect (
139+ evaluateSpringVelocity ( spring , {
153140 from : 0 ,
154141 to : 100 ,
155142 initialVelocity : 0 ,
156143 time : 0 ,
157144 } ) ,
158- 0 ,
159- )
145+ ) . toBeCloseTo ( 0 )
160146
161- toMostlyEqual (
162- springVelocity ( spring , {
147+ expect (
148+ evaluateSpringVelocity ( spring , {
163149 from : 0 ,
164150 to : 100 ,
165151 initialVelocity : 1000 ,
166152 time : 0 ,
167153 } ) ,
168- 1000 ,
169- )
154+ ) . toBeCloseTo ( 1000 )
170155 } )
171156
172157 test ( 'bounce = 0' , ( ) => {
@@ -175,25 +160,23 @@ describe('spring', () => {
175160 duration : 1000 ,
176161 } )
177162
178- toMostlyEqual (
179- springVelocity ( spring , {
163+ expect (
164+ evaluateSpringVelocity ( spring , {
180165 from : 0 ,
181166 to : 100 ,
182167 initialVelocity : 0 ,
183168 time : 0 ,
184169 } ) ,
185- 0 ,
186- )
170+ ) . toBeCloseTo ( 0 )
187171
188- toMostlyEqual (
189- springVelocity ( spring , {
172+ expect (
173+ evaluateSpringVelocity ( spring , {
190174 from : 0 ,
191175 to : 100 ,
192176 initialVelocity : 1000 ,
193177 time : 0 ,
194178 } ) ,
195- 1000 ,
196- )
179+ ) . toBeCloseTo ( 1000 )
197180 } )
198181
199182 test ( 'bounce < 0' , ( ) => {
@@ -202,25 +185,23 @@ describe('spring', () => {
202185 duration : 1000 ,
203186 } )
204187
205- toMostlyEqual (
206- springVelocity ( spring , {
188+ expect (
189+ evaluateSpringVelocity ( spring , {
207190 from : 0 ,
208191 to : 100 ,
209192 initialVelocity : 0 ,
210193 time : 0 ,
211194 } ) ,
212- 0 ,
213- )
195+ ) . toBeCloseTo ( 0 )
214196
215- toMostlyEqual (
216- springVelocity ( spring , {
197+ expect (
198+ evaluateSpringVelocity ( spring , {
217199 from : 0 ,
218200 to : 100 ,
219201 initialVelocity : 1000 ,
220202 time : 0 ,
221203 } ) ,
222- 1000 ,
223- )
204+ ) . toBeCloseTo ( 1000 )
224205 } )
225206 } )
226207 } )
@@ -235,6 +216,7 @@ describe('spring', () => {
235216 const actual = springSettlingDuration ( spring , {
236217 from : 100 ,
237218 to : 100 ,
219+ initialVelocity : 0 ,
238220 } )
239221
240222 expect ( Number . isFinite ( actual ) ) . toBe ( true )
@@ -250,35 +232,33 @@ describe('spring', () => {
250232 duration,
251233 } )
252234
253- toMostlyEqual (
254- springValue ( spring , {
235+ expect (
236+ evaluateSpring ( spring , {
255237 from : 0 ,
256238 to : 100 ,
257239 initialVelocity : 0 ,
258240 time :
259241 springSettlingDuration ( spring , {
260242 from : 0 ,
261243 to : 100 ,
244+ initialVelocity : 0 ,
262245 } ) / duration ,
263246 } ) ,
264- 100 ,
265- 0.01 ,
266- )
247+ ) . toBeCloseTo ( 100 , 0.01 )
267248
268- toMostlyEqual (
269- springValue ( spring , {
249+ expect (
250+ evaluateSpring ( spring , {
270251 from : 0 ,
271252 to : 100 ,
272253 initialVelocity : 6000 ,
273254 time :
274255 springSettlingDuration ( spring , {
275256 from : 0 ,
276257 to : 100 ,
258+ initialVelocity : 6000 ,
277259 } ) / duration ,
278260 } ) ,
279- 100 ,
280- 0.01 ,
281- )
261+ ) . toBeCloseTo ( 100 , 0.01 )
282262 } )
283263
284264 test ( 'bounce = 0' , ( ) => {
@@ -289,34 +269,32 @@ describe('spring', () => {
289269 duration,
290270 } )
291271
292- toMostlyEqual (
293- springValue ( spring , {
272+ expect (
273+ evaluateSpring ( spring , {
294274 from : 0 ,
295275 to : 100 ,
296276 initialVelocity : 0 ,
297277 time :
298278 springSettlingDuration ( spring , {
299279 from : 0 ,
300280 to : 100 ,
281+ initialVelocity : 0 ,
301282 } ) / duration ,
302283 } ) ,
303- 100 ,
304- 0.01 ,
305- )
284+ ) . toBeCloseTo ( 100 , 0.01 )
306285
307- toMostlyEqual (
308- springValue ( spring , {
286+ expect (
287+ evaluateSpring ( spring , {
309288 from : 0 ,
310289 to : 100 ,
311290 initialVelocity : 6000 ,
312291 time : springSettlingDuration ( spring , {
313292 from : 0 ,
314293 to : 100 ,
294+ initialVelocity : 6000 ,
315295 } ) ,
316296 } ) ,
317- 100 ,
318- 0.01 ,
319- )
297+ ) . toBeCloseTo ( 100 , 0.01 )
320298 } )
321299
322300 test ( 'bounce < 0' , ( ) => {
@@ -327,35 +305,33 @@ describe('spring', () => {
327305 duration,
328306 } )
329307
330- toMostlyEqual (
331- springValue ( spring , {
308+ expect (
309+ evaluateSpring ( spring , {
332310 from : 0 ,
333311 to : 100 ,
334312 initialVelocity : 0 ,
335313 time :
336314 springSettlingDuration ( spring , {
337315 from : 0 ,
338316 to : 100 ,
317+ initialVelocity : 0 ,
339318 } ) / duration ,
340319 } ) ,
341- 100 ,
342- 0.01 ,
343- )
320+ ) . toBeCloseTo ( 100 , 0.01 )
344321
345- toMostlyEqual (
346- springValue ( spring , {
322+ expect (
323+ evaluateSpring ( spring , {
347324 from : 0 ,
348325 to : 100 ,
349326 initialVelocity : 6000 ,
350327 time :
351328 springSettlingDuration ( spring , {
352329 from : 0 ,
353330 to : 100 ,
331+ initialVelocity : 6000 ,
354332 } ) / duration ,
355333 } ) ,
356- 100 ,
357- 0.05 ,
358- )
334+ ) . toBeCloseTo ( 100 , 0.05 )
359335 } )
360336 } )
361337 } )
0 commit comments