1 /* 2 * Copyright (C) 2016 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 #include <gtest/gtest.h> 18 19 #include <Interpolator.h> 20 21 namespace android { 22 namespace uirenderer { 23 24 struct TestData { 25 const std::vector<float> x; 26 const std::vector<float> y; 27 const std::vector<float> inFraction; 28 const std::vector<float> outFraction; 29 }; 30 31 const static TestData sTestDataSet[] = { 32 { 33 // Straight line as a path. 34 {0.0f, 1.0f}, 35 {0.0f, 1.0f}, 36 {0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f}, 37 {0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f}, 38 }, 39 40 { 41 { 42 0.0f, 0.5f, 0.5178955f, 0.5341797f, 0.5489991f, 0.5625f, 0.5748291f, 43 0.5861328f, 0.60625005f, 0.62402344f, 0.640625f, 0.675f, 0.6951172f, 44 0.71875f, 0.7470703f, 0.78125f, 0.82246095f, 0.84606934f, 0.871875f, 45 0.9000244f, 0.93066406f, 0.96394044f, 1.0f 46 }, 47 { 48 0.0f, 0.0f, 0.0028686523f, 0.011230469f, 0.024719238f, 0.04296875f, 49 0.06561279f, 0.092285156f, 0.15625f, 0.2319336f, 0.31640625f, 0.5f, 50 0.5932617f, 0.68359375f, 0.7680664f, 0.84375f, 0.90771484f, 0.9343872f, 51 0.95703125f, 0.97528076f, 0.98876953f, 0.99713135f, 1.0f 52 }, 53 { 54 0.0f, 0.03375840187072754f, 0.13503384590148926f, 0.23630905151367188f, 55 0.336834192276001f, 0.4508626461029053f, 0.564141035079956f, 56 0.6781694889068604f, 0.7921979427337646f, 0.9054763317108154f, 1.0f 57 }, 58 { 59 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0459827296435833f, 60 0.5146934390068054f, 0.8607426285743713f, 0.9776809215545654f, 1.0f 61 62 } 63 64 }, 65 { 66 { 67 0.0f, 0.017895509f, 0.034179688f, 0.048999026f, 0.0625f, 0.0748291f, 68 0.08613282f, 0.10625f, 0.12402344f, 0.140625f, 0.17500001f, 0.19511719f, 69 0.21875f, 0.24707031f, 0.28125f, 0.32246095f, 0.34606934f, 0.371875f, 70 0.4000244f, 0.43066406f, 0.46394044f, 0.5f, 1.0f 71 }, 72 { 73 0.0f, 0.0028686523f, 0.011230469f, 0.024719238f, 0.04296875f, 0.06561279f, 74 0.092285156f, 0.15625f, 0.2319336f, 0.31640625f, 0.5f, 0.5932617f, 75 0.68359375f, 0.7680664f, 0.84375f, 0.90771484f, 0.9343872f, 0.95703125f, 76 0.97528076f, 0.98876953f, 0.99713135f, 1.0f, 1.0f 77 }, 78 { 79 0.0f, 0.102020263671875f, 0.20330810546875f, 0.3165740966796875f, 80 0.43060302734375f, 0.5318756103515625f, 0.6331634521484375f, 81 0.746429443359375f, 0.84771728515625f, 0.9617462158203125f, 1.0f 82 }, 83 { 84 0.0f, 0.14280107617378235f, 0.6245699524879456f, 0.8985776901245117f, 85 0.9887426495552063f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f 86 } 87 }, 88 89 90 }; 91 92 static std::vector<float> getX(const TestData& data) { 93 return data.x; 94 } 95 96 static std::vector<float> getY(const TestData& data) { 97 return data.y; 98 } 99 100 TEST(Interpolator, pathInterpolation) { 101 for (const TestData& data: sTestDataSet) { 102 PathInterpolator interpolator(getX(data), getY(data)); 103 for (size_t i = 0; i < data.inFraction.size(); i++) { 104 EXPECT_FLOAT_EQ(data.outFraction[i], interpolator.interpolate(data.inFraction[i])); 105 } 106 } 107 } 108 109 } 110 } 111