documentation and tests bug fix for PIMathVector.h
This commit is contained in:
@@ -5,7 +5,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrix<double> matrix, double val, int num)
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.element(i, j) != val) {
|
||||
if(matrix.element(i, j) - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double v
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.at(i, j) != val) {
|
||||
if(matrix.at(i, j) - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathvector.h"
|
||||
|
||||
const uint SIZE = 3u;
|
||||
|
||||
bool cmpVectorWithValue(PIMathVector<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;
|
||||
}
|
||||
}
|
||||
@@ -12,146 +14,181 @@ bool cmpVectorWithValue(PIMathVector<double> vector, double val, int num) {
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, size) {
|
||||
auto vector = PIMathVector<double>(3u);
|
||||
ASSERT_TRUE(vector.size() == 3u);
|
||||
auto vector = PIMathVector<double>(SIZE);
|
||||
ASSERT_TRUE(vector.size() == SIZE);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, resize) {
|
||||
uint newSize = 4u;
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(4u, 5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size()));
|
||||
vector.resize(newSize, a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size()));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, resized) {
|
||||
uint newSize = 4u;
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector;
|
||||
vector.resized(4u, 5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, vector.size()));
|
||||
vector.resized(newSize, a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size()));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, fill) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3u));
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, moveVal) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(5.0);
|
||||
vector.move(5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 10.0, 3u));
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
vector.move(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 2 * a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, moveVec) {
|
||||
PIMathVector<double> vector(3u);
|
||||
PIMathVector<double> vec(3u);
|
||||
vector.fill(5.0);
|
||||
vec.fill(7.0);
|
||||
double a = 5.0;
|
||||
double b = 7.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector.fill(a);
|
||||
vec.fill(b);
|
||||
vector.move(vec);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 12.0, 3u));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a + b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, swap) {
|
||||
PIMathVector<double> vector(3u);
|
||||
double b = 5.12;
|
||||
double c = 3.32;
|
||||
double d = 7.12;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
double a[3];
|
||||
vector[0] = 5.12;
|
||||
vector[1] = 3.32;
|
||||
vector[2] = 7.12;
|
||||
vector[0] = b;
|
||||
vector[1] = c;
|
||||
vector[2] = d;
|
||||
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]));
|
||||
ASSERT_DOUBLE_EQ(a[0], vector[1]);
|
||||
ASSERT_DOUBLE_EQ(a[1], vector[0]);
|
||||
ASSERT_DOUBLE_EQ(a[2], vector[2]);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, lengthSqr) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(1.0);
|
||||
ASSERT_EQ(3.0, vector.lengthSqr());
|
||||
double a = 3.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a * a, vector.lengthSqr());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, length) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(1.0);
|
||||
ASSERT_DOUBLE_EQ(sqrt(3.0), vector.length());
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(sqrt(SIZE * a * a), vector.length());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, manhattanLength) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(5.0);
|
||||
ASSERT_DOUBLE_EQ(15.0, vector.manhattanLength());
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a, 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));
|
||||
double a = 3.32;
|
||||
double angle = 0.78539816339744830961566084581988;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(cos(angle), 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));
|
||||
double a = 3.32;
|
||||
double angle = 0.78539816339744830961566084581988;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(sin(angle), 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));
|
||||
double a = 3.32;
|
||||
double angle = 0.78539816339744830961566084581988;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle, 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));
|
||||
double a = 3.32;
|
||||
double angle = 45.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle, 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;
|
||||
double a = 2.0;
|
||||
double b = 2.0;
|
||||
double res = sqrt(32.0);
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
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(PIMathVector_Test, normalize) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), 5.0 / sqrt(75.0), 3u));
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector.normalize(), a / sqrt(SIZE * a * a), SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, normalized) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector.fill(5.0);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector.normalized(), 5.0 / sqrt(75.0), 3u));
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vectorNew(SIZE);
|
||||
vector.fill(a);
|
||||
vectorNew = vector.normalized();
|
||||
ASSERT_TRUE(cmpVectorWithValue(vectorNew, a / sqrt(SIZE * a * a), SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isNullTrue) {
|
||||
PIMathVector<double> vector(3u);
|
||||
PIMathVector<double> vector(SIZE);
|
||||
ASSERT_TRUE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isNullFalse) {
|
||||
PIMathVector<double> vector(3u);
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector[0] = 6.273;
|
||||
ASSERT_FALSE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isValidTrue) {
|
||||
PIMathVector<double> vector(3u);
|
||||
PIMathVector<double> vector(SIZE);
|
||||
ASSERT_TRUE(vector.isValid());
|
||||
}
|
||||
|
||||
@@ -161,27 +198,35 @@ TEST(PIMathVector_Test, isValidFalse) {
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isOrthoTrue) {
|
||||
PIMathVector<double> vector(2u);
|
||||
PIMathVector<double> vect(2u);
|
||||
vector[0] = 2.0;
|
||||
vect[1] = 1.0;
|
||||
uint sizeNew = 2u;
|
||||
double a = 2.0;
|
||||
double b = 1.0;
|
||||
PIMathVector<double> vector(sizeNew);
|
||||
PIMathVector<double> vect(sizeNew);
|
||||
vector[0] = a;
|
||||
vect[1] = b;
|
||||
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;
|
||||
uint sizeNew = 2u;
|
||||
double a = 2.0;
|
||||
double b = 1.0;
|
||||
double c = 5.0;
|
||||
PIMathVector<double> vector(sizeNew);
|
||||
PIMathVector<double> vect(sizeNew);
|
||||
vector[0] = a;
|
||||
vect[0] = c;
|
||||
vect[1] = b;
|
||||
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){
|
||||
double a = 5.5;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
for(uint i = 0; i < SIZE; i++){
|
||||
if(vector.at(i) - a >= double(1E-200)){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -189,176 +234,212 @@ TEST(PIMathVector_Test, at) {
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_AssignmentValue) {
|
||||
PIMathVector<double> vector(3u);
|
||||
vector = 3.0;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 3.0, 3));
|
||||
double a = 5.5;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector = a;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_AssignmentVector) {
|
||||
PIMathVector<double> vector(3u);
|
||||
PIMathVector<double> vec(3u);
|
||||
vec = 5.0;
|
||||
double a = 5.5;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vec = a;
|
||||
vector = vec;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, 5.0, 3));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
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;
|
||||
double a = 5.12;
|
||||
double b = 7.34;
|
||||
uint newSize = 2u;
|
||||
PIMathVector<double> vector(newSize);
|
||||
PIMathVector<double> vec(newSize);
|
||||
vector[0] = a;
|
||||
vector[1] = b;
|
||||
vec[0] = a;
|
||||
vec[1] = b;
|
||||
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;
|
||||
double a = 5.12;
|
||||
double b = 7.34;
|
||||
double c = 7.332;
|
||||
uint newSize = 2u;
|
||||
PIMathVector<double> vector(newSize);
|
||||
PIMathVector<double> vec(newSize);
|
||||
vector[0] = a;
|
||||
vector[1] = b;
|
||||
vec[0] = a;
|
||||
vec[1] = c;
|
||||
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;
|
||||
double a = 5.12;
|
||||
double b = 7.34;
|
||||
double c = 7.332;
|
||||
uint newSize = 2u;
|
||||
PIMathVector<double> vector(newSize);
|
||||
PIMathVector<double> vec(newSize);
|
||||
vector[0] = a;
|
||||
vector[1] = b;
|
||||
vec[0] = a;
|
||||
vec[1] = c;
|
||||
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;
|
||||
double a = 5.12;
|
||||
double b = 7.34;
|
||||
uint newSize = 2u;
|
||||
PIMathVector<double> vector(newSize);
|
||||
PIMathVector<double> vec(newSize);
|
||||
vector[0] = a;
|
||||
vector[1] = b;
|
||||
vec[0] = a;
|
||||
vec[1] = b;
|
||||
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);
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 += vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 7.72, 3));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a + b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Subtraction_Assignment) {
|
||||
PIMathVector<double> vector1(3u);
|
||||
PIMathVector<double> vector2(3u);
|
||||
vector1.fill(6.0);
|
||||
vector2.fill(1.72);
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 -= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.28, 3));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a - b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) {
|
||||
PIMathVector<double> vector1(3u);
|
||||
vector1.fill(6.0);
|
||||
vector1 *= 4.0;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 24.0, 3));
|
||||
double a = 6.0;
|
||||
double b = 4.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
vector1.fill(a);
|
||||
vector1 *= b;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector) {
|
||||
PIMathVector<double> vector1(3u);
|
||||
PIMathVector<double> vector2(3u);
|
||||
vector1.fill(6.0);
|
||||
vector2.fill(1.72);
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 *= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 10.32, 3));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a * b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Division_AssignmentValue) {
|
||||
PIMathVector<double> vector1(3u);
|
||||
vector1.fill(6.0);
|
||||
vector1 /= 4.0;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 1.5, 3));
|
||||
double a = 6.0;
|
||||
double b = 4.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
vector1.fill(a);
|
||||
vector1 /= b;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Division_AssignmentVector) {
|
||||
PIMathVector<double> vector1(3u);
|
||||
PIMathVector<double> vector2(3u);
|
||||
vector1.fill(6.0);
|
||||
vector2.fill(1.5);
|
||||
double a = 6.0;
|
||||
double b = 1.5;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 /= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, 4.0, 3));
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a / b, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a + b, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a - b, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 6.0;
|
||||
double b = 4.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 * b, a * b, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue((vector1 * vector2), 0.0, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 1.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
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(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_DivisionValue) {
|
||||
double a = 6.0;
|
||||
double b = 4.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
vector1.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 / b, a / b, SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
double a = 6.0;
|
||||
double b = 5.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a * b, SIZE));
|
||||
}
|
||||
|
||||
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);
|
||||
TEST(PIMathVector_Test, operator_DotProduct) {
|
||||
double a = 6.0;
|
||||
double b = 5.0;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(SIZE * a * b == (vector1 ^ vector2));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user