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