-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for easing function #608
Add unit test for easing function #608
Conversation
…N.Easing.InOut() should be 0.5 at midpoint"
Back.in() and Back.Out() now have limits. Sinusoidal.In() and .InOut() are replaced with Math.sin from Math.cos. Because 1 - Math.cos(Math.PI / 2) = 0.99999999999 and it does not snap to 1.
@@ -159,11 +159,11 @@ const Easing = { | |||
Back: { | |||
In: function (amount: number): number { | |||
const s = 1.70158 | |||
return amount * amount * ((s + 1) * amount - s) | |||
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fix a jump?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Back.In(1.0) = 0.9999999999999998
This jump is not visually problematic, but it is not enough to pass the test.
As the jump is very small, I did not modify the process and added a truncation.
Hey, nice stuff! What do you mean by "The purpose of this test is to check if results of the function changes depending on the version of node.js."? |
In(amount: number): number | ||
Out(amount: number): number | ||
InOut(amount: number): number | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I suppose this can be moved to the definition of the function groups in https://github.com/tweenjs/tween.js/blob/master/src/Easing.ts, then imported here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During the writing of this test, I considered how to add the definition to Easing.ts
.
In order to add the EasingFunctionGroup type definition, we had to modify the export of index.ts.
I thought it would be excessive to modify index.ts to add tests, so I added a type definition to test.ts.
In the future, I also think that adding a type definition to Easing.ts is the best way to go.
If node.js is updated and the decimal point handling or Math class handling changes, this test will detect the change. CI of tween.js supports multiple versions of node.js. Therefore, it is easy to determine which version the change occurred in. A possibility of such a disruptive change in node.js is very low. However, tracking with CI does not waste developers' time. I think it's a good deal to add a few dozen lines of test code to save our collaborators' valuable time. |
Related Issues
Purpose of this Pull Request
This PR is for adding unit tests to TWEEN.Easing functions.
Details of the changes
'Test TWEEN.Easing should starts at 0.0, ends at 1.0. TWEEN.Easing.InOut() should be 0.5 at midpoint'
Based on #507, this test checks that all easing functions satisfy conditions
f(0) = 0.0
,f(1.0) = 1.0
. This test also checks thatEasing.InOut(0.5) = 0.5
.'Test TWEEN.Easing should pass a specific value'
This test verifies that a result of
f(Math.LOG10E)
is not broken. The purpose of this test is to check if results of the function changes depending on the version of node.js.toBeCloseTo
are based on jest's functions.fix Sinusoidal easing
tween.js/src/Easing.ts
Line 73 in d8b4f09
Because
1 - Math.cos(1.0 * Math.PI / 2) = 0.99999999999
, it does not snap to 1.0.By replacing Math.cos with Math.sin, this function snap to 1.0.
fix Back easing
Added truncation of 1.0 and 0.0.