1 /* 2 * Copyright (c) 2022 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 "gtest/gtest.h" 17 18 #include "base/geometry/least_square_impl.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS::Ace { 24 namespace { 25 const double NUM_D1 = 1.0; 26 const double NUM_D2 = 0.2; 27 const int32_t PARAMS_NUM1 = 1; 28 const int32_t PARAMS_NUM2 = 2; 29 const int32_t PARAMS_NUM3 = 3; 30 const int32_t PARAMS_NUM4 = 4; 31 } // namespace 32 33 class LeastSquareImplTest : public testing::Test {}; 34 35 /** 36 * @tc.name: LeastSquareImplTest001 37 * @tc.desc: Test all functions of the class LeastSquareImpl. 38 * @tc.type: FUNC 39 */ 40 HWTEST_F(LeastSquareImplTest, LeastSquareImplTest001, TestSize.Level1) 41 { 42 LeastSquareImpl leastSquareImpl1(PARAMS_NUM1); 43 std::vector<double> params; 44 EXPECT_FALSE(leastSquareImpl1.GetLeastSquareParams(params)); 45 EXPECT_TRUE(params.empty()); 46 47 params.clear(); 48 LeastSquareImpl leastSquareImpl2(PARAMS_NUM2); 49 leastSquareImpl2.UpdatePoint(NUM_D1, NUM_D2); 50 leastSquareImpl2.UpdatePoint(NUM_D1, NUM_D2); 51 EXPECT_FALSE(leastSquareImpl2.GetLeastSquareParams(params)); 52 53 params.clear(); 54 LeastSquareImpl leastSquareImpl3(PARAMS_NUM3); 55 leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2); 56 leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2); 57 leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2); 58 EXPECT_FALSE(leastSquareImpl3.GetLeastSquareParams(params)); 59 60 params.clear(); 61 LeastSquareImpl leastSquareImpl4(PARAMS_NUM4); 62 leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2); 63 leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2); 64 leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2); 65 leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2); 66 EXPECT_TRUE(leastSquareImpl4.GetLeastSquareParams(params)); 67 // In the second call, the function is not calculated and returns directly. 68 EXPECT_TRUE(leastSquareImpl4.GetLeastSquareParams(params)); 69 } 70 } // namespace OHOS::Ace 71