1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "VelocityTracker_test"
18 
19 #include <math.h>
20 
21 #include <android-base/stringprintf.h>
22 #include <gtest/gtest.h>
23 #include <input/VelocityTracker.h>
24 
25 using android::base::StringPrintf;
26 
27 namespace android {
28 
29 constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests
30 
31 // velocity must be in the range (1-tol)*EV <= velocity <= (1+tol)*EV
32 // here EV = expected value, tol = VELOCITY_TOLERANCE
33 constexpr float VELOCITY_TOLERANCE = 0.2;
34 
35 // --- VelocityTrackerTest ---
36 class VelocityTrackerTest : public testing::Test { };
37 
checkVelocity(float Vactual,float Vtarget)38 static void checkVelocity(float Vactual, float Vtarget) {
39     // Compare directions
40     if ((Vactual > 0 && Vtarget <= 0) || (Vactual < 0 && Vtarget >= 0)) {
41         FAIL() << StringPrintf("Velocity %f does not have the same direction"
42                 " as the target velocity %f", Vactual, Vtarget);
43     }
44 
45     // Compare magnitudes
46     const float Vlower = fabsf(Vtarget * (1 - VELOCITY_TOLERANCE));
47     const float Vupper = fabsf(Vtarget * (1 + VELOCITY_TOLERANCE));
48     if (fabsf(Vactual) < Vlower) {
49         FAIL() << StringPrintf("Velocity %f is more than %.0f%% below target velocity %f",
50                 Vactual, VELOCITY_TOLERANCE * 100, Vtarget);
51     }
52     if (fabsf(Vactual) > Vupper) {
53         FAIL() << StringPrintf("Velocity %f is more than %.0f%% above target velocity %f",
54                 Vactual, VELOCITY_TOLERANCE * 100, Vtarget);
55     }
56     SUCCEED() << StringPrintf("Velocity %f within %.0f%% of target %f)",
57             Vactual, VELOCITY_TOLERANCE * 100, Vtarget);
58 }
59 
failWithMessage(std::string message)60 void failWithMessage(std::string message) {
61     FAIL() << message; // cannot do this directly from a non-void function
62 }
63 
64 struct Position {
65       nsecs_t time;
66       float x;
67       float y;
68 };
69 
70 
createSimpleMotionEvent(const Position * positions,size_t numSamples)71 MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSamples) {
72     /**
73      * Only populate the basic fields of a MotionEvent, such as time and a single axis
74      * Designed for use with manually-defined tests.
75      * Create a new MotionEvent on the heap, caller responsible for destroying the object.
76      */
77     if (numSamples < 1) {
78         failWithMessage(StringPrintf("Need at least 1 sample to create a MotionEvent."
79                 " Received numSamples=%zu", numSamples));
80     }
81 
82     MotionEvent* event = new MotionEvent();
83     PointerCoords coords;
84     PointerProperties properties[1];
85 
86     properties[0].id = DEFAULT_POINTER_ID;
87     properties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
88 
89     // First sample added separately with initialize
90     coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[0].x);
91     coords.setAxisValue(AMOTION_EVENT_AXIS_Y, positions[0].y);
92     event->initialize(0, AINPUT_SOURCE_TOUCHSCREEN, AMOTION_EVENT_ACTION_MOVE,
93             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, positions[0].time, 1, properties, &coords);
94 
95     for (size_t i = 1; i < numSamples; i++) {
96         coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[i].x);
97         coords.setAxisValue(AMOTION_EVENT_AXIS_Y, positions[i].y);
98         event->addSample(positions[i].time, &coords);
99     }
100     return event;
101 }
102 
computeAndCheckVelocity(const Position * positions,size_t numSamples,int32_t axis,float targetVelocity)103 static void computeAndCheckVelocity(const Position* positions, size_t numSamples,
104             int32_t axis, float targetVelocity) {
105     VelocityTracker vt(nullptr);
106     float Vx, Vy;
107 
108     MotionEvent* event = createSimpleMotionEvent(positions, numSamples);
109     vt.addMovement(event);
110 
111     vt.getVelocity(DEFAULT_POINTER_ID, &Vx, &Vy);
112 
113     switch (axis) {
114     case AMOTION_EVENT_AXIS_X:
115         checkVelocity(Vx, targetVelocity);
116         break;
117     case AMOTION_EVENT_AXIS_Y:
118         checkVelocity(Vy, targetVelocity);
119         break;
120     default:
121         FAIL() << "Axis must be either AMOTION_EVENT_AXIS_X or AMOTION_EVENT_AXIS_Y";
122     }
123     delete event;
124 }
125 
126 /*
127  * ================== VelocityTracker tests generated manually =====================================
128  */
129  // @todo Currently disabled, enable when switching away from lsq2 VelocityTrackerStrategy
TEST_F(VelocityTrackerTest,DISABLED_ThreePointsPositiveVelocityTest)130 TEST_F(VelocityTrackerTest, DISABLED_ThreePointsPositiveVelocityTest) {
131     // Same coordinate is reported 2 times in a row
132     // It is difficult to determine the correct answer here, but at least the direction
133     // of the reported velocity should be positive.
134     Position values[] = {
135         { 0, 273, NAN },
136         { 12585000, 293, NAN },
137         { 14730000, 293, NAN },
138     };
139     size_t count = sizeof(values) / sizeof(Position);
140     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 1600);
141 }
142 
TEST_F(VelocityTrackerTest,ThreePointsZeroVelocityTest)143 TEST_F(VelocityTrackerTest, ThreePointsZeroVelocityTest) {
144     // Same coordinate is reported 3 times in a row
145     Position values[] = {
146         { 0, 293, NAN },
147         { 6132000, 293, NAN },
148         { 11283000, 293, NAN },
149     };
150     size_t count = sizeof(values) / sizeof(Position);
151     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 0);
152 }
153 
TEST_F(VelocityTrackerTest,ThreePointsLinearVelocityTest)154 TEST_F(VelocityTrackerTest, ThreePointsLinearVelocityTest) {
155     // Fixed velocity at 5 points per 10 milliseconds
156     Position values[] = {
157         { 0, 0, NAN },
158         { 10000000, 5, NAN },
159         { 20000000, 10, NAN },
160     };
161     size_t count = sizeof(values) / sizeof(Position);
162     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 500);
163 }
164 
165 
166 /**
167  * ================== VelocityTracker tests generated by recording real events =====================
168  *
169  * To add a test, record the input coordinates and event times to all calls
170  * to void VelocityTracker::addMovement(const MotionEvent* event).
171  * Also record all calls to VelocityTracker::clear().
172  * Finally, record the output of VelocityTracker::getVelocity(...)
173  * This will give you the necessary data to create a new test.
174  */
175 
176 // --------------- Recorded by hand on swordfish ---------------------------------------------------
177 // @todo Currently disabled, enable when switching away from lsq2 VelocityTrackerStrategy
TEST_F(VelocityTrackerTest,DISABLED_SwordfishFlingDown)178 TEST_F(VelocityTrackerTest, DISABLED_SwordfishFlingDown) {
179     // Recording of a fling on Swordfish that could cause a fling in the wrong direction
180     Position values[] = {
181         { 0, 271, 96 },
182         { 16071042, 269.786346, 106.922775 },
183         { 35648403, 267.983063, 156.660034 },
184         { 52313925, 262.638397, 220.339081 },
185         { 68976522, 266.138824, 331.581116 },
186         { 85639375, 274.79245, 428.113159 },
187         { 96948871, 274.79245, 428.113159 },
188     };
189     size_t count = sizeof(values) / sizeof(Position);
190     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 623.577637);
191     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 8523.348633);
192 }
193 
194 // --------------- Recorded by hand on sailfish, generated by a script -----------------------------
195 // For some of these tests, the X-direction velocity checking has been removed, because the lsq2
196 // and the impulse VelocityTrackerStrategies did not agree within 20%.
197 // Since the flings were recorded in the Y-direction, the intentional user action should only
198 // be relevant for the Y axis.
199 // There have been also cases where lsq2 and impulse disagreed more than 20% in the Y-direction.
200 // Those recordings have been discarded because we didn't feel one strategy's interpretation was
201 // more correct than another's but didn't want to increase the tolerance for the entire test suite.
202 //
203 // There are 18 tests total below: 9 in the positive Y direction and 9 in the opposite.
204 // The recordings were loosely binned into 3 categories - slow, faster, and fast, which roughly
205 // characterizes the velocity of the finger motion.
206 // These can be treated approximately as:
207 // slow - less than 1 page gets scrolled
208 // faster - more than 1 page gets scrolled, but less than 3
209 // fast - entire list is scrolled (fling is done as hard as possible)
210 
TEST_F(VelocityTrackerTest,SailfishFlingUpSlow1)211 TEST_F(VelocityTrackerTest, SailfishFlingUpSlow1) {
212     // Sailfish - fling up - slow - 1
213     Position values[] = {
214         { 235089067457000, 528.00, 983.00 },
215         { 235089084684000, 527.00, 981.00 },
216         { 235089093349000, 527.00, 977.00 },
217         { 235089095677625, 527.00, 975.93 },
218         { 235089101859000, 527.00, 970.00 },
219         { 235089110378000, 528.00, 960.00 },
220         { 235089112497111, 528.25, 957.51 },
221         { 235089118760000, 531.00, 946.00 },
222         { 235089126686000, 535.00, 931.00 },
223         { 235089129316820, 536.33, 926.02 },
224         { 235089135199000, 540.00, 914.00 },
225         { 235089144297000, 546.00, 896.00 },
226         { 235089146136443, 547.21, 892.36 },
227         { 235089152923000, 553.00, 877.00 },
228         { 235089160784000, 559.00, 851.00 },
229         { 235089162955851, 560.66, 843.82 },
230     };
231     size_t count = sizeof(values) / sizeof(Position);
232     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 872.794617); // impulse
233     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 951.698181); // lsq2
234     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -3604.819336); // impulse
235     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -3044.966064); // lsq2
236 }
237 
238 
TEST_F(VelocityTrackerTest,SailfishFlingUpSlow2)239 TEST_F(VelocityTrackerTest, SailfishFlingUpSlow2) {
240     // Sailfish - fling up - slow - 2
241     Position values[] = {
242         { 235110560704000, 522.00, 1107.00 },
243         { 235110575764000, 522.00, 1107.00 },
244         { 235110584385000, 522.00, 1107.00 },
245         { 235110588421179, 521.52, 1106.52 },
246         { 235110592830000, 521.00, 1106.00 },
247         { 235110601385000, 520.00, 1104.00 },
248         { 235110605088160, 519.14, 1102.27 },
249         { 235110609952000, 518.00, 1100.00 },
250         { 235110618353000, 517.00, 1093.00 },
251         { 235110621755146, 516.60, 1090.17 },
252         { 235110627010000, 517.00, 1081.00 },
253         { 235110634785000, 518.00, 1063.00 },
254         { 235110638422450, 518.87, 1052.58 },
255         { 235110643161000, 520.00, 1039.00 },
256         { 235110651767000, 524.00, 1011.00 },
257         { 235110655089581, 525.54, 1000.19 },
258         { 235110660368000, 530.00, 980.00 },
259     };
260     size_t count = sizeof(values) / sizeof(Position);
261     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -4096.583008); // impulse
262     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -3455.094238); // lsq2
263 }
264 
265 
TEST_F(VelocityTrackerTest,SailfishFlingUpSlow3)266 TEST_F(VelocityTrackerTest, SailfishFlingUpSlow3) {
267     // Sailfish - fling up - slow - 3
268     Position values[] = {
269         { 792536237000, 580.00, 1317.00 },
270         { 792541538987, 580.63, 1311.94 },
271         { 792544613000, 581.00, 1309.00 },
272         { 792552301000, 583.00, 1295.00 },
273         { 792558362309, 585.13, 1282.92 },
274         { 792560828000, 586.00, 1278.00 },
275         { 792569446000, 589.00, 1256.00 },
276         { 792575185095, 591.54, 1241.41 },
277         { 792578491000, 593.00, 1233.00 },
278         { 792587044000, 597.00, 1211.00 },
279         { 792592008172, 600.28, 1195.92 },
280         { 792594616000, 602.00, 1188.00 },
281         { 792603129000, 607.00, 1167.00 },
282         { 792608831290, 609.48, 1155.83 },
283         { 792612321000, 611.00, 1149.00 },
284         { 792620768000, 615.00, 1131.00 },
285         { 792625653873, 617.32, 1121.73 },
286         { 792629200000, 619.00, 1115.00 },
287     };
288     size_t count = sizeof(values) / sizeof(Position);
289     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 574.33429); // impulse
290     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 617.40564); // lsq2
291     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -2361.982666); // impulse
292     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -2500.055664); // lsq2
293 }
294 
295 
TEST_F(VelocityTrackerTest,SailfishFlingUpFaster1)296 TEST_F(VelocityTrackerTest, SailfishFlingUpFaster1) {
297     // Sailfish - fling up - faster - 1
298     Position values[] = {
299         { 235160420675000, 610.00, 1042.00 },
300         { 235160428220000, 609.00, 1026.00 },
301         { 235160436544000, 609.00, 1024.00 },
302         { 235160441852394, 609.64, 1020.82 },
303         { 235160444878000, 610.00, 1019.00 },
304         { 235160452673000, 613.00, 1006.00 },
305         { 235160458519743, 617.18, 992.06 },
306         { 235160461061000, 619.00, 986.00 },
307         { 235160469798000, 627.00, 960.00 },
308         { 235160475186713, 632.22, 943.02 },
309         { 235160478051000, 635.00, 934.00 },
310         { 235160486489000, 644.00, 906.00 },
311         { 235160491853697, 649.56, 890.56 },
312         { 235160495177000, 653.00, 881.00 },
313         { 235160504148000, 662.00, 858.00 },
314         { 235160509231495, 666.81, 845.37 },
315         { 235160512603000, 670.00, 837.00 },
316         { 235160520366000, 679.00, 814.00 },
317     };
318     size_t count = sizeof(values) / sizeof(Position);
319     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 1274.141724); // impulse
320     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 1438.53186); // lsq2
321     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -3877.35498); // impulse
322     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -3695.859619); // lsq2
323 }
324 
325 
TEST_F(VelocityTrackerTest,SailfishFlingUpFaster2)326 TEST_F(VelocityTrackerTest, SailfishFlingUpFaster2) {
327     // Sailfish - fling up - faster - 2
328     Position values[] = {
329         { 847153808000, 576.00, 1264.00 },
330         { 847171174000, 576.00, 1262.00 },
331         { 847179640000, 576.00, 1257.00 },
332         { 847185187540, 577.41, 1249.22 },
333         { 847187487000, 578.00, 1246.00 },
334         { 847195710000, 581.00, 1227.00 },
335         { 847202027059, 583.93, 1209.40 },
336         { 847204324000, 585.00, 1203.00 },
337         { 847212672000, 590.00, 1176.00 },
338         { 847218861395, 594.36, 1157.11 },
339         { 847221190000, 596.00, 1150.00 },
340         { 847230484000, 602.00, 1124.00 },
341         { 847235701400, 607.56, 1103.83 },
342         { 847237986000, 610.00, 1095.00 },
343     };
344     size_t count = sizeof(values) / sizeof(Position);
345     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -4280.07959); // impulse
346     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -4241.004395); // lsq2
347 }
348 
349 
TEST_F(VelocityTrackerTest,SailfishFlingUpFaster3)350 TEST_F(VelocityTrackerTest, SailfishFlingUpFaster3) {
351     // Sailfish - fling up - faster - 3
352     Position values[] = {
353         { 235200532789000, 507.00, 1084.00 },
354         { 235200549221000, 507.00, 1083.00 },
355         { 235200557841000, 507.00, 1081.00 },
356         { 235200558051189, 507.00, 1080.95 },
357         { 235200566314000, 507.00, 1078.00 },
358         { 235200574876586, 508.97, 1070.12 },
359         { 235200575006000, 509.00, 1070.00 },
360         { 235200582900000, 514.00, 1054.00 },
361         { 235200591276000, 525.00, 1023.00 },
362         { 235200591701829, 525.56, 1021.42 },
363         { 235200600064000, 542.00, 976.00 },
364         { 235200608519000, 563.00, 911.00 },
365         { 235200608527086, 563.02, 910.94 },
366         { 235200616933000, 590.00, 844.00 },
367     };
368     size_t count = sizeof(values) / sizeof(Position);
369     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -8715.686523); // impulse
370     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -7639.026367); // lsq2
371 }
372 
373 
TEST_F(VelocityTrackerTest,SailfishFlingUpFast1)374 TEST_F(VelocityTrackerTest, SailfishFlingUpFast1) {
375     // Sailfish - fling up - fast - 1
376     Position values[] = {
377         { 920922149000, 561.00, 1412.00 },
378         { 920930185000, 559.00, 1377.00 },
379         { 920930262463, 558.98, 1376.66 },
380         { 920938547000, 559.00, 1371.00 },
381         { 920947096857, 562.91, 1342.68 },
382         { 920947302000, 563.00, 1342.00 },
383         { 920955502000, 577.00, 1272.00 },
384         { 920963931021, 596.87, 1190.54 },
385         { 920963987000, 597.00, 1190.00 },
386         { 920972530000, 631.00, 1093.00 },
387         { 920980765511, 671.31, 994.68 },
388         { 920980906000, 672.00, 993.00 },
389         { 920989261000, 715.00, 903.00 },
390     };
391     size_t count = sizeof(values) / sizeof(Position);
392     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 5670.329102); // impulse
393     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, 5991.866699); // lsq2
394     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -13021.101562); // impulse
395     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -15093.995117); // lsq2
396 }
397 
398 
TEST_F(VelocityTrackerTest,SailfishFlingUpFast2)399 TEST_F(VelocityTrackerTest, SailfishFlingUpFast2) {
400     // Sailfish - fling up - fast - 2
401     Position values[] = {
402         { 235247153233000, 518.00, 1168.00 },
403         { 235247170452000, 517.00, 1167.00 },
404         { 235247178908000, 515.00, 1159.00 },
405         { 235247179556213, 514.85, 1158.39 },
406         { 235247186821000, 515.00, 1125.00 },
407         { 235247195265000, 521.00, 1051.00 },
408         { 235247196389476, 521.80, 1041.15 },
409         { 235247203649000, 538.00, 932.00 },
410         { 235247212253000, 571.00, 794.00 },
411         { 235247213222491, 574.72, 778.45 },
412         { 235247220736000, 620.00, 641.00 },
413     };
414     size_t count = sizeof(values) / sizeof(Position);
415     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -20286.958984); // impulse
416     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -20494.587891); // lsq2
417 }
418 
419 
TEST_F(VelocityTrackerTest,SailfishFlingUpFast3)420 TEST_F(VelocityTrackerTest, SailfishFlingUpFast3) {
421     // Sailfish - fling up - fast - 3
422     Position values[] = {
423         { 235302568736000, 529.00, 1167.00 },
424         { 235302576644000, 523.00, 1140.00 },
425         { 235302579395063, 520.91, 1130.61 },
426         { 235302585140000, 522.00, 1130.00 },
427         { 235302593615000, 527.00, 1065.00 },
428         { 235302596207444, 528.53, 1045.12 },
429         { 235302602102000, 559.00, 872.00 },
430         { 235302610545000, 652.00, 605.00 },
431         { 235302613019881, 679.26, 526.73 },
432     };
433     size_t count = sizeof(values) / sizeof(Position);
434     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -39295.941406); // impulse
435     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, -36461.421875); // lsq2
436 }
437 
438 
TEST_F(VelocityTrackerTest,SailfishFlingDownSlow1)439 TEST_F(VelocityTrackerTest, SailfishFlingDownSlow1) {
440     // Sailfish - fling down - slow - 1
441     Position values[] = {
442         { 235655749552755, 582.00, 432.49 },
443         { 235655750638000, 582.00, 433.00 },
444         { 235655758865000, 582.00, 440.00 },
445         { 235655766221523, 581.16, 448.43 },
446         { 235655767594000, 581.00, 450.00 },
447         { 235655776044000, 580.00, 462.00 },
448         { 235655782890696, 579.18, 474.35 },
449         { 235655784360000, 579.00, 477.00 },
450         { 235655792795000, 578.00, 496.00 },
451         { 235655799559531, 576.27, 515.04 },
452         { 235655800612000, 576.00, 518.00 },
453         { 235655809535000, 574.00, 542.00 },
454         { 235655816988015, 572.17, 564.86 },
455         { 235655817685000, 572.00, 567.00 },
456         { 235655825981000, 569.00, 595.00 },
457         { 235655833808653, 566.26, 620.60 },
458         { 235655834541000, 566.00, 623.00 },
459         { 235655842893000, 563.00, 649.00 },
460     };
461     size_t count = sizeof(values) / sizeof(Position);
462     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -419.749695); // impulse
463     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -398.303894); // lsq2
464     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 3309.016357); // impulse
465     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 3969.099854); // lsq2
466 }
467 
468 
TEST_F(VelocityTrackerTest,SailfishFlingDownSlow2)469 TEST_F(VelocityTrackerTest, SailfishFlingDownSlow2) {
470     // Sailfish - fling down - slow - 2
471     Position values[] = {
472         { 235671152083370, 485.24, 558.28 },
473         { 235671154126000, 485.00, 559.00 },
474         { 235671162497000, 484.00, 566.00 },
475         { 235671168750511, 483.27, 573.29 },
476         { 235671171071000, 483.00, 576.00 },
477         { 235671179390000, 482.00, 588.00 },
478         { 235671185417210, 481.31, 598.98 },
479         { 235671188173000, 481.00, 604.00 },
480         { 235671196371000, 480.00, 624.00 },
481         { 235671202084196, 479.27, 639.98 },
482         { 235671204235000, 479.00, 646.00 },
483         { 235671212554000, 478.00, 673.00 },
484         { 235671219471011, 476.39, 697.12 },
485         { 235671221159000, 476.00, 703.00 },
486         { 235671229592000, 474.00, 734.00 },
487         { 235671236281462, 472.43, 758.38 },
488         { 235671238098000, 472.00, 765.00 },
489         { 235671246532000, 470.00, 799.00 },
490     };
491     size_t count = sizeof(values) / sizeof(Position);
492     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -262.80426); // impulse
493     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -243.665344); // lsq2
494     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4215.682129); // impulse
495     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4587.986816); // lsq2
496 }
497 
498 
TEST_F(VelocityTrackerTest,SailfishFlingDownSlow3)499 TEST_F(VelocityTrackerTest, SailfishFlingDownSlow3) {
500     // Sailfish - fling down - slow - 3
501     Position values[] = {
502         { 170983201000, 557.00, 533.00 },
503         { 171000668000, 556.00, 534.00 },
504         { 171007359750, 554.73, 535.27 },
505         { 171011197000, 554.00, 536.00 },
506         { 171017660000, 552.00, 540.00 },
507         { 171024201831, 549.97, 544.73 },
508         { 171027333000, 549.00, 547.00 },
509         { 171034603000, 545.00, 557.00 },
510         { 171041043371, 541.98, 567.55 },
511         { 171043147000, 541.00, 571.00 },
512         { 171051052000, 536.00, 586.00 },
513     };
514     size_t count = sizeof(values) / sizeof(Position);
515     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -723.413513); // impulse
516     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -651.038452); // lsq2
517     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 2091.502441); // impulse
518     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 1934.517456); // lsq2
519 }
520 
521 
TEST_F(VelocityTrackerTest,SailfishFlingDownFaster1)522 TEST_F(VelocityTrackerTest, SailfishFlingDownFaster1) {
523     // Sailfish - fling down - faster - 1
524     Position values[] = {
525         { 235695280333000, 558.00, 451.00 },
526         { 235695283971237, 558.43, 454.45 },
527         { 235695289038000, 559.00, 462.00 },
528         { 235695297388000, 561.00, 478.00 },
529         { 235695300638465, 561.83, 486.25 },
530         { 235695305265000, 563.00, 498.00 },
531         { 235695313591000, 564.00, 521.00 },
532         { 235695317305492, 564.43, 532.68 },
533         { 235695322181000, 565.00, 548.00 },
534         { 235695330709000, 565.00, 577.00 },
535         { 235695333972227, 565.00, 588.10 },
536         { 235695339250000, 565.00, 609.00 },
537         { 235695347839000, 565.00, 642.00 },
538         { 235695351313257, 565.00, 656.18 },
539         { 235695356412000, 565.00, 677.00 },
540         { 235695364899000, 563.00, 710.00 },
541         { 235695368118682, 562.24, 722.52 },
542         { 235695373403000, 564.00, 744.00 },
543     };
544     size_t count = sizeof(values) / sizeof(Position);
545     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4254.639648); // impulse
546     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4698.415039); // lsq2
547 }
548 
549 
TEST_F(VelocityTrackerTest,SailfishFlingDownFaster2)550 TEST_F(VelocityTrackerTest, SailfishFlingDownFaster2) {
551     // Sailfish - fling down - faster - 2
552     Position values[] = {
553         { 235709624766000, 535.00, 579.00 },
554         { 235709642256000, 534.00, 580.00 },
555         { 235709643350278, 533.94, 580.06 },
556         { 235709650760000, 532.00, 584.00 },
557         { 235709658615000, 530.00, 593.00 },
558         { 235709660170495, 529.60, 594.78 },
559         { 235709667095000, 527.00, 606.00 },
560         { 235709675616000, 524.00, 628.00 },
561         { 235709676983261, 523.52, 631.53 },
562         { 235709684289000, 521.00, 652.00 },
563         { 235709692763000, 518.00, 682.00 },
564         { 235709693804993, 517.63, 685.69 },
565         { 235709701438000, 515.00, 709.00 },
566         { 235709709830000, 512.00, 739.00 },
567         { 235709710626776, 511.72, 741.85 },
568     };
569     size_t count = sizeof(values) / sizeof(Position);
570     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -430.440247); // impulse
571     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -447.600311); // lsq2
572     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 3953.859375); // impulse
573     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4316.155273); // lsq2
574 }
575 
576 
TEST_F(VelocityTrackerTest,SailfishFlingDownFaster3)577 TEST_F(VelocityTrackerTest, SailfishFlingDownFaster3) {
578     // Sailfish - fling down - faster - 3
579     Position values[] = {
580         { 235727628927000, 540.00, 440.00 },
581         { 235727636810000, 537.00, 454.00 },
582         { 235727646176000, 536.00, 454.00 },
583         { 235727653586628, 535.12, 456.65 },
584         { 235727654557000, 535.00, 457.00 },
585         { 235727663024000, 534.00, 465.00 },
586         { 235727670410103, 533.04, 479.45 },
587         { 235727670691000, 533.00, 480.00 },
588         { 235727679255000, 531.00, 501.00 },
589         { 235727687233704, 529.09, 526.73 },
590         { 235727687628000, 529.00, 528.00 },
591         { 235727696113000, 526.00, 558.00 },
592         { 235727704057546, 523.18, 588.98 },
593         { 235727704576000, 523.00, 591.00 },
594         { 235727713099000, 520.00, 626.00 },
595         { 235727720880776, 516.33, 655.36 },
596         { 235727721580000, 516.00, 658.00 },
597     };
598     size_t count = sizeof(values) / sizeof(Position);
599     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4484.617676); // impulse
600     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 4927.92627); // lsq2
601 }
602 
603 
TEST_F(VelocityTrackerTest,SailfishFlingDownFast1)604 TEST_F(VelocityTrackerTest, SailfishFlingDownFast1) {
605     // Sailfish - fling down - fast - 1
606     Position values[] = {
607         { 235762352849000, 467.00, 286.00 },
608         { 235762360250000, 443.00, 344.00 },
609         { 235762362787412, 434.77, 363.89 },
610         { 235762368807000, 438.00, 359.00 },
611         { 235762377220000, 425.00, 423.00 },
612         { 235762379608561, 421.31, 441.17 },
613         { 235762385698000, 412.00, 528.00 },
614         { 235762394133000, 406.00, 648.00 },
615         { 235762396429369, 404.37, 680.67 },
616     };
617     size_t count = sizeof(values) / sizeof(Position);
618     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 19084.931641); // impulse
619     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 16064.685547); // lsq2
620 }
621 
622 
TEST_F(VelocityTrackerTest,SailfishFlingDownFast2)623 TEST_F(VelocityTrackerTest, SailfishFlingDownFast2) {
624     // Sailfish - fling down - fast - 2
625     Position values[] = {
626         { 235772487188000, 576.00, 204.00 },
627         { 235772495159000, 553.00, 236.00 },
628         { 235772503568000, 551.00, 240.00 },
629         { 235772508192247, 545.55, 254.17 },
630         { 235772512051000, 541.00, 266.00 },
631         { 235772520794000, 520.00, 337.00 },
632         { 235772525015263, 508.92, 394.43 },
633         { 235772529174000, 498.00, 451.00 },
634         { 235772537635000, 484.00, 589.00 },
635     };
636     size_t count = sizeof(values) / sizeof(Position);
637     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 18660.048828); // impulse
638     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 16918.439453); // lsq2
639 }
640 
641 
TEST_F(VelocityTrackerTest,SailfishFlingDownFast3)642 TEST_F(VelocityTrackerTest, SailfishFlingDownFast3) {
643     // Sailfish - fling down - fast - 3
644     Position values[] = {
645         { 507650295000, 628.00, 233.00 },
646         { 507658234000, 605.00, 269.00 },
647         { 507666784000, 601.00, 274.00 },
648         { 507669660483, 599.65, 275.68 },
649         { 507675427000, 582.00, 308.00 },
650         { 507683740000, 541.00, 404.00 },
651         { 507686506238, 527.36, 435.95 },
652         { 507692220000, 487.00, 581.00 },
653         { 507700707000, 454.00, 792.00 },
654         { 507703352649, 443.71, 857.77 },
655     };
656     size_t count = sizeof(values) / sizeof(Position);
657     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -6772.508301); // impulse
658     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_X, -6388.48877); // lsq2
659     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 29765.908203); // impulse
660     computeAndCheckVelocity(values, count, AMOTION_EVENT_AXIS_Y, 28354.796875); // lsq2
661 }
662 
663 
664 } // namespace android
665