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 "gfx_utils/graphic_math.h" 17 18 #include <climits> 19 #include <gtest/gtest.h> 20 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace { 25 const Point POINT1 = { 5, 4 }; 26 const Point POINT2 = { 3, 2 }; 27 const uint16_t MAX_NUM_8BIT = 256; 28 } 29 class MathTest : public testing::Test { 30 public: SetUpTestCase(void)31 static void SetUpTestCase(void) {} TearDownTestCase(void)32 static void TearDownTestCase(void) {} 33 }; 34 35 /** 36 * @tc.name: MathSin_001 37 * @tc.desc: Verify Sin function, equal. 38 * @tc.type: FUNC 39 * @tc.require: AR000EEMQ9 40 */ 41 HWTEST_F(MathTest, MathSin_001, TestSize.Level0) 42 { 43 EXPECT_EQ(Sin(0), 0); 44 EXPECT_EQ(Sin(QUARTER_IN_DEGREE), 1); 45 EXPECT_EQ(Sin(THREE_QUARTER_IN_DEGREE), -1); 46 } 47 48 /** 49 * @tc.name: MathFastAtan2_001 50 * @tc.desc: Verify FastAtan2 function, equal. 51 * @tc.type: FUNC 52 * @tc.require: AR000EEMQ9 53 */ 54 HWTEST_F(MathTest, MathFastAtan2_001, TestSize.Level0) 55 { 56 EXPECT_EQ(FastAtan2(0, 1), 0); 57 EXPECT_EQ(FastAtan2(1, 0), QUARTER_IN_DEGREE); 58 EXPECT_EQ(FastAtan2(0, -1), SEMICIRCLE_IN_DEGREE); 59 EXPECT_EQ(FastAtan2(-1, 0), THREE_QUARTER_IN_DEGREE); 60 } 61 62 63 /** 64 * @tc.name: MathFloatToInt64_001 65 * @tc.desc: Verify FloatToInt64 function, equal. 66 * @tc.type: FUNC 67 * @tc.require: AR000EEMQ9 68 */ 69 HWTEST_F(MathTest, MathFloatToInt64_001, TestSize.Level0) 70 { 71 EXPECT_EQ(FloatToInt64(1), MAX_NUM_8BIT); 72 } 73 74 /** 75 * @tc.name: MathSqrt_001 76 * @tc.desc: Verify Sqrt function, equal. 77 * @tc.type: FUNC 78 * @tc.require: AR000EEMQ9 79 */ 80 HWTEST_F(MathTest, MathSqrt_001, TestSize.Level0) 81 { 82 const float testInteger = 2.0; 83 const float testIntegerSquared = testInteger * testInteger; 84 const float testFloat = 2.121320; // 2.121320: 4.5 squaring results 85 const float testFloatSquared = 4.5; 86 87 EXPECT_EQ(Sqrt(0), 0); 88 float ret = Sqrt(testIntegerSquared); 89 EXPECT_TRUE(MATH_FLT_EQUAL(ret, testInteger)); 90 91 ret = Sqrt(testFloatSquared); 92 EXPECT_TRUE(MATH_FLT_EQUAL(ret, testFloat)); 93 } 94 95 /** 96 * @tc.name: Vector2Dot_001 97 * @tc.desc: Verify Dot function, equal. 98 * @tc.type: FUNC 99 * @tc.require: AR000EEMQ9 100 */ 101 HWTEST_F(MathTest, Vector2Dot_001, TestSize.Level0) 102 { 103 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 104 if (vector1 == nullptr) { 105 EXPECT_EQ(1, 0); 106 return; 107 } 108 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 109 if (vector2 == nullptr) { 110 delete vector1; 111 EXPECT_EQ(1, 0); 112 return; 113 } 114 uint16_t value = POINT1.x * POINT2.x + POINT1.y * POINT2.y; 115 116 EXPECT_EQ(vector1->Dot(*vector2), value); 117 118 delete vector1; 119 delete vector2; 120 } 121 122 /** 123 * @tc.name: Vector2Cross_001 124 * @tc.desc: Verify Cross function, equal. 125 * @tc.type: FUNC 126 * @tc.require: AR000EEMQ9 127 */ 128 HWTEST_F(MathTest, Vector2Cross_001, TestSize.Level0) 129 { 130 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 131 if (vector1 == nullptr) { 132 EXPECT_EQ(1, 0); 133 return; 134 } 135 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 136 if (vector2 == nullptr) { 137 delete vector1; 138 EXPECT_EQ(1, 0); 139 return; 140 } 141 uint16_t value = POINT1.x * POINT2.y - POINT1.y * POINT2.x; 142 143 EXPECT_EQ(vector1->Cross(*vector2), value); 144 145 delete vector1; 146 delete vector2; 147 } 148 149 /** 150 * @tc.name: Vector2Operator_001 151 * @tc.desc: Verify negative operator function, equal. 152 * @tc.type: FUNC 153 * @tc.require: AR000EEMQ9 154 */ 155 HWTEST_F(MathTest, Vector2Operator_001, TestSize.Level0) 156 { 157 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 158 if (vector1 == nullptr) { 159 EXPECT_EQ(1, 0); 160 return; 161 } 162 Vector2<uint16_t> vector3 = vector1->operator-(); 163 164 EXPECT_EQ(vector3.x_, 65531); // 65531: -POINT1.x 165 EXPECT_EQ(vector3.y_, 65532); // 65532: -POINT1.y 166 delete vector1; 167 } 168 169 /** 170 * @tc.name: Vector2Operator_002 171 * @tc.desc: Verify minus operator function, equal. 172 * @tc.type: FUNC 173 * @tc.require: AR000EEMQ9 174 */ 175 HWTEST_F(MathTest, Vector2Operator_002, TestSize.Level0) 176 { 177 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 178 if (vector1 == nullptr) { 179 EXPECT_EQ(1, 0); 180 return; 181 } 182 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 183 if (vector2 == nullptr) { 184 delete vector1; 185 EXPECT_EQ(1, 0); 186 return; 187 } 188 Vector2<uint16_t> vector3 = vector1->operator-(*vector2); 189 190 EXPECT_EQ(vector3.x_, POINT1.x - POINT2.x); 191 EXPECT_EQ(vector3.y_, POINT1.y - POINT2.y); 192 delete vector1; 193 delete vector2; 194 } 195 196 /** 197 * @tc.name: Vector2Operator_003 198 * @tc.desc: Verify addition operator function, equal. 199 * @tc.type: FUNC 200 * @tc.require: AR000EEMQ9 201 */ 202 HWTEST_F(MathTest, Vector2Operator_003, TestSize.Level0) 203 { 204 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 205 if (vector1 == nullptr) { 206 EXPECT_EQ(1, 0); 207 return; 208 } 209 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 210 if (vector2 == nullptr) { 211 delete vector1; 212 EXPECT_EQ(1, 0); 213 return; 214 } 215 Vector2<uint16_t> vector3 = vector1->operator+(*vector2); 216 217 EXPECT_EQ(vector3.x_, POINT1.x + POINT2.x); 218 EXPECT_EQ(vector3.y_, POINT1.y + POINT2.y); 219 delete vector1; 220 delete vector2; 221 } 222 223 /** 224 * @tc.name: Vector2Operator_004 225 * @tc.desc: Verify multiplication operator function, equal. 226 * @tc.type: FUNC 227 * @tc.require: AR000EEMQ9 228 */ 229 HWTEST_F(MathTest, Vector2Operator_004, TestSize.Level0) 230 { 231 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 232 if (vector1 == nullptr) { 233 EXPECT_EQ(1, 0); 234 return; 235 } 236 Vector2<uint16_t> vector3 = vector1->operator*(2); 237 EXPECT_EQ(vector3.x_, POINT1.x * 2); 238 EXPECT_EQ(vector3.y_, POINT1.y * 2); 239 delete vector1; 240 } 241 242 /** 243 * @tc.name: Vector2Operator_005 244 * @tc.desc: Verify equal operator function, equal. 245 * @tc.type: FUNC 246 * @tc.require: AR000EEMQ9 247 */ 248 HWTEST_F(MathTest, Vector2Operator_005, TestSize.Level0) 249 { 250 Vector2<uint16_t>* vector1 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 251 if (vector1 == nullptr) { 252 EXPECT_EQ(1, 0); 253 return; 254 } 255 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 256 if (vector2 == nullptr) { 257 delete vector1; 258 EXPECT_EQ(1, 0); 259 return; 260 } 261 Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 262 if (vector3 == nullptr) { 263 delete vector1; 264 delete vector2; 265 EXPECT_EQ(1, 0); 266 return; 267 } 268 EXPECT_EQ(vector1->operator==(*vector2), false); 269 EXPECT_EQ(vector1->operator==(*vector3), true); 270 271 delete vector1; 272 delete vector2; 273 delete vector3; 274 } 275 276 /** 277 * @tc.name: Vector2Operator_006 278 * @tc.desc: Verify assignment operator function, equal. 279 * @tc.type: FUNC 280 * @tc.require: AR000EEMQ9 281 */ 282 HWTEST_F(MathTest, Vector2Operator_006, TestSize.Level0) 283 { 284 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 285 if (vector2 == nullptr) { 286 EXPECT_EQ(1, 0); 287 return; 288 } 289 Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 290 if (vector3 == nullptr) { 291 delete vector2; 292 EXPECT_EQ(1, 0); 293 return; 294 } 295 vector3->operator=(*vector2); 296 EXPECT_EQ(vector3->x_, POINT2.x); 297 EXPECT_EQ(vector3->y_, POINT2.y); 298 299 delete vector2; 300 delete vector3; 301 } 302 303 /** 304 * @tc.name: Vector2Operator_007 305 * @tc.desc: Verify plus equal operator function, equal. 306 * @tc.type: FUNC 307 * @tc.require: AR000EEMQ9 308 */ 309 HWTEST_F(MathTest, Vector2Operator_007, TestSize.Level0) 310 { 311 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 312 if (vector2 == nullptr) { 313 EXPECT_EQ(1, 0); 314 return; 315 } 316 Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 317 if (vector3 == nullptr) { 318 delete vector2; 319 EXPECT_EQ(1, 0); 320 return; 321 } 322 323 vector3->operator+=(*vector2); 324 EXPECT_EQ(vector3->x_, POINT1.x + POINT2.x); 325 EXPECT_EQ(vector3->y_, POINT1.y + POINT2.y); 326 327 delete vector2; 328 delete vector3; 329 } 330 331 /** 332 * @tc.name: Vector2Operator_008 333 * @tc.desc: Verify minus equal operator function, equal. 334 * @tc.type: FUNC 335 * @tc.require: AR000EEMQ9 336 */ 337 HWTEST_F(MathTest, Vector2Operator_008, TestSize.Level0) 338 { 339 Vector2<uint16_t>* vector2 = new Vector2<uint16_t>(POINT2.x, POINT2.y); 340 if (vector2 == nullptr) { 341 EXPECT_EQ(1, 0); 342 return; 343 } 344 Vector2<uint16_t>* vector3 = new Vector2<uint16_t>(POINT1.x, POINT1.y); 345 if (vector3 == nullptr) { 346 delete vector2; 347 EXPECT_EQ(1, 0); 348 return; 349 } 350 351 vector3->operator-=(*vector2); 352 EXPECT_EQ(vector3->x_, POINT1.x - POINT2.x); 353 EXPECT_EQ(vector3->y_, POINT1.y - POINT2.y); 354 355 delete vector2; 356 delete vector3; 357 } 358 359 /** 360 * @tc.name: Vector3Operator_001 361 * @tc.desc: Verify index operator function, equal. 362 * @tc.type: FUNC 363 * @tc.require: AR000EEMQ9 364 */ 365 HWTEST_F(MathTest, Vector3Operator_001, TestSize.Level0) 366 { 367 const uint16_t posX = 3; 368 const uint16_t posY = 5; 369 const uint16_t posZ = 7; 370 Vector3<uint16_t>* vector1 = new Vector3<uint16_t>(posX, posY, posZ); 371 if (vector1 == nullptr) { 372 EXPECT_EQ(1, 0); 373 return; 374 } 375 376 uint16_t i = 0; 377 EXPECT_EQ(vector1->operator[](i++), posX); 378 EXPECT_EQ(vector1->operator[](i++), posY); 379 EXPECT_EQ(vector1->operator[](i++), posZ); 380 381 delete vector1; 382 } 383 384 /** 385 * @tc.name: Vector3Operator_002 386 * @tc.desc: Verify equal operator function, equal. 387 * @tc.type: FUNC 388 * @tc.require: AR000EEMQ9 389 */ 390 HWTEST_F(MathTest, Vector3Operator_002, TestSize.Level0) 391 { 392 const uint16_t posX = 3; 393 const uint16_t posY = 5; 394 const uint16_t posZ = 7; 395 Vector3<uint16_t>* vector1 = new Vector3<uint16_t>(posX, posY, posZ); 396 if (vector1 == nullptr) { 397 EXPECT_EQ(1, 0); 398 return; 399 } 400 Vector3<uint16_t>* vector2 = new Vector3<uint16_t>(posX, posY, posZ); 401 if (vector2 == nullptr) { 402 delete vector1; 403 EXPECT_EQ(1, 0); 404 return; 405 } 406 Vector3<uint16_t>* vector3 = new Vector3<uint16_t>(posX - 1, posY, posZ); 407 if (vector3 == nullptr) { 408 delete vector1; 409 delete vector2; 410 EXPECT_EQ(1, 0); 411 return; 412 } 413 EXPECT_EQ(vector1->operator==(*vector2), true); 414 EXPECT_EQ(vector1->operator==(*vector3), false); 415 416 delete vector1; 417 delete vector2; 418 delete vector3; 419 } 420 421 /** 422 * @tc.name: Matrix3GetData_001 423 * @tc.desc: Verify GetData function, equal. 424 * @tc.type: FUNC 425 * @tc.require: AR000EEMQ9 426 */ 427 HWTEST_F(MathTest, Matrix3GetData_001, TestSize.Level0) 428 { 429 Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 430 if (matrix == nullptr) { 431 EXPECT_EQ(1, 0); 432 return; 433 } 434 EXPECT_EQ(matrix->GetData()[0], 1); 435 436 delete matrix; 437 } 438 439 /** 440 * @tc.name: Matrix3Operator_001 441 * @tc.desc: Verify multiplication operator function, equal. 442 * @tc.type: FUNC 443 * @tc.require: AR000EEMQ9 444 */ 445 HWTEST_F(MathTest, Matrix3Operator_001, TestSize.Level0) 446 { 447 Matrix3<uint16_t> matrix1(1, 1, 1, 1, 1, 1, 1, 1, 1); 448 /* 449 * 1: m00 Indicates the element in row 1 and column 1 of the matrix. 450 * 2: m01 Indicates the element in row 1 and column 2 of the matrix. 451 * 3: m02 Indicates the element in row 1 and column 3 of the matrix. 452 * 4: m10 Indicates the element in row 2 and column 1 of the matrix. 453 * 5: m11 Indicates the element in row 2 and column 2 of the matrix. 454 * 6: m12 Indicates the element in row 2 and column 3 of the matrix. 455 * 7: m20 Indicates the element in row 3 and column 1 of the matrix. 456 * 8: m21 Indicates the element in row 3 and column 2 of the matrix. 457 * 9: m22 Indicates the element in row 3 and column 3 of the matrix. 458 */ 459 Matrix3<uint16_t> matrix2(1, 2, 3, 4, 5, 6, 7, 8, 9); 460 Matrix3<uint16_t> matrix3 = matrix1 * matrix2; 461 462 uint16_t i = 0; 463 // 6: data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2]; 464 EXPECT_EQ(matrix3.GetData()[i++], 6); 465 // 6: data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2]; 466 EXPECT_EQ(matrix3.GetData()[i++], 6); 467 // 6: data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2]; 468 EXPECT_EQ(matrix3.GetData()[i++], 6); 469 // 15: data_[0] * oData[3] + data_[3] * oData[4] + data_[6] * oData[5]; 470 EXPECT_EQ(matrix3.GetData()[i++], 15); 471 // 15: data_[1] * oData[3] + data_[4] * oData[4] + data_[7] * oData[5]; 472 EXPECT_EQ(matrix3.GetData()[i++], 15); 473 // 15: data_[2] * oData[3] + data_[5] * oData[4] + data_[8] * oData[5]; 474 EXPECT_EQ(matrix3.GetData()[i++], 15); 475 // 24: data_[0] * oData[6] + data_[3] * oData[7] + data_[6] * oData[8]; 476 EXPECT_EQ(matrix3.GetData()[i++], 24); 477 // 24: data_[1] * oData[6] + data_[4] * oData[7] + data_[7] * oData[8]; 478 EXPECT_EQ(matrix3.GetData()[i++], 24); 479 // 24: data_[2] * oData[6] + data_[5] * oData[7] + data_[8] * oData[8]; 480 EXPECT_EQ(matrix3.GetData()[i++], 24); 481 } 482 483 /** 484 * @tc.name: Matrix3Operator_002 485 * @tc.desc: Verify multiplication operator function, equal. 486 * @tc.type: FUNC 487 * @tc.require: AR000EEMQ9 488 */ 489 HWTEST_F(MathTest, Matrix3Operator_002, TestSize.Level0) 490 { 491 Matrix3<uint16_t> matrix1(1, 1, 1, 1, 1, 1, 1, 1, 1); 492 /* 493 * 1: Indicates the X coordinate. 494 * 2: Indicates the Y coordinate. 495 * 3: Indicates the Z coordinate. 496 */ 497 Vector3<uint16_t> vector1(1, 2, 3); 498 Vector3<uint16_t> vector2 = matrix1 * vector1; 499 500 // 6: data_[0] * oData[0] + data_[3] * oData[1] + data_[6] * oData[2]; 501 EXPECT_EQ(vector2.x_, 6); 502 // 6: data_[1] * oData[0] + data_[4] * oData[1] + data_[7] * oData[2]; 503 EXPECT_EQ(vector2.y_, 6); 504 // 6: data_[2] * oData[0] + data_[5] * oData[1] + data_[8] * oData[2]; 505 EXPECT_EQ(vector2.z_, 6); 506 } 507 508 /** 509 * @tc.name: Matrix3Operator_003 510 * @tc.desc: Verify index operator function, equal. 511 * @tc.type: FUNC 512 * @tc.require: AR000EEMQ9 513 */ 514 HWTEST_F(MathTest, Matrix3Operator_003, TestSize.Level0) 515 { 516 Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 0, 0, 1, 0, 0, 1, 0, 0); 517 if (matrix == nullptr) { 518 EXPECT_EQ(1, 0); 519 return; 520 } 521 uint16_t i = 0; 522 EXPECT_EQ(*matrix->operator[](i++), 1); 523 EXPECT_EQ(*matrix->operator[](i++), 1); 524 EXPECT_EQ(*matrix->operator[](i++), 1); 525 526 delete matrix; 527 } 528 529 /** 530 * @tc.name: Matrix3Operator_004 531 * @tc.desc: Verify assignment operator function, equal. 532 * @tc.type: FUNC 533 * @tc.require: AR000EEMQ9 534 */ 535 HWTEST_F(MathTest, Matrix3Operator_004, TestSize.Level0) 536 { 537 Matrix3<uint16_t>* matrix = new Matrix3<uint16_t>(1, 0, 0, 1, 0, 0, 1, 0, 0); 538 if (matrix == nullptr) { 539 EXPECT_EQ(1, 0); 540 return; 541 } 542 Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 543 if (matrix2 == nullptr) { 544 delete matrix; 545 EXPECT_EQ(1, 0); 546 return; 547 } 548 matrix->operator=(*matrix2); 549 uint16_t i = 0; 550 EXPECT_EQ(matrix->GetData()[i++], 1); 551 EXPECT_EQ(matrix->GetData()[i++], 1); 552 EXPECT_EQ(matrix->GetData()[i++], 1); 553 EXPECT_EQ(matrix->GetData()[i++], 1); 554 EXPECT_EQ(matrix->GetData()[i++], 1); 555 EXPECT_EQ(matrix->GetData()[i++], 1); 556 EXPECT_EQ(matrix->GetData()[i++], 1); 557 EXPECT_EQ(matrix->GetData()[i++], 1); 558 EXPECT_EQ(matrix->GetData()[i++], 1); 559 560 delete matrix; 561 delete matrix2; 562 } 563 564 /** 565 * @tc.name: Matrix3Determinant_001 566 * @tc.desc: Verify Determinant operator function, equal. 567 * @tc.type: FUNC 568 * @tc.require: AR000EEMQ9 569 */ 570 HWTEST_F(MathTest, Matrix3Determinant_001, TestSize.Level0) 571 { 572 Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 573 if (matrix2 == nullptr) { 574 EXPECT_EQ(1, 0); 575 return; 576 } 577 EXPECT_EQ(matrix2->Determinant(), 0); 578 579 delete matrix2; 580 } 581 582 /** 583 * @tc.name: Matrix3Inverse_001 584 * @tc.desc: Verify Inverse operator function, equal. 585 * @tc.type: FUNC 586 * @tc.require: AR000EEMQ9 587 */ 588 HWTEST_F(MathTest, Matrix3Inverse_001, TestSize.Level0) 589 { 590 Matrix3<uint16_t>* matrix1 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 591 if (matrix1 == nullptr) { 592 EXPECT_EQ(1, 0); 593 return; 594 } 595 Matrix3<uint16_t> matrix2 = matrix1->Inverse(); 596 597 uint16_t i = 0; 598 EXPECT_EQ(matrix2.GetData()[i++], 1); 599 EXPECT_EQ(matrix2.GetData()[i++], 1); 600 EXPECT_EQ(matrix2.GetData()[i++], 1); 601 EXPECT_EQ(matrix2.GetData()[i++], 1); 602 EXPECT_EQ(matrix2.GetData()[i++], 1); 603 EXPECT_EQ(matrix2.GetData()[i++], 1); 604 EXPECT_EQ(matrix2.GetData()[i++], 1); 605 EXPECT_EQ(matrix2.GetData()[i++], 1); 606 EXPECT_EQ(matrix2.GetData()[i++], 1); 607 608 delete matrix1; 609 } 610 611 /** 612 * @tc.name: Matrix3Operator_005 613 * @tc.desc: Verify equal operator function, equal. 614 * @tc.type: FUNC 615 * @tc.require: AR000EEMQ9 616 */ 617 HWTEST_F(MathTest, Matrix3Operator_005, TestSize.Level0) 618 { 619 Matrix3<uint16_t>* matrix1 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 620 if (matrix1 == nullptr) { 621 EXPECT_EQ(1, 0); 622 return; 623 } 624 Matrix3<uint16_t>* matrix2 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 1, 1, 1); 625 if (matrix2 == nullptr) { 626 delete matrix1; 627 EXPECT_EQ(1, 0); 628 return; 629 } 630 Matrix3<uint16_t>* matrix3 = new Matrix3<uint16_t>(1, 1, 1, 1, 1, 1, 0, 1, 1); 631 if (matrix3 == nullptr) { 632 delete matrix1; 633 delete matrix2; 634 EXPECT_EQ(1, 0); 635 return; 636 } 637 638 EXPECT_EQ(matrix1->operator==(*matrix2), true); 639 EXPECT_EQ(matrix1->operator==(*matrix3), false); 640 641 delete matrix1; 642 delete matrix2; 643 delete matrix3; 644 } 645 646 /** 647 * @tc.name: Matrix3Rotate_001 648 * @tc.desc: Verify Rotate function, equal. 649 * @tc.type: FUNC 650 * @tc.require: AR000EEMQ9 651 */ 652 HWTEST_F(MathTest, Matrix3Rotate_001, TestSize.Level0) 653 { 654 Matrix3<uint64_t> rotate = Matrix3<uint64_t>::Rotate(0, Vector2<uint64_t>(0, 0)); 655 uint16_t i = 0; 656 EXPECT_EQ(rotate.GetData()[i++], 1); 657 EXPECT_EQ(rotate.GetData()[i++], 0); 658 EXPECT_EQ(rotate.GetData()[i++], 0); 659 EXPECT_EQ(rotate.GetData()[i++], 0); 660 EXPECT_EQ(rotate.GetData()[i++], 1); 661 EXPECT_EQ(rotate.GetData()[i++], 0); 662 EXPECT_EQ(rotate.GetData()[i++], 0); 663 EXPECT_EQ(rotate.GetData()[i++], 0); 664 EXPECT_EQ(rotate.GetData()[i++], 1); 665 } 666 667 /** 668 * @tc.name: Matrix3Scale_001 669 * @tc.desc: Verify Scale function, equal. 670 * @tc.type: FUNC 671 * @tc.require: AR000EEMQ9 672 */ 673 HWTEST_F(MathTest, Matrix3Scale_001, TestSize.Level0) 674 { 675 Matrix3<int64_t> scale = 676 Matrix3<int64_t>::Scale(Vector2<int64_t>(1, 1), Vector2<int64_t>(0, 0)); 677 uint16_t i = 0; 678 EXPECT_EQ(scale.GetData()[i++], 1); 679 EXPECT_EQ(scale.GetData()[i++], 0); 680 EXPECT_EQ(scale.GetData()[i++], 0); 681 EXPECT_EQ(scale.GetData()[i++], 0); 682 EXPECT_EQ(scale.GetData()[i++], 1); 683 EXPECT_EQ(scale.GetData()[i++], 0); 684 EXPECT_EQ(scale.GetData()[i++], 0); 685 EXPECT_EQ(scale.GetData()[i++], 0); 686 EXPECT_EQ(scale.GetData()[i++], 1); 687 } 688 689 /** 690 * @tc.name: Matrix3Translate_001 691 * @tc.desc: Verify Translate function, equal. 692 * @tc.type: FUNC 693 * @tc.require: AR000EEMQ9 694 */ 695 HWTEST_F(MathTest, Matrix3Translate_001, TestSize.Level0) 696 { 697 Matrix3<int64_t> translate = Matrix3<int64_t>::Translate(Vector2<int64_t>(0, 0)); 698 uint16_t i = 0; 699 EXPECT_EQ(translate.GetData()[i++], 1); 700 EXPECT_EQ(translate.GetData()[i++], 0); 701 EXPECT_EQ(translate.GetData()[i++], 0); 702 EXPECT_EQ(translate.GetData()[i++], 0); 703 EXPECT_EQ(translate.GetData()[i++], 1); 704 EXPECT_EQ(translate.GetData()[i++], 0); 705 EXPECT_EQ(translate.GetData()[i++], 0); 706 EXPECT_EQ(translate.GetData()[i++], 0); 707 EXPECT_EQ(translate.GetData()[i++], 1); 708 } 709 } // namespace OHOS 710