documentation and tests bug fix for PIMathVector.h

This commit is contained in:
2020-09-25 12:36:05 +03:00
parent b7f035178f
commit 0940e8fa44
5 changed files with 740 additions and 590 deletions

View File

@@ -2,188 +2,233 @@
#include "pimathvector.h"
#include "pimathmatrix.h"
const uint size = 3u;
const uint SIZE = 3u;
bool cmpVectorWithValue(PIMathVectorT<size, double> vector, double val, int num) {
bool cmpVectorWithValue(PIMathVectorT<SIZE, double> vector, double val, int num) {
bool b = true;
for(int i = 0; i < num; i++) {
if(vector[i] != val) {
if(vector[i] - val >= double(1E-200)) {
b = false;
}
}
return b;
}
TEST(PIMathVectorT_Test, size) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(vector.size() == 3u);
TEST(PIMathVectorT_Test, SIZE) {
PIMathVectorT<SIZE, double> vector;
ASSERT_TRUE(vector.size() == SIZE);
}
TEST(PIMathVectorT_Test, fill) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.fill(5.0), 5.0, 3));
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.fill(a), a, SIZE));
}
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));
double a = 5.0;
double b = 3.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE, double> vector2;
ASSERT_TRUE(cmpVectorWithValue(vector.set(vector1.fill(a), vector2.fill(b)), b - a, SIZE));
}
TEST(PIMathVectorT_Test, MoveVal) {
PIMathVectorT<size, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.move(4.0), 4.0, 3));
double a = 4.0;
PIMathVectorT<SIZE, double> vector;
ASSERT_TRUE(cmpVectorWithValue(vector.move(a), a, SIZE));
}
TEST(PIMathVectorT_Test, MoveVector) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vector1;
ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(5.0)), 5.0, 3));
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vector1;
ASSERT_TRUE(cmpVectorWithValue(vector.move(vector1.fill(a)), a, SIZE));
}
TEST(PIMathVectorT_Test, lengthSqr) {
PIMathVectorT<size, double> vector;
vector.fill(1.0);
ASSERT_EQ(3.0, vector.lengthSqr());
double a = 1.0;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
ASSERT_DOUBLE_EQ(SIZE * a, vector.lengthSqr());
}
TEST(PIMathVectorT_Test, length) {
PIMathVectorT<size, double> vector;
vector.fill(1.0);
ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length());
double a = 1.0;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
ASSERT_DOUBLE_EQ(sqrt(SIZE * a), vector.length());
}
TEST(PIMathVectorT_Test, manhattanLength) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength());
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
ASSERT_DOUBLE_EQ(SIZE * a, 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));
double a = 1.0;
double angle = 0.78539816339744830961566084581988;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = a;
vec[1] = a;
ASSERT_DOUBLE_EQ(cos(angle), 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));
double a = 1.0;
double angle = 0.78539816339744830961566084581988;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = a;
vec[1] = a;
ASSERT_DOUBLE_EQ(sin(angle), 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));
double a = 1.0;
double angle = 0.78539816339744830961566084581988;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = a;
vec[1] = a;
ASSERT_DOUBLE_EQ(angle, 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));
double a = 1.0;
double angle = 45.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = a;
vec[1] = a;
ASSERT_DOUBLE_EQ(angle, 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));
double a = 1.0;
double angle = 45.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = a;
vec[1] = a;
ASSERT_DOUBLE_EQ(-angle, 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;
double a = 2.0;
double b = 2.0;
double res = sqrt(32.0);
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vec[0] = a;
vec[2] = b;
vector[0] = a;
vector[1] = b;
vector[2] = a;
auto vecProj = vector.projection(vec);
ASSERT_TRUE(vecProj == vec);
ASSERT_DOUBLE_EQ(res, vecProj[0]);
ASSERT_DOUBLE_EQ(0.0, vecProj[1]);
ASSERT_DOUBLE_EQ(res, vecProj[2]);
}
TEST(PIMathVectorT_Test, normalize) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u));
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE));
}
TEST(PIMathVectorT_Test, normalized) {
PIMathVectorT<size, double> vector;
vector.fill(5.0);
ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u));
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vectorNew;
vector.fill(a);
vectorNew = vector.normalized();
ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE));
}
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));
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE, double> vector2;
double a = 5.0;
double b = 1.72;
double c = 0.0;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue(vector1.cross(vector2), c, SIZE));
}
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));
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE, double> vector2;
double a = 1.0;
vector1[0] = a;
vector2[1] = a;
auto crossVec = vector1 * vector2;
ASSERT_DOUBLE_EQ(crossVec[0], 0.0);
ASSERT_DOUBLE_EQ(crossVec[1], 0.0);
ASSERT_DOUBLE_EQ(crossVec[2], a);
}
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);
double a = 6.0;
double b = 5.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE, double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_DOUBLE_EQ(vector1.dot(vector2), SIZE * a * b);
}
TEST(PIMathVectorT_Test, isNullTrue) {
PIMathVectorT<size, double> vector;
PIMathVectorT<SIZE, double> vector;
ASSERT_TRUE(vector.isNull());
}
TEST(PIMathVectorT_Test, isNullFalse) {
PIMathVectorT<size, double> vector;
vector[0] = 6.273;
double a = 6.273;
PIMathVectorT<SIZE, double> vector;
vector[0] = a;
ASSERT_FALSE(vector.isNull());
}
TEST(PIMathVectorT_Test, isOrthoTrue) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vect;
vector[0] = 2.0;
vect[1] = 1.0;
double a = 2.0;
double b = 1.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vect;
vector[0] = a;
vect[1] = b;
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;
double a = 2.0;
double b = 5.0;
double c = 1.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vect;
vector[0] = a;
vect[0] = b;
vect[1] = c;
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){
double a = 5.5;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
for(uint i = 0; i < SIZE; i++){
if(vector.at(i) != a){
ASSERT_TRUE(false);
}
}
@@ -191,184 +236,226 @@ TEST(PIMathVectorT_Test, at) {
}
TEST(PIMathVectorT_Test, operator_AssignmentValue) {
PIMathVectorT<size, double> vector;
vector = 3.0;
ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3));
double a = 3.0;
PIMathVectorT<SIZE, double> vector;
vector = a;
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
}
TEST(PIMathVectorT_Test, operator_AssignmentVector) {
PIMathVectorT<size, double> vector;
PIMathVectorT<size, double> vec;
vec = 5.0;
double a = 5.0;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vec = a;
vector = vec;
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3));
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
}
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;
double a = 5.12;
double b = 7.34;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = b;
vec[0] = a;
vec[1] = b;
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;
double a = 5.12;
double b = 7.34;
double c = 0.34;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = b;
vec[0] = a;
vec[1] = c;
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;
double a = 5.12;
double b = 7.34;
double c = 0.34;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = b;
vec[0] = a;
vec[1] = c;
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;
double a = 5.12;
double b = 7.34;
PIMathVectorT<SIZE, double> vector;
PIMathVectorT<SIZE, double> vec;
vector[0] = a;
vector[1] = b;
vec[0] = a;
vec[1] = b;
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);
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
vector1 += vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3));
ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE));
}
TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
vector1 -= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3));
ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE));
}
TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
vector1 *= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3));
double a = 6.0;
double b = 4.0;
PIMathVectorT<SIZE, double> vector1;
vector1.fill(a);
vector1 *= b;
ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE));
}
TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentVector) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
vector1 *= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3));
ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE));
}
TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
vector1 /= 4.0;
ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3));
double a = 6.0;
double b = 4.0;
PIMathVectorT<SIZE, double> vector1;
vector1.fill(a);
vector1 /= b;
ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE));
}
TEST(PIMathVectorT_Test, operator_Division_AssignmentVector) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.5);
double a = 6.0;
double b = 1.5;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
vector1 /= vector2;
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3));
ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE));
}
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));
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE));
}
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));
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE));
}
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));
double a = 6.0;
double b = 4.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE));
}
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));
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE));
}
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));
double a = 1.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1[0] = a;
vector2[1] = a;
ASSERT_TRUE(((vector1 * vector2)[0] < double(1E-200)) && ((vector1 * vector2)[1] < double(1E-200)) && ((vector1 * vector2)[2] - a < double(1E-200)));
}
TEST(PIMathVectorT_Test, operator_DivisionVal) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(vector1 / 4.0, 1.5, 3));
double a = 6.0;
double b = 4.0;
PIMathVectorT<SIZE, double> vector1;
vector1.fill(a);
ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE));
}
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));
double a = 6.0;
double b = 4.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE, double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue(vector1 / vector2, a / b, SIZE));
}
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));
double a = 6.0;
double b = 5.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE));
}
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));
double a = 6.0;
double b = 5.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_DOUBLE_EQ(vector1 ^ vector2, SIZE * a * b);
}
TEST(PIMathVectorT_Test, transposed) {
PIMathVectorT<size, double> vector;
vector.fill(6.0);
double a = 6.0;
PIMathVectorT<SIZE, double> vector;
vector.fill(a);
auto matrix = vector.transposed();
for(int i = 0; i < size; i++){
if(matrix[0][i] != 6.0)
for(int i = 0; i < SIZE; i++){
if(matrix[0][i] != a)
{
ASSERT_TRUE(false);
}
@@ -377,51 +464,48 @@ TEST(PIMathVectorT_Test, transposed) {
}
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);
double a = 6.0;
auto vector = PIMathVectorT<SIZE, double>::filled(a);
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
}
TEST(PIMathVectorT_Test, turnTo) {
PIMathVectorT<size, double> vect;
vect.fill(6.0);
double a = 6.0;
PIMathVectorT<SIZE, double> vect;
vect.fill(a);
auto vector = vect.turnTo<2u, double>();
ASSERT_TRUE((vector.size() == 2) && (vector.size() == 2));
ASSERT_TRUE(vector.size() == 2);
}
TEST(PIMathVectorT_Test, LogicalOrTrue) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1.fill(6.0);
vector2.fill(1.72);
double a = 6.0;
double b = 1.72;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1.fill(a);
vector2.fill(b);
ASSERT_TRUE(vector1 || vector2);
}
TEST(PIMathVectorT_Test, LogicalOrFalse) {
PIMathVectorT<size, double> vector1;
PIMathVectorT<size,double> vector2;
vector1[0] = 1.0;
vector2[1] = 1.0;
double a = 1.0;
PIMathVectorT<SIZE, double> vector1;
PIMathVectorT<SIZE,double> vector2;
vector1[0] = a;
vector2[1] = a;
ASSERT_FALSE(vector1 || vector2);
}
TEST(PIMathVectorT_Test, sqrt) {
PIMathVectorT<size, double> vector1;
vector1.fill(36.0);
ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), 6.0, 3u));
double a = 36.0;
PIMathVectorT<SIZE, double> vector1;
vector1.fill(a);
ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), sqrt(a), SIZE));
}
TEST(PIMathVectorT_Test, sqr) {
PIMathVectorT<size, double> vector1;
vector1.fill(6.0);
ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), 36.0, 3u));
double a = 6.0;
PIMathVectorT<SIZE, double> vector1;
vector1.fill(a);
ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), sqr(a), SIZE));
}