123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include <cmath> 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include "gtest/gtest.h" 1923b3eb3cSopenharmony_ci 2023b3eb3cSopenharmony_ci#include "base/geometry/matrix3.h" 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ciusing namespace testing; 2323b3eb3cSopenharmony_ciusing namespace testing::ext; 2423b3eb3cSopenharmony_ci 2523b3eb3cSopenharmony_cinamespace OHOS::Ace { 2623b3eb3cSopenharmony_cinamespace { 2723b3eb3cSopenharmony_ciconstexpr double DEFAULT_DOUBLE0 = 0.0; 2823b3eb3cSopenharmony_ciconstexpr double DEFAULT_DOUBLE1 = 1.0; 2923b3eb3cSopenharmony_ciconstexpr double DEFAULT_DOUBLE2 = 2.0; 3023b3eb3cSopenharmony_ciconstexpr double DEFAULT_DOUBLE3 = 3.0; 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ciconstexpr int32_t VALID_ROW0 = 0; 3323b3eb3cSopenharmony_ciconstexpr int32_t VALID_COL0 = 0; 3423b3eb3cSopenharmony_ciconstexpr int32_t VALID_ROW1 = 1; 3523b3eb3cSopenharmony_ciconstexpr int32_t VALID_COL1 = 1; 3623b3eb3cSopenharmony_ciconstexpr int32_t VALID_ROW2 = 2; 3723b3eb3cSopenharmony_ciconstexpr int32_t VALID_COL2 = 2; 3823b3eb3cSopenharmony_ciconstexpr uint32_t VALID_DIMENSION = 3; 3923b3eb3cSopenharmony_ci 4023b3eb3cSopenharmony_ciconstexpr int32_t INVALID_ROW_NEG = -1; 4123b3eb3cSopenharmony_ciconstexpr int32_t INVALID_COL_NEG = -1; 4223b3eb3cSopenharmony_ciconstexpr int32_t INVALID_ROW_POS = 5; 4323b3eb3cSopenharmony_ciconstexpr int32_t INVALID_COL_POS = 5; 4423b3eb3cSopenharmony_ci 4523b3eb3cSopenharmony_ciconstexpr uint32_t ROW_NUM = 4; 4623b3eb3cSopenharmony_ciconstexpr uint32_t COLUMN_NUM = 4; 4723b3eb3cSopenharmony_ci} // namespace 4823b3eb3cSopenharmony_ci 4923b3eb3cSopenharmony_ciclass Matrix3Test : public testing::Test {}; 5023b3eb3cSopenharmony_ci 5123b3eb3cSopenharmony_ci/** 5223b3eb3cSopenharmony_ci * @tc.name: Matrix3Test001 5323b3eb3cSopenharmony_ci * @tc.desc: Test the function SetEntry of the classes Matrix3, Matrix3N and MatrixN3. 5423b3eb3cSopenharmony_ci * @tc.type: FUNC 5523b3eb3cSopenharmony_ci */ 5623b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test001, TestSize.Level1) 5723b3eb3cSopenharmony_ci{ 5823b3eb3cSopenharmony_ci /** 5923b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 6023b3eb3cSopenharmony_ci */ 6123b3eb3cSopenharmony_ci Matrix3 matrixObj1; 6223b3eb3cSopenharmony_ci std::string initStrObj1 = matrixObj1.ToString(); 6323b3eb3cSopenharmony_ci Matrix3N matrix3NObj1(COLUMN_NUM); 6423b3eb3cSopenharmony_ci std::string initStr3NObj1 = matrix3NObj1.ToString(); 6523b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj1(ROW_NUM); 6623b3eb3cSopenharmony_ci std::string initStrN3Obj1 = matrixN3Obj1.ToString(); 6723b3eb3cSopenharmony_ci 6823b3eb3cSopenharmony_ci /** 6923b3eb3cSopenharmony_ci * @tc.steps2: Call the function SetEntry of the classes Matrix3. 7023b3eb3cSopenharmony_ci * @tc.expected: Set the value of a legal location, the value of the corresponding location changes normally. 7123b3eb3cSopenharmony_ci * Set the value of an illegal location, there is no change. 7223b3eb3cSopenharmony_ci */ 7323b3eb3cSopenharmony_ci matrixObj1.SetEntry(INVALID_ROW_NEG, INVALID_COL_NEG, DEFAULT_DOUBLE1); 7423b3eb3cSopenharmony_ci EXPECT_EQ(matrixObj1.ToString(), initStrObj1); 7523b3eb3cSopenharmony_ci matrixObj1.SetEntry(INVALID_ROW_POS, INVALID_COL_POS, DEFAULT_DOUBLE1); 7623b3eb3cSopenharmony_ci EXPECT_EQ(matrixObj1.ToString(), initStrObj1); 7723b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 7823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixObj1[VALID_ROW0][VALID_COL0], DEFAULT_DOUBLE1); 7923b3eb3cSopenharmony_ci 8023b3eb3cSopenharmony_ci /** 8123b3eb3cSopenharmony_ci * @tc.steps3: Call the function SetEntry of the classes Matrix3N. 8223b3eb3cSopenharmony_ci * @tc.expected: Set the value of a legal location, the value of the corresponding location changes normally. 8323b3eb3cSopenharmony_ci * Set the value of an illegal location, there is no change. 8423b3eb3cSopenharmony_ci */ 8523b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(INVALID_ROW_POS, INVALID_COL_POS, DEFAULT_DOUBLE1); 8623b3eb3cSopenharmony_ci EXPECT_EQ(matrix3NObj1.ToString(), initStr3NObj1); 8723b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 8823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrix3NObj1[VALID_ROW0][VALID_COL0], DEFAULT_DOUBLE1); 8923b3eb3cSopenharmony_ci 9023b3eb3cSopenharmony_ci /** 9123b3eb3cSopenharmony_ci * @tc.steps4: Call the function SetEntry of the classes MatrixN3. 9223b3eb3cSopenharmony_ci * @tc.expected: Set the value of a legal location, the value of the corresponding location changes normally. 9323b3eb3cSopenharmony_ci * Set the value of an illegal location, there is no change. 9423b3eb3cSopenharmony_ci */ 9523b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(INVALID_ROW_POS, INVALID_COL_POS, DEFAULT_DOUBLE1); 9623b3eb3cSopenharmony_ci EXPECT_EQ(matrixN3Obj1.ToString(), initStrN3Obj1); 9723b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 9823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixN3Obj1[VALID_ROW0][VALID_COL0], DEFAULT_DOUBLE1); 9923b3eb3cSopenharmony_ci} 10023b3eb3cSopenharmony_ci 10123b3eb3cSopenharmony_ci/** 10223b3eb3cSopenharmony_ci * @tc.name: Matrix3Test002 10323b3eb3cSopenharmony_ci * @tc.desc: Test the function Transpose of the classes Matrix3, Matrix3N and MatrixN3. 10423b3eb3cSopenharmony_ci * @tc.type: FUNC 10523b3eb3cSopenharmony_ci */ 10623b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test002, TestSize.Level1) 10723b3eb3cSopenharmony_ci{ 10823b3eb3cSopenharmony_ci /** 10923b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 11023b3eb3cSopenharmony_ci */ 11123b3eb3cSopenharmony_ci Matrix3 matrixObj1; 11223b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW0, VALID_COL2, DEFAULT_DOUBLE1); 11323b3eb3cSopenharmony_ci Matrix3N matrix3NObj1(COLUMN_NUM); 11423b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW0, VALID_COL2, DEFAULT_DOUBLE1); 11523b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj1(ROW_NUM); 11623b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW0, VALID_COL2, DEFAULT_DOUBLE1); 11723b3eb3cSopenharmony_ci 11823b3eb3cSopenharmony_ci /** 11923b3eb3cSopenharmony_ci * @tc.steps2: Call the function Transpose of the classes Matrix3. 12023b3eb3cSopenharmony_ci * @tc.expected: The value of corresponding locations of two matrixes is equal. 12123b3eb3cSopenharmony_ci */ 12223b3eb3cSopenharmony_ci Matrix3 matrixObj2 = matrixObj1.Transpose(); 12323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixObj2[VALID_ROW2][VALID_COL0], DEFAULT_DOUBLE1); 12423b3eb3cSopenharmony_ci 12523b3eb3cSopenharmony_ci /** 12623b3eb3cSopenharmony_ci * @tc.steps3: Call the function Transpose of the classes Matrix3N. 12723b3eb3cSopenharmony_ci * @tc.expected: The value of corresponding locations of two matrixes is equal. 12823b3eb3cSopenharmony_ci */ 12923b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj2 = matrix3NObj1.Transpose(); 13023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixN3Obj2[VALID_ROW2][VALID_COL0], DEFAULT_DOUBLE1); 13123b3eb3cSopenharmony_ci 13223b3eb3cSopenharmony_ci /** 13323b3eb3cSopenharmony_ci * @tc.steps4: Call the function Transpose of the classes MatrixN3. 13423b3eb3cSopenharmony_ci * @tc.expected: The value of corresponding locations of two matrixes is equal. 13523b3eb3cSopenharmony_ci */ 13623b3eb3cSopenharmony_ci Matrix3N matrix3NObj2 = matrixN3Obj1.Transpose(); 13723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrix3NObj2[VALID_ROW2][VALID_COL0], DEFAULT_DOUBLE1); 13823b3eb3cSopenharmony_ci} 13923b3eb3cSopenharmony_ci 14023b3eb3cSopenharmony_ci/** 14123b3eb3cSopenharmony_ci * @tc.name: Matrix3Test003 14223b3eb3cSopenharmony_ci * @tc.desc: Test the function inverse of the class Matrix3. 14323b3eb3cSopenharmony_ci * @tc.type: FUNC 14423b3eb3cSopenharmony_ci */ 14523b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test003, TestSize.Level1) 14623b3eb3cSopenharmony_ci{ 14723b3eb3cSopenharmony_ci /** 14823b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 14923b3eb3cSopenharmony_ci */ 15023b3eb3cSopenharmony_ci Matrix3 matrixObj1; 15123b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 15223b3eb3cSopenharmony_ci Matrix3 matrixObj2; 15323b3eb3cSopenharmony_ci std::string initStrObj2 = matrixObj2.ToString(); 15423b3eb3cSopenharmony_ci 15523b3eb3cSopenharmony_ci /** 15623b3eb3cSopenharmony_ci * @tc.steps2: Call the function inverse of the matrix with determinant 0. 15723b3eb3cSopenharmony_ci * @tc.expected: The function inverse does not work, and the matrix matrixObj2 is not changed. 15823b3eb3cSopenharmony_ci */ 15923b3eb3cSopenharmony_ci EXPECT_FALSE(matrixObj1.Invert(matrixObj2)); 16023b3eb3cSopenharmony_ci EXPECT_EQ(matrixObj2.ToString(), initStrObj2); 16123b3eb3cSopenharmony_ci 16223b3eb3cSopenharmony_ci /** 16323b3eb3cSopenharmony_ci * @tc.steps3: Set the matrix matrixObj1 to identity matrix. 16423b3eb3cSopenharmony_ci */ 16523b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE1); 16623b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE1); 16723b3eb3cSopenharmony_ci 16823b3eb3cSopenharmony_ci /** 16923b3eb3cSopenharmony_ci * @tc.steps4: Call the function inverse of the identity matrix. 17023b3eb3cSopenharmony_ci * @tc.expected: The inverse matrix of matrixObj2 is the identity matrix, and is set to the matrix matrixObj2. 17123b3eb3cSopenharmony_ci */ 17223b3eb3cSopenharmony_ci EXPECT_TRUE(matrixObj1.Invert(matrixObj2)); 17323b3eb3cSopenharmony_ci EXPECT_NE(matrixObj2.ToString(), initStrObj2); 17423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixObj2[VALID_ROW0][VALID_COL0], DEFAULT_DOUBLE1); 17523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixObj2[VALID_ROW1][VALID_COL1], DEFAULT_DOUBLE1); 17623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(matrixObj2[VALID_ROW2][VALID_COL2], DEFAULT_DOUBLE1); 17723b3eb3cSopenharmony_ci} 17823b3eb3cSopenharmony_ci 17923b3eb3cSopenharmony_ci/** 18023b3eb3cSopenharmony_ci * @tc.name: Matrix3Test004 18123b3eb3cSopenharmony_ci * @tc.desc: Test the function operator* of classes Matrix3 and Matrix3N. 18223b3eb3cSopenharmony_ci * @tc.type: FUNC 18323b3eb3cSopenharmony_ci */ 18423b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test004, TestSize.Level1) 18523b3eb3cSopenharmony_ci{ 18623b3eb3cSopenharmony_ci /** 18723b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 18823b3eb3cSopenharmony_ci */ 18923b3eb3cSopenharmony_ci Matrix3 matrixObj1; 19023b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 19123b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE1); 19223b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE1); 19323b3eb3cSopenharmony_ci Matrix3N matrix3NObj1(COLUMN_NUM); 19423b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 19523b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE2); 19623b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE3); 19723b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj1(ROW_NUM); 19823b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 19923b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW1, VALID_COL1, 1.0 / DEFAULT_DOUBLE2); 20023b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW2, VALID_COL2, 1.0 / DEFAULT_DOUBLE3); 20123b3eb3cSopenharmony_ci 20223b3eb3cSopenharmony_ci /** 20323b3eb3cSopenharmony_ci * @tc.steps2: Call the function operator* of classes Matrix3 with the identity matrix matrixObj1. 20423b3eb3cSopenharmony_ci * @tc.expected: The product of matrixes matrixObj1 and matrix3NObj1 is equal to matrix3NObj2. 20523b3eb3cSopenharmony_ci */ 20623b3eb3cSopenharmony_ci Matrix3N matrix3NObj2 = matrixObj1 * matrix3NObj1; 20723b3eb3cSopenharmony_ci EXPECT_EQ(matrix3NObj1.ToString(), matrix3NObj2.ToString()); 20823b3eb3cSopenharmony_ci 20923b3eb3cSopenharmony_ci /** 21023b3eb3cSopenharmony_ci * @tc.steps3: Call the function operator* of classes Matrix3N. 21123b3eb3cSopenharmony_ci * @tc.expected: The product of matrixes matrix3NObj1 and matrixN3Obj1 is equal to matrixObj1. 21223b3eb3cSopenharmony_ci */ 21323b3eb3cSopenharmony_ci Matrix3 matrixObj2 = matrix3NObj1 * matrixN3Obj1; 21423b3eb3cSopenharmony_ci EXPECT_EQ(matrixObj2.ToString(), matrixObj1.ToString()); 21523b3eb3cSopenharmony_ci} 21623b3eb3cSopenharmony_ci 21723b3eb3cSopenharmony_ci/** 21823b3eb3cSopenharmony_ci * @tc.name: Matrix3Test005 21923b3eb3cSopenharmony_ci * @tc.desc: Test the function MapScalars of the class Matrix3. 22023b3eb3cSopenharmony_ci * @tc.type: FUNC 22123b3eb3cSopenharmony_ci */ 22223b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test005, TestSize.Level1) 22323b3eb3cSopenharmony_ci{ 22423b3eb3cSopenharmony_ci /** 22523b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 22623b3eb3cSopenharmony_ci */ 22723b3eb3cSopenharmony_ci Matrix3 matrixObj1; 22823b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 22923b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE2); 23023b3eb3cSopenharmony_ci matrixObj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE3); 23123b3eb3cSopenharmony_ci 23223b3eb3cSopenharmony_ci /** 23323b3eb3cSopenharmony_ci * @tc.steps2: Given the vector srcVec whose size is invalid, test the 23423b3eb3cSopenharmony_ci * function MapScalars with single parameter. 23523b3eb3cSopenharmony_ci * @tc.expected: The function MapScalars does not work and all values of the return vector are equal to zero. 23623b3eb3cSopenharmony_ci */ 23723b3eb3cSopenharmony_ci std::vector<double> srcVec = { DEFAULT_DOUBLE1, DEFAULT_DOUBLE1 }; 23823b3eb3cSopenharmony_ci std::vector<double> dstVec = matrixObj1.MapScalars(srcVec); 23923b3eb3cSopenharmony_ci EXPECT_EQ(dstVec.size(), VALID_DIMENSION); 24023b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE0); 24123b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE0); 24223b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE0); 24323b3eb3cSopenharmony_ci 24423b3eb3cSopenharmony_ci /** 24523b3eb3cSopenharmony_ci * @tc.steps3: Given the vector srcVec whose size is valid, test the 24623b3eb3cSopenharmony_ci * function MapScalars with single parameter. 24723b3eb3cSopenharmony_ci * @tc.expected: The values of return vector is equal to values on the diagonal of matrixObj1. 24823b3eb3cSopenharmony_ci */ 24923b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 25023b3eb3cSopenharmony_ci dstVec = matrixObj1.MapScalars(srcVec); 25123b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE1); 25223b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE2); 25323b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE3); 25423b3eb3cSopenharmony_ci 25523b3eb3cSopenharmony_ci /** 25623b3eb3cSopenharmony_ci * @tc.steps4: Given the vector srcVec whose size is invalid, test the 25723b3eb3cSopenharmony_ci * function MapScalars with two parameters. 25823b3eb3cSopenharmony_ci * @tc.expected: The function MapScalars does not work and the return vector is empty. 25923b3eb3cSopenharmony_ci */ 26023b3eb3cSopenharmony_ci srcVec.clear(); 26123b3eb3cSopenharmony_ci dstVec.clear(); 26223b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 26323b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 26423b3eb3cSopenharmony_ci EXPECT_FALSE(matrixObj1.MapScalars(srcVec, dstVec)); 26523b3eb3cSopenharmony_ci EXPECT_TRUE(dstVec.empty()); 26623b3eb3cSopenharmony_ci 26723b3eb3cSopenharmony_ci /** 26823b3eb3cSopenharmony_ci * @tc.steps5: Given the vector srcVec whose size is valid, test the 26923b3eb3cSopenharmony_ci * function MapScalars with two parameters. 27023b3eb3cSopenharmony_ci * @tc.expected: The values of return vector is equal to values on the diagonal of matrixObj1. 27123b3eb3cSopenharmony_ci */ 27223b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 27323b3eb3cSopenharmony_ci EXPECT_TRUE(matrixObj1.MapScalars(srcVec, dstVec)); 27423b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE1); 27523b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE2); 27623b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE3); 27723b3eb3cSopenharmony_ci} 27823b3eb3cSopenharmony_ci 27923b3eb3cSopenharmony_ci/** 28023b3eb3cSopenharmony_ci * @tc.name: Matrix3Test006 28123b3eb3cSopenharmony_ci * @tc.desc: Test the function MapScalars of the class Matrix3N. 28223b3eb3cSopenharmony_ci * @tc.type: FUNC 28323b3eb3cSopenharmony_ci */ 28423b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test006, TestSize.Level1) 28523b3eb3cSopenharmony_ci{ 28623b3eb3cSopenharmony_ci /** 28723b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 28823b3eb3cSopenharmony_ci */ 28923b3eb3cSopenharmony_ci Matrix3N matrix3NObj1(COLUMN_NUM); 29023b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 29123b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE2); 29223b3eb3cSopenharmony_ci matrix3NObj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE3); 29323b3eb3cSopenharmony_ci 29423b3eb3cSopenharmony_ci /** 29523b3eb3cSopenharmony_ci * @tc.steps2: Given the vector srcVec whose size is invalid, test the 29623b3eb3cSopenharmony_ci * function MapScalars with single parameter. 29723b3eb3cSopenharmony_ci * @tc.expected: The function MapScalars does not work and all values of the return vector are equal to zero. 29823b3eb3cSopenharmony_ci */ 29923b3eb3cSopenharmony_ci std::vector<double> srcVec = { DEFAULT_DOUBLE1, DEFAULT_DOUBLE1 }; 30023b3eb3cSopenharmony_ci std::vector<double> dstVec = matrix3NObj1.MapScalars(srcVec); 30123b3eb3cSopenharmony_ci EXPECT_EQ(dstVec.size(), VALID_DIMENSION); 30223b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE0); 30323b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE0); 30423b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE0); 30523b3eb3cSopenharmony_ci 30623b3eb3cSopenharmony_ci /** 30723b3eb3cSopenharmony_ci * @tc.steps3: Given the vector srcVec whose size is valid, test the 30823b3eb3cSopenharmony_ci * function MapScalars with single parameter. 30923b3eb3cSopenharmony_ci * @tc.expected: The values of return vector is equal to values on the diagonal of matrix3NObj1. 31023b3eb3cSopenharmony_ci */ 31123b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 31223b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 31323b3eb3cSopenharmony_ci dstVec = matrix3NObj1.MapScalars(srcVec); 31423b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE1); 31523b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE2); 31623b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE3); 31723b3eb3cSopenharmony_ci 31823b3eb3cSopenharmony_ci /** 31923b3eb3cSopenharmony_ci * @tc.steps4: Given the vector srcVec whose size is invalid, test the 32023b3eb3cSopenharmony_ci * function MapScalars with two parameters. 32123b3eb3cSopenharmony_ci * @tc.expected: The function MapScalars does not work and the return vector is empty. 32223b3eb3cSopenharmony_ci */ 32323b3eb3cSopenharmony_ci srcVec.clear(); 32423b3eb3cSopenharmony_ci dstVec.clear(); 32523b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 32623b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 32723b3eb3cSopenharmony_ci EXPECT_FALSE(matrix3NObj1.MapScalars(srcVec, dstVec)); 32823b3eb3cSopenharmony_ci EXPECT_TRUE(dstVec.empty()); 32923b3eb3cSopenharmony_ci 33023b3eb3cSopenharmony_ci /** 33123b3eb3cSopenharmony_ci * @tc.steps: Given the vector srcVec whose size is valid, test the 33223b3eb3cSopenharmony_ci * function MapScalars with two parameters. 33323b3eb3cSopenharmony_ci * @tc.expected: The values of return vector is equal to values on the diagonal of matrix3NObj1. 33423b3eb3cSopenharmony_ci */ 33523b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 33623b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 33723b3eb3cSopenharmony_ci EXPECT_TRUE(matrix3NObj1.MapScalars(srcVec, dstVec)); 33823b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE1); 33923b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE2); 34023b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE3); 34123b3eb3cSopenharmony_ci} 34223b3eb3cSopenharmony_ci 34323b3eb3cSopenharmony_ci/** 34423b3eb3cSopenharmony_ci * @tc.name: Matrix3Test007 34523b3eb3cSopenharmony_ci * @tc.desc: Test the function MapScalars of the class MatrixN3. 34623b3eb3cSopenharmony_ci * @tc.type: FUNC 34723b3eb3cSopenharmony_ci */ 34823b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test007, TestSize.Level1) 34923b3eb3cSopenharmony_ci{ 35023b3eb3cSopenharmony_ci /** 35123b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters. 35223b3eb3cSopenharmony_ci */ 35323b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj1(ROW_NUM); 35423b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW0, VALID_COL0, DEFAULT_DOUBLE1); 35523b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW1, VALID_COL1, DEFAULT_DOUBLE2); 35623b3eb3cSopenharmony_ci matrixN3Obj1.SetEntry(VALID_ROW2, VALID_COL2, DEFAULT_DOUBLE3); 35723b3eb3cSopenharmony_ci 35823b3eb3cSopenharmony_ci /** 35923b3eb3cSopenharmony_ci * @tc.steps2: Given the vector srcVec whose size is invalid, test the function MapScalars. 36023b3eb3cSopenharmony_ci * @tc.expected: The function MapScalars does not work and all values of the return vector are equal to zero. 36123b3eb3cSopenharmony_ci */ 36223b3eb3cSopenharmony_ci std::vector<double> srcVec = { DEFAULT_DOUBLE1, DEFAULT_DOUBLE1 }; 36323b3eb3cSopenharmony_ci std::vector<double> dstVec = matrixN3Obj1.MapScalars(srcVec); 36423b3eb3cSopenharmony_ci EXPECT_EQ(dstVec.size(), ROW_NUM); 36523b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE0); 36623b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE0); 36723b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE0); 36823b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[3], DEFAULT_DOUBLE0); 36923b3eb3cSopenharmony_ci 37023b3eb3cSopenharmony_ci /** 37123b3eb3cSopenharmony_ci * @tc.steps3: Given the vector srcVec whose size is valid, test the function MapScalars. 37223b3eb3cSopenharmony_ci * @tc.expected: The values of return vector is equal to values on the diagonal of matrixN3Obj1. 37323b3eb3cSopenharmony_ci */ 37423b3eb3cSopenharmony_ci srcVec.push_back(DEFAULT_DOUBLE1); 37523b3eb3cSopenharmony_ci dstVec = matrixN3Obj1.MapScalars(srcVec); 37623b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[0], DEFAULT_DOUBLE1); 37723b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[1], DEFAULT_DOUBLE2); 37823b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[2], DEFAULT_DOUBLE3); 37923b3eb3cSopenharmony_ci EXPECT_EQ(dstVec[3], DEFAULT_DOUBLE0); 38023b3eb3cSopenharmony_ci} 38123b3eb3cSopenharmony_ci 38223b3eb3cSopenharmony_ci/** 38323b3eb3cSopenharmony_ci * @tc.name: Matrix3Test008 38423b3eb3cSopenharmony_ci * @tc.desc: Test the function SetEntry for Matrix3/Matrix3N 38523b3eb3cSopenharmony_ci * @tc.type: FUNC 38623b3eb3cSopenharmony_ci */ 38723b3eb3cSopenharmony_ciHWTEST_F(Matrix3Test, Matrix3Test008, TestSize.Level1) 38823b3eb3cSopenharmony_ci{ 38923b3eb3cSopenharmony_ci /** 39023b3eb3cSopenharmony_ci * @tc.steps1: initialize parameters.Matrix3::SetEntry: index out of range 39123b3eb3cSopenharmony_ci */ 39223b3eb3cSopenharmony_ci Matrix3 matrixObj1; 39323b3eb3cSopenharmony_ci // true false false false 39423b3eb3cSopenharmony_ci matrixObj1.SetEntry(-1, 2, 5.0f); 39523b3eb3cSopenharmony_ci // false true false false 39623b3eb3cSopenharmony_ci matrixObj1.SetEntry(10, 2, 5.0f); 39723b3eb3cSopenharmony_ci // false false true false 39823b3eb3cSopenharmony_ci matrixObj1.SetEntry(0, -1, 5.0f); 39923b3eb3cSopenharmony_ci // false false false true 40023b3eb3cSopenharmony_ci matrixObj1.SetEntry(0, 10, 5.0f); 40123b3eb3cSopenharmony_ci // false false false false 40223b3eb3cSopenharmony_ci matrixObj1.SetEntry(0, 2, 5.0f); 40323b3eb3cSopenharmony_ci EXPECT_EQ(matrixObj1(0, 2) == 5.0f, true); 40423b3eb3cSopenharmony_ci 40523b3eb3cSopenharmony_ci /** 40623b3eb3cSopenharmony_ci * @tc.steps2: Matrix3N::SetEntry: index out of range 40723b3eb3cSopenharmony_ci */ 40823b3eb3cSopenharmony_ci Matrix3N matrix3NObj1(3); 40923b3eb3cSopenharmony_ci // true false 41023b3eb3cSopenharmony_ci bool ret = matrix3NObj1.SetEntry(10, 2, 5.0f); 41123b3eb3cSopenharmony_ci EXPECT_FALSE(ret); 41223b3eb3cSopenharmony_ci // false true 41323b3eb3cSopenharmony_ci bool ret2 = matrix3NObj1.SetEntry(0, 3, 5.0f); 41423b3eb3cSopenharmony_ci EXPECT_FALSE(ret2); 41523b3eb3cSopenharmony_ci // false false 41623b3eb3cSopenharmony_ci bool ret3 = matrix3NObj1.SetEntry(0, 2, 5.0f); 41723b3eb3cSopenharmony_ci EXPECT_TRUE(ret3); 41823b3eb3cSopenharmony_ci 41923b3eb3cSopenharmony_ci /** 42023b3eb3cSopenharmony_ci * @tc.steps3: MatrixN3::SetEntry: index out of range 42123b3eb3cSopenharmony_ci */ 42223b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj1(3); 42323b3eb3cSopenharmony_ci // true false 42423b3eb3cSopenharmony_ci bool ret4 = matrixN3Obj1.SetEntry(3, 2, 5.0f); 42523b3eb3cSopenharmony_ci EXPECT_FALSE(ret4); 42623b3eb3cSopenharmony_ci // false true 42723b3eb3cSopenharmony_ci bool ret5 = matrixN3Obj1.SetEntry(0, 10, 5.0f); 42823b3eb3cSopenharmony_ci EXPECT_FALSE(ret5); 42923b3eb3cSopenharmony_ci // false false 43023b3eb3cSopenharmony_ci bool ret6 = matrixN3Obj1.SetEntry(0, 2, 5.0f); 43123b3eb3cSopenharmony_ci EXPECT_TRUE(ret6); 43223b3eb3cSopenharmony_ci 43323b3eb3cSopenharmony_ci // Matrix3N::operator*: matrix size not match 43423b3eb3cSopenharmony_ci MatrixN3 matrixN3Obj2(2); 43523b3eb3cSopenharmony_ci Matrix3 ret7 = matrix3NObj1 * matrixN3Obj2; 43623b3eb3cSopenharmony_ci EXPECT_EQ(ret7(0, 0) == 0.0f, true); 43723b3eb3cSopenharmony_ci} 43823b3eb3cSopenharmony_ci} // namespace OHOS::Ace 439