v / vlib / math / easing / easing_test.v
37 lines · 30 sloc · 1.06 KB · 547564579df34da8d6d522d212df78c3313d5ca9
Raw
1import math.easing
2
3// Note: most of the checks are done not here, but by comparing the produced table,
4// in the .vv/.out pair, checked by:
5// `v run vlib/v/slow_tests/inout/math_easing_tables.vv > vlib/v/slow_tests/inout/math_easing_tables.out`
6
7fn test_linear() {
8 for x := -10.0; x <= 10.0; x += 0.1 {
9 assert easing.linear(x) == x
10 }
11}
12
13fn test_in_out_back() {
14 assert easing.in_out_back(0.333).eq_epsilon(-0.04451079425639395)
15 assert easing.in_out_back(3).eq_epsilon(136.79638)
16}
17
18fn test_in_out_expo() {
19 assert easing.in_out_expo(123).eq_epsilon(1.0)
20}
21
22fn test_in_bounce() {
23 assert easing.in_bounce(0.333).eq_epsilon(0.1382769374999998)
24 assert easing.in_bounce(33).eq_epsilon(-7743)
25}
26
27fn test_in_out_bounce() {
28 assert easing.in_out_bounce(0.333).eq_epsilon(0.07817887500000009)
29 assert easing.in_out_bounce(33).eq_epsilon(15511)
30}
31
32fn test_out_bounce() {
33 assert easing.out_bounce(0.200).eq_epsilon(0.30250000000000005)
34 assert easing.out_bounce(0.600).eq_epsilon(0.7725)
35 assert easing.out_bounce(0.800).eq_epsilon(0.94)
36 assert easing.out_bounce(33).eq_epsilon(7767)
37}
38