-
Notifications
You must be signed in to change notification settings - Fork 2
/
veasing_test.v
207 lines (173 loc) · 4.44 KB
/
veasing_test.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import veasing
import math
//
// Veasing Tests
//
//
// Linear tests
fn test_linear_interpolation() {
assert compare(veasing.linear_interpolation(2), 2.00)
}
//
// Quadratic tests
fn test_quadratic_ease_in() {
assert compare(veasing.quadratic_ease_in(2), 4.00)
}
fn test_quadratic_ease_out() {
assert compare(veasing.quadratic_ease_out(5), -15.00)
}
fn test_quadratic_ease_in_out() {
// p < 0.5
assert compare(veasing.quadratic_ease_in_out(0.4), 0.32)
// p >= 0.5
assert compare(veasing.quadratic_ease_in_out(0.6), 0.68)
}
//
// Cubic tests
fn test_cubic_ease_in() {
assert compare(veasing.cubic_ease_in(3), 27.00)
}
fn test_cubic_ease_out() {
assert compare(veasing.cubic_ease_out(4), 28.00)
}
fn test_cubic_ease_in_out() {
// p < 0.5
assert compare(veasing.cubic_ease_in_out(0.4), 0.256)
// p >= 0.5
assert compare(veasing.cubic_ease_in_out(0.6), 0.744)
}
//
// Quadratic tests
fn test_quartic_ease_in() {
assert compare(veasing.quartic_ease_in(3), 81.00)
}
fn test_quartic_ease_out() {
assert compare(veasing.quartic_ease_out(3), -15.00)
}
fn test_quartic_ease_in_out() {
// p < 0.5
assert compare(veasing.quartic_ease_in_out(0.4), 0.2048)
// p >= 0.5
assert compare(veasing.quartic_ease_in_out(0.6), 0.7952)
}
//
// Quintic tests
fn test_quintic_ease_in() {
assert compare(veasing.quintic_ease_in(4), 1024.00)
}
fn test_quintic_ease_out() {
assert compare(veasing.quintic_ease_out(4), 244.00)
}
fn test_quintic_ease_in_out() {
// p < 0.5
assert compare(veasing.quintic_ease_in_out(0.4), 0.16384)
// p >= 0.5
assert compare(veasing.quintic_ease_in_out(0.6), 0.83616)
}
//
// Sine tests
fn test_sine_ease_in() {
assert compare(veasing.sine_ease_in(3), 1.00)
}
fn test_sine_ease_out() {
assert compare(veasing.sine_ease_out(3), 0.000000)
}
fn test_sine_ease_in_out() {
assert compare(veasing.sine_ease_in_out(3), 1.00)
}
//
// Circular tests
fn test_circular_ease_in() {
assert compare(veasing.circular_ease_in(0.4), 0.083485)
}
fn test_circular_ease_out() {
assert compare(veasing.circular_ease_out(0.4), 0.80)
}
fn test_circular_ease_in_out() {
// p < 0.5
assert compare(veasing.circular_ease_in_out(0.4), 0.20)
// p >= 0.5
assert compare(veasing.circular_ease_in_out(0.6), 0.80)
}
//
// Exponential tests
fn test_exponential_ease_in() {
assert compare(veasing.exponential_ease_in(2), 1024.00)
}
fn test_exponential_ease_out() {
assert compare(veasing.exponential_ease_out(2), 0.999999)
}
fn test_exponential_ease_in_out() {
// p = 0
assert compare(veasing.exponential_ease_in_out(0), 0.00)
// p = 1
assert compare(veasing.exponential_ease_in_out(1), 1.00)
// p < 0.5
assert compare(veasing.exponential_ease_in_out(0.4), 0.125)
// p >= 0.5
assert compare(veasing.exponential_ease_in_out(0.6), 0.875)
}
//
// Elastic tests
fn test_elastic_ease_in() {
assert compare(veasing.elastic_ease_in(2), 0.00)
}
fn test_elastic_ease_out() {
assert compare(veasing.elastic_ease_out(2), 1.00)
}
fn test_elastic_ease_in_out() {
// p < 0.5
assert compare(veasing.elastic_ease_in_out(0.4), 0.073473)
// p >= 0.5
assert compare(veasing.elastic_ease_in_out(0.6), 1.073473)
}
//
// Back tests
fn test_back_ease_in() {
assert compare(veasing.back_ease_in(2), 8.00)
}
fn test_back_ease_out() {
assert compare(veasing.back_ease_out(2), 2.00)
}
fn test_back_ease_in_out() {
// p < 0.5
assert compare(veasing.back_ease_in_out(0.4), 0.020886)
// p >= 0.5
assert compare(veasing.back_ease_in_out(0.6), 0.979114)
}
//
// Bounce tests
fn test_bounce_ease_in() {
assert compare(veasing.bounce_ease_in(2), -6.562500)
}
fn test_bounce_ease_out() {
// p < 4 / 11.0
assert compare(veasing.bounce_ease_out(0.35), 0.926406)
// p < 8.0 / 11.0
assert compare(veasing.bounce_ease_out(0.70), 0.916750)
// p < 9.0 / 10.0
assert compare(veasing.bounce_ease_out(0.89), 0.980365)
// p >= 9.0 / 10.0
assert compare(veasing.bounce_ease_out(0.91), 0.990280)
}
fn test_bounce_ease_in_out() {
// p < 0.5
assert compare(veasing.bounce_ease_in_out(0.4), 0.348750)
// p >= 0.5
assert compare(veasing.bounce_ease_in_out(0.6), 0.651250)
}
//
// Helper method for comparing floats
fn compare(x f64, y f64) bool {
tolerance := 0.00001
// Special case for zeroes
if x < tolerance && x > (-1.0 * tolerance) && y < tolerance && y > (-1.0 * tolerance) {
return true
}
diff := math.abs(x - y)
mean := math.abs(x + y) / 2.0
if math.is_nan(diff / mean) {
return true
}
return (diff / mean) < tolerance
}