1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "animator/interpolation.h" 17 18 #include <climits> 19 #include <gtest/gtest.h> 20 21 using namespace testing::ext; 22 namespace OHOS { 23 namespace { 24 constexpr float U1 = 0.5f; 25 constexpr float U2 = 0.25f; 26 constexpr float U3 = 0.125f; 27 constexpr float U4 = 0.5f; 28 constexpr float PRECISION = 0.001f; 29 } 30 class InterpolationTest : public testing::Test { 31 public: SetUpTestCase(void)32 static void SetUpTestCase(void) {} TearDownTestCase(void)33 static void TearDownTestCase(void) {} 34 }; 35 36 /** 37 * @tc.name: InterpolationGetBezierInterpolation_001 38 * @tc.desc: Verify GetBezierInterpolation function, equal. 39 * @tc.type: FUNC 40 * @tc.require: AR000DSMQM 41 */ 42 HWTEST_F(InterpolationTest, InterpolationGetBezierInterpolation_001, TestSize.Level0) 43 { 44 float ret = Interpolation::GetBezierInterpolation(0.2f, U1, U2, U3, U4); // 0.2f:current change rate; 45 EXPECT_NEAR(0.368, ret, PRECISION); // 0.368:current change rate; 46 ret = Interpolation::GetBezierInterpolation(0.5f, U1, U2, U3, U4); // 0.5f:current change rate; 47 EXPECT_NEAR(0.266, ret, PRECISION); // 0.266:current change rate; 48 ret = Interpolation::GetBezierInterpolation(0.7f, U1, U2, U3, U4); // 0.7f:current change rate; 49 EXPECT_NEAR(0.287, ret, PRECISION); // 0.287:current change rate; 50 ret = Interpolation::GetBezierInterpolation(0.9f, U1, U2, U3, U4); // 0.9f:current change rate; 51 EXPECT_NEAR(0.402, ret, PRECISION); // 0.402:current change rate; 52 } 53 54 /** 55 * @tc.name: GetBezierY_001 56 * @tc.desc: Verify GetBezierY function, equal. 57 * @tc.type: FUNC 58 * @tc.require: AR000DSMQM 59 */ 60 HWTEST_F(InterpolationTest, GetBezierY_001, TestSize.Level0) 61 { 62 float ret = Interpolation::GetBezierY(0.2f, U1, U2, U3, U4); // 0.2f:current change rate; 63 EXPECT_NEAR(0.152, ret, PRECISION); // 0.152:current change rate; 64 ret = Interpolation::GetBezierY(0.5f, U1, U2, U3, U4); // 0.5f:current change rate; 65 EXPECT_NEAR(0.635, ret, PRECISION); // 0.635:current change rate; 66 ret = Interpolation::GetBezierY(0.7f, U1, U2, U3, U4); // 0.7f:current change rate; 67 EXPECT_NEAR(0.811, ret, PRECISION); // 0.811:current change rate; 68 ret = Interpolation::GetBezierY(0.9f, U1, U2, U3, U4); // 0.9f:current change rate; 69 EXPECT_NEAR(0.949, ret, PRECISION); // 0.949:current change rate; 70 } 71 } // namespace OHOS 72