PIMathVector Tests and bug fixes in PIMathMatrixT

This commit is contained in:
2020-09-17 17:07:29 +03:00
parent aae59106f0
commit c3abd747f2
6 changed files with 870 additions and 3058 deletions

View File

@@ -111,18 +111,18 @@ TEST(PIMathMatrix_Test, swapCols) {
double a1[3], a2[3], a3[3];
double b1[3], b2[3], b3[3];
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix1 = origMatr.identity(3, 3);
matrix1.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix1.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix1.setCol(2, vector);
for(int i = 0; i < 3; i++) {
a1[i] = matrix1.element(i, 0);
@@ -146,18 +146,18 @@ TEST(PIMathMatrix_Test, swapRows) {
double a1[3], a2[3], a3[3];
double b1[3], b2[3], b3[3];
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix1 = origMatr.identity(3, 3);
matrix1.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix1.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix1.setCol(2, vector);
for(int i = 0; i < 3; i++) {
a1[i] = matrix1.element(0, i);
@@ -339,17 +339,17 @@ TEST(PIMathMatrix_Test, determinantIfSquare) {
PIMathMatrix<double> matrix(3, 3, 0.0);
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix.setCol(2, vector);
d = matrix.determinant();
ASSERT_DOUBLE_EQ(d, i);
@@ -367,17 +367,17 @@ TEST(PIMathMatrix_Test, trace) {
double i = 9.0;
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix.setCol(2, vector);
t = matrix.trace();
ASSERT_DOUBLE_EQ(t, i);
@@ -395,17 +395,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular) {
int i;
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix.setCol(2, vector);
d1 = matrix.determinant();
matrix.toUpperTriangular();
@@ -424,17 +424,17 @@ TEST(PIMathMatrix_Test, invert) {
PIMathMatrix<double> matrix4(3, 3, 0.0);
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix1.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix1.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix1.setCol(2, vector);
d1 = matrix1.determinant();
matrix2 = matrix1;
@@ -452,17 +452,17 @@ TEST(PIMathMatrix_Test, inverted) {
PIMathMatrix<double> matrix4(3, 3, 0.0);
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix1.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix1.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix1.setCol(2, vector);
d1 = matrix1.determinant();
matrix2 = matrix1;
@@ -480,18 +480,17 @@ TEST(PIMathMatrix_Test, transposed) {
PIMathMatrix<double> matrix3;
PIMathVector<double> vector;
vector.resize(3, 3.0);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
matrix1 = origMatr.identity(3, 3);
vector[0] = 3.0;
vector[1] = 6.0;
vector[2] = 8.0;
matrix1.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
vector[0] = 2.0;
vector[1] = 1.0;
vector[2] = 4.0;
matrix1.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
vector[0] = 6.0;
vector[1] = 2.0;
vector[2] = 5.0;
matrix1.setCol(2, vector);
d1 = matrix1.determinant();
matrix2 = matrix1.transposed();

View File

@@ -106,9 +106,9 @@ TEST(PIMathMatrixT_Test, row) {
TEST(PIMathMatrixT_Test, setCol) {
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect;
vect.at(0) = 1.0;
vect.at(1) = 3.0;
vect.at(2) = 5.0;
vect[0] = 1.0;
vect[1] = 3.0;
vect[2] = 5.0;
uint g = 1;
matr.setCol(g, vect);
for(uint i = 0; i < vect.size(); i++) {
@@ -122,9 +122,9 @@ TEST(PIMathMatrixT_Test, setCol) {
TEST(PIMathMatrixT_Test, setRow) {
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect;
vect.at(0) = 1.0;
vect.at(1) = 3.0;
vect.at(2) = 5.0;
vect[0] = 1.0;
vect[1] = 3.0;
vect[2] = 5.0;
uint g = 1;
matr.setRow(g, vect);
for(uint i = 0; i < vect.size(); i++) {

View File

@@ -0,0 +1,364 @@
#include "gtest/gtest.h"
#include "pimathvector.h"
bool cmpVectorWithValue(PIMathVector<double> vector, double val, int num) {
bool b = true;
for(int i = 0; i < num; i++) {
if(vector[i] != val) {
b = false;
}
}
return b;
}
TEST(PIMathVector_Test, size) {
auto vector = PIMathVector<double>(3u);
ASSERT_TRUE(vector.size() == 3u);
}
TEST(PIMathVector_Test, resize) {
PIMathVector<double> vector;
vector.resize(4u, 5.0);
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size()));
}
TEST(PIMathVector_Test, resized) {
PIMathVector<double> vector;
vector.resized(4u, 5.0);
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size()));
}
TEST(PIMathVector_Test, fill) {
PIMathVector<double> vector(3u);
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3u));
}
TEST(PIMathVector_Test, moveVal) {
PIMathVector<double> vector(3u);
vector.fill(5.0);
vector.move(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector, 10.0, 3u));
}
TEST(PIMathVector_Test, moveVec) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vector.fill(5.0);
vec.fill(7.0);
vector.move(vec);
ASSERT_TRUE(cmpVectorWithValue(vector, 12.0, 3u));
}
TEST(PIMathVector_Test, swap) {
PIMathVector<double> vector(3u);
double a[3];
vector[0] = 5.12;
vector[1] = 3.32;
vector[2] = 7.12;
a[0] = vector[0];
a[1] = vector[1];
a[2] = vector[2];
vector.swap(0u, 1u);
ASSERT_TRUE((a[0] == vector[1]) && (a[1] == vector[0]) && (a[2] == vector[2]));
}
TEST(PIMathVector_Test, lengthSqr) {
PIMathVector<double> vector(3u);
vector.fill(1.0);
ASSERT_EQ(3.0, vector.lengthSqr());
}
TEST(PIMathVector_Test, length) {
PIMathVector<double> vector(3u);
vector.fill(1.0);
ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length());
}
TEST(PIMathVector_Test, manhattanLength) {
PIMathVector<double> vector(3u);
vector.fill(5.0);
ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength());
}
TEST(PIMathVector_Test, angleCos) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec));
}
TEST(PIMathVector_Test, angleSin) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec));
}
TEST(PIMathVector_Test, angleRad) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec));
}
TEST(PIMathVector_Test, angleDeg) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec));
}
TEST(PIMathVector_Test, projection) {
PIMathVector<double> vector(2u);
PIMathVector<double> vec(2u);
vec[0] = 1.0;
vector[0] = 1.0;
vector[1] = 1.0;
auto vecProj = vector.projection(vec);
ASSERT_TRUE(vecProj == vec);
}
TEST(PIMathVector_Test, normalize) {
PIMathVector<double> vector(3u);
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u));
}
TEST(PIMathVector_Test, normalized) {
PIMathVector<double> vector(3u);
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u));
}
TEST(PIMathVector_Test, isNullTrue) {
PIMathVector<double> vector(3u);
ASSERT_TRUE(vector.isNull());
}
TEST(PIMathVector_Test, isNullFalse) {
PIMathVector<double> vector(3u);
vector[0] = 6.273;
ASSERT_FALSE(vector.isNull());
}
TEST(PIMathVector_Test, isValidTrue) {
PIMathVector<double> vector(3u);
ASSERT_TRUE(vector.isValid());
}
TEST(PIMathVector_Test, isValidFalse) {
PIMathVector<double> vector;
ASSERT_FALSE(vector.isValid());
}
TEST(PIMathVector_Test, isOrthoTrue) {
PIMathVector<double> vector(2u);
PIMathVector<double> vect(2u);
vector[0] = 2.0;
vect[1] = 1.0;
ASSERT_TRUE(vector.isOrtho(vect));
}
TEST(PIMathVector_Test, isOrthoFalse) {
PIMathVector<double> vector(2u);
PIMathVector<double> vect(2u);
vector[0] = 2.0;
vect[0] = 5.0;
vect[1] = 1.0;
ASSERT_FALSE(vector.isOrtho(vect));
}
TEST(PIMathVector_Test, at) {
PIMathVector<double> vector(3u);
vector.fill(5.5);
for(uint i = 0; i < 3u; i++){
if(vector.at(i) != 5.5){
ASSERT_TRUE(false);
}
}
ASSERT_TRUE(true);
}
TEST(PIMathVector_Test, operator_AssignmentValue) {
PIMathVector<double> vector(3u);
vector = 3.0;
ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3));
}
TEST(PIMathVector_Test, operator_AssignmentVector) {
PIMathVector<double> vector(3u);
PIMathVector<double> vec(3u);
vec = 5.0;
vector = vec;
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3));
}
TEST(PIMathVector_Test, operator_EqualTrue) {
PIMathVector<double> vector(2u);
PIMathVector<double> vec(2u);
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 7.34;
ASSERT_TRUE(vec == vector);
}
TEST(PIMathVector_Test, operator_EqualFalse) {
PIMathVector<double> vector(2u);
PIMathVector<double> vec(2u);
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 0.34;
ASSERT_FALSE(vec == vector);
}
TEST(PIMathVector_Test, operator_Not_EqualTrue) {
PIMathVector<double> vector(2u);
PIMathVector<double> vec(2u);
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 0.34;
ASSERT_TRUE(vec != vector);
}
TEST(PIMathVector_Test, operator_Not_EqualFalse) {
PIMathVector<double> vector(2u);
PIMathVector<double> vec(2u);
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 7.34;
ASSERT_FALSE(vec != vector);
}
TEST(PIMathVector_Test, operator_Addition_Aassignment) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
vector1 += vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3));
}
TEST(PIMathVector_Test, operator_Subtraction_Assignment) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
vector1 -= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3));
}
TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) {
PIMathVector<double> vector1(3u);
vector1.fill(6.0);
vector1 *= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3));
}
TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
vector1 *= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3));
}
TEST(PIMathVector_Test, operator_Division_AssignmentValue) {
PIMathVector<double> vector1(3u);
vector1.fill(6.0);
vector1 /= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3));
}
TEST(PIMathVector_Test, operator_Division_AssignmentVector) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.5);
vector1 /= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3));
}
TEST(PIMathVector_Test, operator_Addition) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3));
}
TEST(PIMathVector_Test, operator_Subtraction) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3));
}
TEST(PIMathVector_Test, operator_MultiplicationValue) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3));
}
TEST(PIMathVector_Test, operator_MultiplicationVector1) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3));
}
TEST(PIMathVector_Test, operator_MultiplicationVector2) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1[0] = 1.0;
vector2[1] = 1.0;
ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0));
}
TEST(PIMathVector_Test, operator_DivisionVector) {
PIMathVector<double> vector1(3u);
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3));
}
TEST(PIMathVector_Test, operator_MultiplVect) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3));
}
TEST(PIMathVector_Test, operator_absDotProduct) {
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vector1.fill(6.0);
vector2.fill(5.0);
ASSERT_TRUE(90.0 == (vector1 ^ vector2));
}
TEST(PIMathVector_Test, distToLine) {
PIMathVector<double> vect(3u);
PIMathVector<double> vector1(3u);
PIMathVector<double> vector2(3u);
vect.fill(6.0);
vector1[0] = 1.0;
vector2[1] = -1.0;
ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0);
}

