• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }
32 
33 class LeastSquareImplTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase()41 void LeastSquareImplTest::SetUpTestCase()
42 {
43     GTEST_LOG_(INFO) << "LeastSquareImplTest SetUpTestCase";
44 }
45 
TearDownTestCase()46 void LeastSquareImplTest::TearDownTestCase()
47 {
48     GTEST_LOG_(INFO) << "LeastSquareImplTest TearDownTestCase";
49 }
50 
SetUp()51 void LeastSquareImplTest::SetUp()
52 {
53     GTEST_LOG_(INFO) << "LeastSquareImplTest SetUp";
54 }
55 
TearDown()56 void LeastSquareImplTest::TearDown()
57 {
58     GTEST_LOG_(INFO) << "LeastSquareImplTest TearDown";
59 }
60 
61 /**
62  * @tc.name: LeastSquareImplTest001
63  * @tc.desc: Test all functions of the class LeastSquareImpl.
64  * @tc.type: FUNC
65  */
66 HWTEST_F(LeastSquareImplTest, LeastSquareImplTest001, TestSize.Level1)
67 {
68     LeastSquareImpl leastSquareImpl1(PARAMS_NUM1);
69     std::vector<double> params;
70     EXPECT_FALSE(leastSquareImpl1.GetLeastSquareParams(params));
71     EXPECT_TRUE(params.empty());
72 
73     params.clear();
74     LeastSquareImpl leastSquareImpl2(PARAMS_NUM2);
75     leastSquareImpl2.UpdatePoint(NUM_D1, NUM_D2);
76     leastSquareImpl2.UpdatePoint(NUM_D1, NUM_D2);
77     EXPECT_FALSE(leastSquareImpl2.GetLeastSquareParams(params));
78 
79     params.clear();
80     LeastSquareImpl leastSquareImpl3(PARAMS_NUM3);
81     leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2);
82     leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2);
83     leastSquareImpl3.UpdatePoint(NUM_D1, NUM_D2);
84     EXPECT_FALSE(leastSquareImpl3.GetLeastSquareParams(params));
85 
86     params.clear();
87     LeastSquareImpl leastSquareImpl4(PARAMS_NUM4);
88     leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2);
89     leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2);
90     leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2);
91     leastSquareImpl4.UpdatePoint(NUM_D1, NUM_D2);
92     EXPECT_TRUE(leastSquareImpl4.GetLeastSquareParams(params));
93     // In the second call, the function is not calculated and returns directly.
94     EXPECT_TRUE(leastSquareImpl4.GetLeastSquareParams(params));
95 }
96 } // namespace OHOS::Ace