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