View File

@@ -0,0 +1,427 @@
#include "gtest/gtest.h"
#include "pimathvector.h"
#include "pimathmatrix.h"
const uint size = 3u;
bool cmpVectorWithValue(PIMathVectorT<size, double> vector, double val, int num) {
bool b = true;
for(int i = 0; i < num; i++) {
if(vector[i] != val) {
b = false;
}
}
return b;
}
TEST(PIMathVectorT_Test, size) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(vector.size() == 3u);
}
TEST(PIMathVectorT_Test, fill) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.fill(5.0), 5.0, 3));
}
TEST(PIMathVectorT_Test, set) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(5.0), vector2.fill(3.0)), -2.0, 3));
}
TEST(PIMathVectorT_Test, MoveVal) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.move(4.0), 4.0, 3));
}
TEST(PIMathVectorT_Test, MoveVector) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vector1;
ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(5.0)), 5.0, 3));
}
TEST(PIMathVectorT_Test, lengthSqr) {
PIMathVectorT<size, double> vector;
vector.fill(1.0);
ASSERT_EQ(3.0, vector.lengthSqr());
}
TEST(PIMathVectorT_Test, length) {
PIMathVectorT<size, double> vector;
vector.fill(1.0);
ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length());
}
TEST(PIMathVectorT_Test, manhattanLength) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength());
}
TEST(PIMathVectorT_Test, angleCos) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleCos(vec));
}
TEST(PIMathVectorT_Test, angleSin) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(cos(0.78539816339744830961566084581988), vector.angleSin(vec));
}
TEST(PIMathVectorT_Test, angleRad) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(0.78539816339744830961566084581988, vector.angleRad(vec));
}
TEST(PIMathVectorT_Test, angleDeg) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(45.0, vector.angleDeg(vec));
}
TEST(PIMathVectorT_Test, angleElevation) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 1.0;
vector[1] = 1.0;
vec[1] = 1.0;
ASSERT_DOUBLE_EQ(-45.0, vector.angleElevation(vec));
}
TEST(PIMathVectorT_Test, projection) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vec[0] = 1.0;
vector[0] = 1.0;
vector[1] = 1.0;
auto vecProj = vector.projection(vec);
ASSERT_TRUE(vecProj == vec);
}
TEST(PIMathVectorT_Test, normalize) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u));
}
TEST(PIMathVectorT_Test, normalized) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u));
}
TEST(PIMathVectorT_Test, cross1) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), 0.0, 3));
}
TEST(PIMathVectorT_Test, cross2) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
vector1[0] = 1.0;
vector2[1] = 1.0;
ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0));
}
TEST(PIMathVectorT_Test, dot) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
vector1.fill(6.0);
vector2.fill(5.0);
ASSERT_EQ(vector1.dot(vector2), 90.0);
}
TEST(PIMathVectorT_Test, isNullTrue) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(vector.isNull());
}
TEST(PIMathVectorT_Test, isNullFalse) {
PIMathVectorT<size, double> vector;
vector[0] = 6.273;
ASSERT_FALSE(vector.isNull());
}
TEST(PIMathVectorT_Test, isOrthoTrue) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vect;
vector[0] = 2.0;
vect[1] = 1.0;
ASSERT_TRUE(vector.isOrtho(vect));
}
TEST(PIMathVectorT_Test, isOrthoFalse) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vect;
vector[0] = 2.0;
vect[0] = 5.0;
vect[1] = 1.0;
ASSERT_FALSE(vector.isOrtho(vect));
}
TEST(PIMathVectorT_Test, at) {
PIMathVectorT<size, double> vector;
vector.fill(5.5);
for(uint i = 0; i < 3u; i++){
if(vector.at(i) != 5.5){
ASSERT_TRUE(false);
}
}
ASSERT_TRUE(true);
}
TEST(PIMathVectorT_Test, operator_AssignmentValue) {
PIMathVectorT<size, double> vector;
vector = 3.0;
ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3));
}
TEST(PIMathVectorT_Test, operator_AssignmentVector) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vec = 5.0;
vector = vec;
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3));
}
TEST(PIMathVectorT_Test, operator_EqualTrue) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 7.34;
ASSERT_TRUE(vec == vector);
}
TEST(PIMathVectorT_Test, operator_EqualFalse) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 0.34;
ASSERT_FALSE(vec == vector);
}
TEST(PIMathVectorT_Test, operator_Not_EqualTrue) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 0.34;
ASSERT_TRUE(vec != vector);
}
TEST(PIMathVectorT_Test, operator_Not_EqualFalse) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vector[0] = 5.12;
vector[1] = 7.34;
vec[0] = 5.12;
vec[1] = 7.34;
ASSERT_FALSE(vec != vector);
}
TEST(PIMathVectorT_Test, operator_Addition_Aassignment) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
vector1 += vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3));
}
TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
vector1 -= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3));
}
TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
vector1 *= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3));
}
TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentVector) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
vector1 *= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3));
}
TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
vector1 /= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3));
}
TEST(PIMathVectorT_Test, operator_Division_AssignmentVector) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.5);
vector1 /= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3));
}
TEST(PIMathVectorT_Test, operator_Addition) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, 7.72, 3));
}
TEST(PIMathVectorT_Test, operator_Subtraction) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, 4.28, 3));
}
TEST(PIMathVectorT_Test, operator_MultiplicationValue) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 * 4.0, 24.0, 3));
}
TEST(PIMathVectorT_Test, operator_MultiplicationVector1) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, 3));
}
TEST(PIMathVectorT_Test, operator_MultiplicationVector2) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1[0] = 1.0;
vector2[1] = 1.0;
ASSERT_TRUE(((vector1 * vector2)[0] == 0.0) && ((vector1 * vector2)[1] == 0.0) && ((vector1 * vector2)[2] == 1.0));
}
TEST(PIMathVectorT_Test, operator_DivisionVal) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3));
}
TEST(PIMathVectorT_Test, operator_DivisionVector) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
vector1.fill(6.0);
vector2.fill(4.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, 1.5, 3));
}
TEST(PIMathVectorT_Test, operator_MultiplVect) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, 30.0, 3));
}
TEST(PIMathVectorT_Test, operator_absDotProduct) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(5.0);
ASSERT_TRUE(90.0 == (vector1 ^ vector2));
}
TEST(PIMathVectorT_Test, transposed) {
PIMathVectorT<size, double> vector;
vector.fill(6.0);
auto matrix = vector.transposed();
for(int i = 0; i < size; i++){
if(matrix[0][i] != 6.0)
{
ASSERT_TRUE(false);
}
}
ASSERT_TRUE(true);
}
TEST(PIMathVectorT_Test, filled) {
auto vector = PIMathVectorT<size, double>::filled(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector, 6.0, 3));
}
TEST(PIMathVectorT_Test, distToLine) {
PIMathVectorT<size, double> vect;
PIMathVectorT<size, double> vector1;
PIMathVectorT<size, double> vector2;
vect.fill(6.0);
vector1[0] = 1.0;
vector2[1] = -1.0;
ASSERT_DOUBLE_EQ(vect.distToLine(vector1, vector2), sqrt(2.0)/2.0);
}
TEST(PIMathVectorT_Test, turnTo) {
PIMathVectorT<size, double> vect;
vect.fill(6.0);
auto vector = vect.turnTo<2u, double>();
ASSERT_TRUE((vector.size() == 2) && (vector.size() == 2));
}
TEST(PIMathVectorT_Test, LogicalOrTrue) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
ASSERT_TRUE(vector1 || vector2);
}
TEST(PIMathVectorT_Test, LogicalOrFalse) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1[0] = 1.0;
vector2[1] = 1.0;
ASSERT_FALSE(vector1 || vector2);
}
TEST(PIMathVectorT_Test, sqrt) {
PIMathVectorT<size, double> vector1;
vector1.fill(36.0);
ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), 6.0, 3u));
}
TEST(PIMathVectorT_Test, sqr) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), 36.0, 3u));
}