pimathvector_tests #38
@@ -29,10 +29,10 @@
|
||||
#include "pimathcomplex.h"
|
||||
|
||||
/**
|
||||
* @brief Inline funtion of compare with zero different types
|
||||
* @brief Floating point number specific comparison between value of matrix passed as parameter and zero
|
||||
*
|
||||
* @param v is input parameter of type T
|
||||
* @return true if zero, false if not zero
|
||||
* @param v floating point parameter for comparison
|
||||
* @return true if v in locality of zero, otherwise false
|
||||
*/
|
||||
template<typename T>
|
||||
inline bool _PIMathMatrixNullCompare(const T v) {
|
||||
@@ -41,10 +41,10 @@ inline bool _PIMathMatrixNullCompare(const T v) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inline funtion of compare with zero colmplexf type
|
||||
* @brief Floating point number specific comparison between parameter value of matrix of complexf type and zero
|
||||
*
|
||||
* @param v is input parameter of type colmplexf
|
||||
* @return true if zero, false if not zero
|
||||
* @return true if absolute value of v in locality of zero, otherwise false
|
||||
*/
|
||||
template<>
|
||||
inline bool _PIMathMatrixNullCompare<complexf>(const complexf v) {
|
||||
@@ -52,10 +52,10 @@ inline bool _PIMathMatrixNullCompare<complexf>(const complexf v) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inline funtion of compare with zero complexd type
|
||||
* @brief Floating point number specific comparison between parameter value of matrix of complexd type and zero
|
||||
*
|
||||
* @param v is input parameter of type colmplexd
|
||||
* @return true if zero, false if not zero
|
||||
* @return true if absolute value of v in locality of zero, otherwise false
|
||||
*/
|
||||
template<>
|
||||
inline bool _PIMathMatrixNullCompare<complexd>(const complexd v) {
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
/**
|
||||
* @brief Constructor that calls the private resize method
|
||||
*
|
||||
* @return identitied matrix of type PIMathMatrixT
|
||||
* @return resized matrix of type PIMathMatrixT
|
||||
*/
|
||||
PIMathMatrixT() { resize(Rows, Cols); }
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
* @brief Constructor that calls the private resize method
|
||||
*
|
||||
* @param val is the PIVector with which the matrix is filled
|
||||
* @return identitied matrix of type PIMathMatrixT
|
||||
* @return resized matrix of type PIMathMatrixT
|
||||
*/
|
||||
PIMathMatrixT(const PIVector<Type> &val) {
|
||||
resize(Rows, Cols);
|
||||
@@ -120,10 +120,10 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a matrix that is filled with elements
|
||||
* @brief Creates a matrix and sets it with elements equal to value "v"
|
||||
*
|
||||
* @param v is a parameter the type and value of which is selected and later filled into the matrix
|
||||
* @return filled matrix of type PIMathMatrixT
|
||||
* @return filled matrix of type PIMathMatrixT equal to "v"
|
||||
*/
|
||||
static _CMatrix filled(const Type &v) {
|
||||
_CMatrix tm;
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param angle is the angle of rotation of the matrix along the X axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the X axis
|
||||
*/
|
||||
static _CMatrix rotationX(double angle) { return _CMatrix(); }
|
||||
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param angle is the angle of rotation of the matrix along the Y axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the Y axis
|
||||
*/
|
||||
static _CMatrix rotationY(double angle) { return _CMatrix(); }
|
||||
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param angle is the angle of rotation of the matrix along the Z axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the Z axis
|
||||
*/
|
||||
static _CMatrix rotationZ(double angle) { return _CMatrix(); }
|
||||
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param factor is the value of scaling by X axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the axis X
|
||||
*/
|
||||
static _CMatrix scaleX(double factor) { return _CMatrix(); }
|
||||
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param factor is the value of scaling by Y axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the axis Y
|
||||
*/
|
||||
static _CMatrix scaleY(double factor) { return _CMatrix(); }
|
||||
|
||||
@@ -190,26 +190,26 @@ public:
|
||||
* else return default construction of PIMathMatrixT
|
||||
*
|
||||
* @param factor is the value of scaling by Z axis
|
||||
* @return rotated matrix
|
||||
* @return rotated matrix along the axis Z
|
||||
*/
|
||||
static _CMatrix scaleZ(double factor) { return _CMatrix(); }
|
||||
|
||||
/**
|
||||
* @brief Method which returns number of columns in matrix
|
||||
* @brief Method which returns number of columns in this matrix
|
||||
*
|
||||
* @return type uint shows number of columns
|
||||
* @return number of columns
|
||||
*/
|
||||
uint cols() const { return Cols; }
|
||||
|
||||
/**
|
||||
* @brief Method which returns number of rows in matrix
|
||||
* @brief Method which returns number of rows in this matrix
|
||||
*
|
||||
* @return type uint shows number of rows
|
||||
* @return number of rows
|
||||
*/
|
||||
uint rows() const { return Rows; }
|
||||
|
||||
/**
|
||||
* @brief Method which returns the selected column in PIMathVectorT format.
|
||||
* @brief Method which returns the selected column of this matrix in PIMathVectorT format.
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the number of the selected column
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which returns the selected row in PIMathVectorT format
|
||||
* @brief Method which returns the selected row of this matrix in PIMathVectorT format.
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the number of the selected row
|
||||
@@ -235,12 +235,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the selected column in matrix.
|
||||
* @brief Set the selected column in this matrix.
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the number of the selected column
|
||||
* @param v is a vector of the type _CMCol that needs to fill the column
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &setCol(uint index, const _CMCol &v) {
|
||||
PIMM_FOR_R(i) m[i][index] = v[i];
|
||||
@@ -248,12 +248,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the selected row in matrix
|
||||
* @brief Set the selected row in this matrix
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the number of the selected row
|
||||
* @param v is a vector of the type _CMCol that needs to fill the row
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &setRow(uint index, const _CMRow &v) {
|
||||
PIMM_FOR_C(i) m[index][i] = v[i];
|
||||
@@ -261,12 +261,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which changes selected rows in a matrix.
|
||||
* @brief Method which permutes the values of two selected rows among themselves in this matrix.
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param r0 is the number of the first selected row
|
||||
* @param r1 is the number of the second selected row
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &swapRows(uint r0, uint r1) {
|
||||
Type t;
|
||||
@@ -279,12 +279,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which changes selected columns in a matrix.
|
||||
* @brief Method which permutes the values of two selected columns among themselves in this matrix.
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param c0 is the number of the first selected column
|
||||
* @param c1 is the number of the second selected column
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &swapCols(uint c0, uint c1) {
|
||||
Type t;
|
||||
@@ -297,10 +297,10 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which fills the matrix with selected value
|
||||
* @brief Method which set this matrix elements with selected value
|
||||
*
|
||||
* @param v is a parameter the type and value of which is selected and later filled into the matrix
|
||||
* @return filled matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &fill(const Type &v) {
|
||||
PIMM_FOR_WB(r, c) m[r][c] = v;
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which checks if matrix is square
|
||||
* @brief Method which checks if this matrix is square
|
||||
*
|
||||
* @return true if matrix is square, else false
|
||||
*/
|
||||
@@ -335,24 +335,14 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Full access to elements reference by row "row" and col "col".
|
||||
* @brief Read-only access to elements reference by row "row" and column "col".
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param row is a parameter that shows the row number of the matrix of the selected element
|
||||
* @param col is a parameter that shows the column number of the matrix of the selected element
|
||||
* @return reference to element of matrix by row "row" and col "col"
|
||||
* @return reference to element of this matrix
|
||||
*/
|
||||
Type &at(uint row, uint col) { return m[row][col]; }
|
||||
|
||||
/**
|
||||
* @brief Full access to element by row "row" and col "col".
|
||||
* If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
*
|
||||
* @param row is a parameter that shows the row number of the matrix of the selected element
|
||||
* @param col is a parameter that shows the column number of the matrix of the selected element
|
||||
* @return element of matrix by row "row" and col "col"
|
||||
*/
|
||||
Type at(uint row, uint col) const { return m[row][col]; }
|
||||
const Type &at(uint row, uint col) { return m[row][col]; }
|
||||
|
||||
/**
|
||||
* @brief Full access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior"
|
||||
@@ -371,10 +361,10 @@ public:
|
||||
const Type *operator[](uint row) const { return m[row]; }
|
||||
|
||||
/**
|
||||
* @brief Matrix assignment to matrix "sm"
|
||||
* @brief Assignment all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the assigment
|
||||
* @return matrix equal with sm
|
||||
* @param sm matrix used for the assignment
|
||||
* @return matrix whose each element is equal to each element of the matrix "sm"
|
||||
*/
|
||||
_CMatrix &operator=(const _CMatrix &sm) {
|
||||
memcpy(m, sm.m, sizeof(Type) * Cols * Rows);
|
||||
@@ -382,9 +372,9 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
* @brief Compare all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @param sm matrix used for the compare
|
||||
* @return if matrices are equal true, else false
|
||||
*/
|
||||
bool operator==(const _CMatrix &sm) const {
|
||||
@@ -393,36 +383,36 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
* @brief Compare all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @param sm matrix used for the compare
|
||||
* @return if matrices are not equal true, else false
|
||||
*/
|
||||
bool operator!=(const _CMatrix &sm) const { return !(*this == sm); }
|
||||
|
||||
/**
|
||||
* @brief Addition assignment with matrix "sm"
|
||||
* @brief Addition all elements of this matrix with all elements matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the addition assigment
|
||||
*/
|
||||
void operator+=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] += sm.m[r][c]; }
|
||||
|
||||
/**
|
||||
* @brief Subtraction assignment with matrix "sm"
|
||||
* @brief Subtraction all elements of this matrix with all elements matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the subtraction assigment
|
||||
*/
|
||||
void operator-=(const _CMatrix &sm) { PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c]; }
|
||||
|
||||
/**
|
||||
* @brief Multiplication assignment with value "v"
|
||||
* @brief Multiplication all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v value for the multiplication assigment
|
||||
*/
|
||||
void operator*=(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] *= v; }
|
||||
|
||||
/**
|
||||
* @brief Division assignment with value "v"
|
||||
* @brief Division all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v value for the division assigment
|
||||
*/
|
||||
@@ -440,7 +430,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix addition
|
||||
* @brief Addition all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm is matrix term
|
||||
* @return the result of matrix addition
|
||||
@@ -452,7 +442,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix substraction
|
||||
* @brief Substraction all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm is matrix subtractor
|
||||
* @return the result of matrix substraction
|
||||
@@ -464,7 +454,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix multiplication
|
||||
* @brief Multiplication all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v is value factor
|
||||
* @return the result of matrix multiplication
|
||||
@@ -476,7 +466,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix division
|
||||
* @brief Division all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v is value divider
|
||||
* @return the result of matrix division
|
||||
@@ -512,7 +502,7 @@ public:
|
||||
* @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix
|
||||
*
|
||||
* @param ok is a parameter with which we can find out if the method worked correctly
|
||||
* @return copy of transformed upper triangular matrix
|
||||
* @return reference to this of transformed upper triangular matrix
|
||||
*/
|
||||
_CMatrix &toUpperTriangular(bool *ok = 0) {
|
||||
if (Cols != Rows) {
|
||||
@@ -554,8 +544,7 @@ public:
|
||||
/**
|
||||
* @brief Matrix inversion operation. Works only with square matrix, nonzero matrices and invertible matrix
|
||||
*
|
||||
* @param ok is a parameter with which we can find out if the method worked correctly
|
||||
* @return copy of inverted matrix
|
||||
* @param ok is a parameter with which we can find out if the method worked correct * @return reference to this inverted matrix
|
||||
*/
|
||||
_CMatrix &invert(bool *ok = 0) {
|
||||
static_assert(Cols == Rows, "Only square matrix invertable");
|
||||
@@ -732,11 +721,11 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Rows, Co
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Add matrix "m" at the end of matrix and return reference to matrix
|
||||
* @brief Outputting the matrix to the console
|
||||
*
|
||||
* @param s PICout type
|
||||
* @param m PIMathMatrixT type
|
||||
* @return bitwise left PICout
|
||||
* @param the matrix type PIMathMatrixT that we print to the console
|
||||
* @return PIMathMatrix printed to the console
|
||||
*/
|
||||
template<uint Rows, uint Cols, typename Type>
|
||||
inline PICout operator<<(PICout s, const PIMathMatrixT<Rows, Cols, Type> &m) {
|
||||
@@ -941,12 +930,12 @@ public:
|
||||
static _CMatrix matrixCol(const PIMathVector<Type> &val) { return _CMatrix(1, val.size(), val.toVector()); }
|
||||
|
||||
/**
|
||||
* @brief Set the selected column in matrix. If there are more elements of the vector than elements in the column of the matrix
|
||||
* or index larger than the number of columns otherwise there will be "undefined behavior"
|
||||
* @brief Set the selected column in this matrix. If there are more elements of the vector than elements in the column of the matrix
|
||||
* or index larger than the number of columns otherwise there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the number of the selected column
|
||||
* @param v is a vector of the type _CMCol that needs to fill the column
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &setCol(uint index, const _CMCol &v) {
|
||||
PIMM_FOR_R(i) _V2D::element(i, index) = v[i];
|
||||
@@ -954,11 +943,11 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the selected row in matrix. If there are more elements of the vector than elements in the row of the matrix,
|
||||
* @brief Set the selected row in this matrix. If there are more elements of the vector than elements in the row of the matrix,
|
||||
* or index larger than the number of rows otherwise there will be "undefined behavior"
|
||||
* @param index is the number of the selected row
|
||||
* @param v is a vector of the type _CMCol that needs to fill the row
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &setRow(uint index, const _CMCol &v) {
|
||||
PIMM_FOR_C(i) _V2D::element(index, i) = v[i];
|
||||
@@ -966,12 +955,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which replace selected columns in a matrix. You cannot use an index larger than the number of columns,
|
||||
* @brief Method which permutes the values of two selected columns among themselves in this matrix. You cannot use an index larger than the number of columns,
|
||||
* otherwise there will be "undefined behavior"
|
||||
*
|
||||
* @param r0 is the number of the first selected row
|
||||
* @param r1 is the number of the second selected row
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &swapCols(uint r0, uint r1) {
|
||||
PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); }
|
||||
@@ -979,12 +968,12 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which replace selected rows in a matrix. You cannot use an index larger than the number of rows,
|
||||
* @briefMethod which permutes the values of two selected rows among themselves in this matrix. You cannot use an index larger than the number of rows,
|
||||
* otherwise there will be "undefined behavior"
|
||||
*
|
||||
* @param c0 is the number of the first selected row
|
||||
* @param c1 is the number of the second selected row
|
||||
* @return matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &swapRows(uint c0, uint c1) {
|
||||
PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); }
|
||||
@@ -992,10 +981,10 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Method which fills the matrix with selected value
|
||||
* @brief Method which set this matrix elements with selected value
|
||||
*
|
||||
* @param v is a parameter the type and value of which is selected and later filled into the matrix
|
||||
* @return filled matrix type _CMatrix
|
||||
* @return reference to this
|
||||
*/
|
||||
_CMatrix &fill(const Type &v) {
|
||||
PIMM_FOR_A(i) _V2D::mat[i] = v;
|
||||
@@ -1037,10 +1026,10 @@ public:
|
||||
bool isValid() const { return !PIVector2D<Type>::isEmpty(); }
|
||||
|
||||
/**
|
||||
* @brief Matrix assignment to matrix "v"
|
||||
* @brief Assignment all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param v matrix for the assigment
|
||||
* @return matrix equal with v
|
||||
* @param v matrix used for the assigment
|
||||
* @return reference to this matrix equal with v
|
||||
*/
|
||||
_CMatrix &operator=(const PIVector<PIVector<Type> > &v) {
|
||||
*this = _CMatrix(v);
|
||||
@@ -1048,9 +1037,9 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
* @brief Compare all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @param sm matrix used for the compare
|
||||
* @return if matrices are equal true, else false
|
||||
*/
|
||||
bool operator==(const _CMatrix &sm) const {
|
||||
@@ -1059,36 +1048,36 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare with matrix "sm"
|
||||
* @brief Compare all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the compare
|
||||
* @param sm matrix used for the compare
|
||||
* @return if matrices are not equal true, else false
|
||||
*/
|
||||
bool operator!=(const _CMatrix &sm) const { return !(*this == sm); }
|
||||
|
||||
/**
|
||||
* @brief Addition assignment with matrix "sm"
|
||||
* @brief Addition all elements of this matrix with all elements matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the addition assigment
|
||||
*/
|
||||
void operator+=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i]; }
|
||||
|
||||
/**
|
||||
* @brief Subtraction assignment with matrix "sm"
|
||||
* @brief Subtraction all elements of this matrix with all elements matrix "sm"
|
||||
*
|
||||
* @param sm matrix for the subtraction assigment
|
||||
*/
|
||||
void operator-=(const _CMatrix &sm) { PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i]; }
|
||||
|
||||
/**
|
||||
* @brief Multiplication assignment with value "v"
|
||||
* @brief Multiplication all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v value for the multiplication assigment
|
||||
*/
|
||||
void operator*=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] *= v; }
|
||||
|
||||
/**
|
||||
* @brief Division assignment with value "v"
|
||||
* @brief Division all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v value for the division assigment
|
||||
*/
|
||||
@@ -1106,7 +1095,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix addition
|
||||
* @brief Addition all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm is matrix term
|
||||
* @return the result of matrix addition
|
||||
@@ -1118,7 +1107,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix subtraction
|
||||
* @brief Substraction all elements of this matrix with all elements of matrix "sm"
|
||||
*
|
||||
* @param sm is matrix subtractor
|
||||
* @return the result of matrix subtraction
|
||||
@@ -1130,7 +1119,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix multiplication
|
||||
* @brief Multiplication all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v is value factor
|
||||
* @return the result of matrix multiplication
|
||||
@@ -1142,7 +1131,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix division
|
||||
* @brief Division all elements of this matrix with value "v"
|
||||
*
|
||||
* @param v is value divider
|
||||
* @return the result of matrix division
|
||||
@@ -1197,7 +1186,7 @@ public:
|
||||
* @brief Transforming matrix to upper triangular. Works only with square matrix, nonzero matrices and invertible matrix
|
||||
*
|
||||
* @param ok is a parameter with which we can find out if the method worked correctly
|
||||
* @return copy of transformed upper triangular matrix
|
||||
* @return this transformed upper triangular matrix
|
||||
*/
|
||||
_CMatrix &toUpperTriangular(bool *ok = 0) {
|
||||
if (!isSquare()) {
|
||||
@@ -1241,7 +1230,7 @@ public:
|
||||
*
|
||||
* @param ok is a parameter with which we can find out if the method worked correctly
|
||||
* @param sv is a vector multiplier
|
||||
* @return copy of inverted matrix
|
||||
* @return this inverted matrix
|
||||
*/
|
||||
_CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) {
|
||||
if (!isSquare()) {
|
||||
@@ -1329,7 +1318,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Inline operator for outputting the matrix to the console
|
||||
* @brief Outputting the matrix to the console
|
||||
*
|
||||
* @param s PICout type
|
||||
* @param the matrix type PIMathMatrix that we print to the console
|
||||
@@ -1350,7 +1339,7 @@ inline PICout operator<<(PICout s, const PIMathMatrix<Type> &m) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inline operator for serializing a matrix into a PIByteArray
|
||||
* @brief Serializing a matrix into a PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathMatrix type
|
||||
@@ -1363,7 +1352,7 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inline operator to deserialize matrix from PIByteArray
|
||||
* @brief Deserializing matrix from PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathMatrix type
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/*! \file pimathvector.h
|
||||
/*! \file pimathvector.h
|
||||
* \brief PIMathVector
|
||||
*
|
||||
* This file declare math vector class, which performs various vector operations
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
@@ -33,59 +35,358 @@ class PIMathMatrixT;
|
||||
|
||||
#define PIMV_FOR(v, s) for (uint v = s; v < Size; ++v)
|
||||
|
||||
//! \brief A class that works with vector operations, the input data of which are size and the data type of the vector
|
||||
//! @tparam Size number of matrix elements
|
||||
//! @tparam Type is the data type of the vector. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /)
|
||||
//! of the C++ language are implemented
|
||||
template<uint Size, typename Type = double>
|
||||
class PIP_EXPORT PIMathVectorT {
|
||||
typedef PIMathVectorT<Size, Type> _CVector;
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
static_assert(Size > 0, "Size count must be > 0");
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor that calls the private resize method
|
||||
*
|
||||
*/
|
||||
PIMathVectorT() {resize();}
|
||||
|
||||
/**
|
||||
* @brief Constructor that fills a vector PIMathVectorT with the values of another vector "PIVector"
|
||||
*
|
||||
* @param val vector of type PIVector which is identified PIMathVectorT
|
||||
*/
|
||||
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
|
||||
|
||||
/**
|
||||
* @brief Constructor that fills a vector PIMathVectorT with the subtraction of two vectors
|
||||
*
|
||||
* @param st vector of type PIMathVectorT
|
||||
* @param fn vector of type PIMathVectorT
|
||||
*/
|
||||
PIMathVectorT(const _CVector & st, const _CVector & fn) {resize(); set(st, fn);}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the number of elements contained in the vector
|
||||
*
|
||||
* @return type uint shows number of elements in this vector
|
||||
*/
|
||||
uint size() const {return Size;}
|
||||
|
||||
/**
|
||||
* @brief Method that set this elements to value "v"
|
||||
*
|
||||
* @param v value of which the vector is filled
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that set this with the subtraction of two vectors
|
||||
*
|
||||
* @param st vector of type PIMathVectorT
|
||||
* @param fn vector of type PIMathVectorT
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & set(const _CVector & st, const _CVector & fn) {PIMV_FOR(i, 0) c[i] = fn[i] - st[i]; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that sets this using a vector, each element of which is added to the value of "v"
|
||||
*
|
||||
* @param v value of which the vector is filled
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that sets this with a vector, each element of which is added to each element of the vector "v"
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns sum of the squares of all elements of the vector
|
||||
*
|
||||
* @return value equal to the sum of the squares of all elements of the vector
|
||||
*/
|
||||
Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a scalar physical value equal to the absolute value of vector
|
||||
*
|
||||
* @return value equal to length of a vector
|
||||
*/
|
||||
Type length() const {return sqrt(lengthSqr());}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the sum of the absolute values of all vector values
|
||||
*
|
||||
* @return value equal sum of the absolute values of all vector values
|
||||
*/
|
||||
Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the cos of the current vector and vector "v"
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return cos value of the angle between two vectors
|
||||
*/
|
||||
Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return sin value of the angle between two vector
|
||||
*/
|
||||
Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the angle between of the current vector and vector "v" in Rad
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return value of the angle between two vectors in Rad
|
||||
*/
|
||||
Type angleRad(const _CVector & v) const {return acos(angleCos(v));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the angle between of the current vector and vector "v" in Deg
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return value of the angle between two vectors in Deg
|
||||
*/
|
||||
Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the angle elevation between of the current vector and vector "v" in Deg
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return value of the angle elevation between two vectors in Deg
|
||||
*/
|
||||
Type angleElevation(const _CVector & v) const {_CVector z = v - *this; double c = z.angleCos(*this); return 90.0 - acos(c) * rad2deg;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v".
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return vector of type PIMathVectorT equal to the projection of the current vector onto the vector "v"
|
||||
*/
|
||||
_CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns this normalized vector (each element of a vector is divided by the absolute value of this vector)
|
||||
*
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs<Type>(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
|
||||
*
|
||||
* @return normalized vector of type PIMathVectorT
|
||||
*/
|
||||
_CVector normalized() {_CVector tv(*this); tv.normalize(); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a vector equal to vector product of current vector and vector "v". Works only with vectors which consists of 3 elements
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return vector equal to vector product of current vector and vector "v" type of PIMathVectorT
|
||||
*/
|
||||
_CVector cross(const _CVector & v) {return (*this) * v;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a value equal to absolute value of dot product of current vector and vector "v"
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return value equal to absolute value of dot product of current vector and vector "v"
|
||||
*/
|
||||
Type dot(const _CVector & v) const {return (*this) ^ v;}
|
||||
|
||||
/**
|
||||
* @brief Method which checks if every elements of vector are zeros
|
||||
*
|
||||
* @return true if vector is zero, else false
|
||||
*/
|
||||
bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;}
|
||||
|
||||
/**
|
||||
* @brief Method which checks if current vector is orthogonal to vector "v"
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return true if vectors are orthogonal, else fal */
|
||||
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
|
||||
|
||||
Type & at(uint index) {return c[index];}
|
||||
Type at(uint index) const {return c[index];}
|
||||
/**
|
||||
* @brief Read-only access to elements reference by index of the vector element "index"
|
||||
* If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is a parameter that shows the index number of the vector of the selected element
|
||||
* @return reference to element of vector by index
|
||||
*/
|
||||
const Type & at(uint index) {return c[index];}
|
||||
|
||||
/**
|
||||
* @brief Full access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the index of necessary element
|
||||
* @return element of vector
|
||||
*/
|
||||
Type & operator [](uint index) {return c[index];}
|
||||
Type operator [](uint index) const {return c[index];}
|
||||
|
||||
/**
|
||||
* @brief Read-only access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the index of necessary element
|
||||
* @return element of vector
|
||||
*/
|
||||
const Type & operator [](uint index) const {return c[index];}
|
||||
|
||||
/**
|
||||
* @brief Assignment all elements of this vector with all elements of vector "v"
|
||||
* If the vectors have different dimensions, it returns this without changing anything
|
||||
|
|
||||
*
|
||||
* @param v vector for the assigment
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & operator =(const _CVector & v) {memcpy(c, v.c, sizeof(Type) * Size); return *this;}
|
||||
|
||||
/**
|
||||
* @brief Assignment all elements of this vector with all elements of value "v"
|
||||
*
|
||||
* @param v value for the assigment
|
||||
* @return reference to this
|
||||
|
zzuummaa
commented
Нечего не понятно Нечего не понятно
|
||||
*/
|
||||
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Compare all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v vector for the compare
|
||||
* @return if vectors are equal true, else false
|
||||
*/
|
||||
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;}
|
||||
bool operator !=(const _CVector & v) const {return !(*this == c);}
|
||||
|
||||
/**
|
||||
* @brief Compare all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v vector for the compare
|
||||
* @return if vectors are not equal true, else false
|
||||
*/
|
||||
bool operator !=(const _CVector & v) const {return !(*this == v);}
|
||||
|
||||
/**
|
||||
* @brief Addition all elements of this vector with all elements vector "v"
|
||||
*
|
||||
* @param v vector for the addition assigment
|
||||
*/
|
||||
void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];}
|
||||
|
||||
/**
|
||||
* @brief Subtraction all elements of this vector with all elements vector "v"
|
||||
*
|
||||
* @param v vector for the subtraction assigment
|
||||
*/
|
||||
void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with value "v"
|
||||
*
|
||||
* @param v value for the multiplication assigment
|
||||
*/
|
||||
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with all elements vector "v"
|
||||
*
|
||||
* @param v vector for the multiplication assigment
|
||||
*/
|
||||
void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with value "v"
|
||||
*
|
||||
* @param v value for the division assigment
|
||||
*/
|
||||
void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with all elements vector "v"
|
||||
*
|
||||
* @param v vector for the division assigment
|
||||
*/
|
||||
void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Vector substraction this vector
|
||||
*
|
||||
* @return the result of vector substraction
|
||||
*/
|
||||
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Addition all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v is vector term
|
||||
* @return the result of vector addition
|
||||
*/
|
||||
_CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Substraction all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v is vector term
|
||||
* @return the result of vector substraction
|
||||
*/
|
||||
_CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with value "v"
|
||||
*
|
||||
* @param v is value factor
|
||||
* @return the result of vector multiplication
|
||||
*/
|
||||
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with value "v"
|
||||
*
|
||||
* @param v is value divider
|
||||
* @return the result of vector division
|
||||
*/
|
||||
_CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v is vector divider
|
||||
* @return the result of vector division
|
||||
*/
|
||||
_CVector operator /(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector
|
||||
*
|
||||
* @param v is vector for cross product
|
||||
* @return the result vector equal of cross product
|
||||
*/
|
||||
_CVector operator *(const _CVector & v) const {if (Size != 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Elementwise assignment of multiplication of two vectors
|
||||
*
|
||||
* @param v is vector for multiplication
|
||||
* @return resulting vector
|
||||
*/
|
||||
_CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Absolute value of the dot product
|
||||
*
|
||||
* @param v is vector for dot product
|
||||
* @return resulting vector
|
||||
*/
|
||||
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
|
||||
|
||||
PIMathMatrixT<1, Size, Type> transposed() const {
|
||||
@@ -94,14 +395,20 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
|
||||
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
|
||||
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
|
||||
return f;}
|
||||
|
||||
/**
|
||||
* @brief The method returns a part of the selected vector from the given vector
|
||||
*
|
||||
* @return the resulting vector that is part of this vector
|
||||
*/
|
||||
template<uint Size1, typename Type1> /// vector {Size, Type} to vector {Size1, Type1}
|
||||
PIMathVectorT<Size1, Type1> turnTo() const {PIMathVectorT<Size1, Type1> tv; uint sz = piMin<uint>(Size, Size1); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Creates a vector each element of which is equal to value "v"
|
||||
*
|
||||
* @param v this value fills the cells of the vector
|
||||
* @return filled vector of type PIMathVectorT
|
||||
*/
|
||||
static _CVector filled(const Type & v) {_CVector vv; PIMV_FOR(i, 0) vv[i] = v; return vv;}
|
||||
|
||||
private:
|
||||
@@ -111,29 +418,106 @@ private:
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Multiplication all vector elements with value "x"
|
||||
*
|
||||
* @param x value for the multiplication
|
||||
* @param v vector for the multiplication
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PIMathVectorT<Size, Type> operator *(const Type & x, const PIMathVectorT<Size, Type> & v) {
|
||||
return v * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Outputting the vector to the console
|
||||
*
|
||||
* @param s PICout type
|
||||
* @param the vector type PIMathVectorT that we print to the console
|
||||
* @return PIMathVectorT printed to the console
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PICout operator <<(PICout s, const PIMathVectorT<Size, Type> & v) {s << "{"; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << "}"; return s;}
|
||||
|
||||
/**
|
||||
* @brief Checking if the cross product of two vectors is zero. Works only with vector containing three elements, otherwise returns current vector
|
||||
*
|
||||
* @param f vector of the first operand
|
||||
* @param s vector of the second operand
|
||||
* @return true if the cross product is zero, else false
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline bool operator ||(const PIMathVectorT<Size, Type> & f, const PIMathVectorT<Size, Type> & s) {return (f * s).isNull();}
|
||||
|
||||
/**
|
||||
* @brief The square root of every element in the vector
|
||||
*
|
||||
* @param v vector of whose elements the square root is taken
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PIMathVectorT<Size, Type> sqrt(const PIMathVectorT<Size, Type> & v) {PIMathVectorT<Size, Type> ret; PIMV_FOR(i, 0) {ret[i] = sqrt(v[i]);} return ret;}
|
||||
|
||||
/**
|
||||
* @brief Squares every element of the vector
|
||||
*
|
||||
* @param v vector whose elements are squared
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PIMathVectorT<Size, Type> sqr(const PIMathVectorT<Size, Type> & v) {PIMathVectorT<Size, Type> ret; PIMV_FOR(i, 0) {ret[i] = sqr(v[i]);} return ret;}
|
||||
|
||||
/**
|
||||
* @brief Serializing a vector into a PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathVectorT type
|
||||
* @return PIBiteArray serialized PIMathVectorT
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s << v[i]; return s;}
|
||||
|
||||
/**
|
||||
* @brief Deserializing vector from PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathVector type
|
||||
* @return PIMathVector deserialized from PIByteArray
|
||||
*/
|
||||
template<uint Size, typename Type>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;}
|
||||
|
||||
/**
|
||||
* @brief Function which returns vector size 2 and type of T
|
||||
*
|
||||
* @param x first element of vector
|
||||
* @param y second element of vector
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<typename T>
|
||||
inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector<T>() << x << y);}
|
||||
|
||||
/**
|
||||
* @brief Function which returns vector size 3 and type of T
|
||||
*
|
||||
* @param x first element of vector
|
||||
* @param y second element of vector
|
||||
* @param z third element of vector
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<typename T>
|
||||
inline PIMathVectorT<3u, T> createVectorT3(T x, T y, T z) {return PIMathVectorT<3u, T>(PIVector<T>() << x << y << z);}
|
||||
|
||||
/**
|
||||
* @brief Function which returns vector size 4 and type of T
|
||||
*
|
||||
* @param x first element of vector
|
||||
* @param y second element of vector
|
||||
* @param z third element of vector
|
||||
* @param w fouth element of vector
|
||||
* @return resulting vector
|
||||
*/
|
||||
template<typename T>
|
||||
inline PIMathVectorT<4u, T> createVectorT4(T x, T y, T z, T w) {return PIMathVectorT<4u, T>(PIVector<T>() << x << y << z << w);}
|
||||
|
||||
@@ -159,72 +543,381 @@ typedef PIMathVectorT<4u, double> PIMathVectorT4d;
|
||||
|
||||
#define PIMV_FOR(v, s) for (uint v = s; v < c.size(); ++v)
|
||||
|
||||
//! \brief A class that works with vector operations, the input data of which is the data type of the vector
|
||||
//! @tparam Type is the data type of the vector. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /)
|
||||
//! of the C++ language are implemented
|
||||
template<typename Type>
|
||||
class PIP_EXPORT PIMathVector {
|
||||
typedef PIMathVector<Type> _CVector;
|
||||
template<typename TypeOp> friend PIByteArray & operator <<(PIByteArray & s, const PIMathVector<TypeOp> & v);
|
||||
template<typename TypeOp> friend PIByteArray & operator >>(PIByteArray & s, PIMathVector<TypeOp> & v);
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor that calls the resize method
|
||||
*
|
||||
* @param size vector dimension
|
||||
*/
|
||||
PIMathVector(const uint size = 0) {c.resize(size);}
|
||||
|
||||
/**
|
||||
* @brief Constructor that fills a vector PIMathVector with the values of another vector "PIVector"
|
||||
*
|
||||
* @param val vector of type PIVector which is identified PIMathVector
|
||||
*/
|
||||
PIMathVector(const PIVector<Type> & val) {c.resize(val.size()); PIMV_FOR(i, 0) c[i] = val[i];}
|
||||
|
||||
/**
|
||||
* @brief Constructor that fills a vector PIMathVector with the subtraction of two vectors
|
||||
*
|
||||
* @param st vector of type PIMathVector
|
||||
* @param fn vector of type PIMathVector
|
||||
*/
|
||||
PIMathVector(const _CVector & st, const _CVector & fn) {c.resize(st.size()); PIMV_FOR(i, 0) c[i] = fn[i] - st[i];}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the number of elements contained in the vector
|
||||
*
|
||||
* @return type uint shows number of elements in this vector
|
||||
*/
|
||||
uint size() const {return c.size();}
|
||||
|
||||
/**
|
||||
* @brief Returns self resized vector
|
||||
*
|
||||
* @param size new vector dimension
|
||||
* @param new_value value with which the vector is filled
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & resize(uint size, const Type & new_value = Type()) {c.resize(size, new_value); return *this;}
|
||||
|
||||
/**
|
||||
* @brief Returns copy of resized vector
|
||||
*
|
||||
* @param size new vector dimension
|
||||
* @param new_value value with which the vector is filled
|
||||
* @return resized vector
|
||||
*/
|
||||
_CVector resized(uint size, const Type & new_value = Type()) {_CVector tv = _CVector(*this); tv.resize(size, new_value); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method that set this elements to value "v"
|
||||
*
|
||||
* @param v value of which the vector is filled
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & fill(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that sets this using a vector, each element of which is added to the value of "v"
|
||||
*
|
||||
* @param v value of which the vector is filled
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & move(const Type & v) {PIMV_FOR(i, 0) c[i] += v; return *this;}
|
||||
_CVector & move(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that sets this with a vector, each element of which is added to each element of the vector "v".
|
||||
* If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & move(const _CVector & v) {if(v.size() != c.size()) return *this; PIMV_FOR(i, 0) c[i] += v[i]; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that replaces two elements in this vector by indices. You cannot use an index larger than the number vector dimension,
|
||||
|
zzuummaa
commented
Ничего не понятно. Ничего не понятно.
|
||||
* otherwise there will be "undefined behavior"
|
||||
*
|
||||
* @param fe index of the first element
|
||||
* @param se index of the second element
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & swap(uint fe, uint se) {piSwap<Type>(c[fe], c[se]); return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns sum of the squares of all elements of the vector
|
||||
*
|
||||
* @return value equal to the sum of the squares of all elements of the vector
|
||||
*/
|
||||
|
zzuummaa
commented
Ничего не понятно по документации. Ничего не понятно по документации.
В документации не отражен случай когда размерности векторов не равны.
В коде не учитен случай, когда размерности векторов не равны.
|
||||
Type lengthSqr() const {Type tv(0); PIMV_FOR(i, 0) tv += (c[i] * c[i]); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a scalar physical value equal to the absolute value of vector
|
||||
*
|
||||
* @return value equal to length of a vector
|
||||
*/
|
||||
Type length() const {return sqrt(lengthSqr());}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the sum of the absolute values of all vector values
|
||||
*
|
||||
* @return value equal sum of the absolute values of all vector values
|
||||
*/
|
||||
Type manhattanLength() const {Type tv(0); PIMV_FOR(i, 0) tv += fabs(c[i]); return tv;}
|
||||
Type angleCos(const _CVector & v) const {Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);}
|
||||
Type angleSin(const _CVector & v) const {Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);}
|
||||
Type angleRad(const _CVector & v) const {return acos(angleCos(v));}
|
||||
Type angleDeg(const _CVector & v) const {return toDeg(acos(angleCos(v)));}
|
||||
_CVector projection(const _CVector & v) {Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the cos of the current vector and vector "v". If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v vector of type PIMathVector
|
||||
* @return cos value of the angle between two vectors
|
||||
*/
|
||||
Type angleCos(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = v.length() * length(); return (tv == Type(0) ? Type(0) : ((*this) ^ v) / tv);}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the sin of the current vector and vector "v". Works only with vectors which consists of 3 elements.
|
||||
* If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v vector of type PIMathVector
|
||||
* @return sin value of the angle between two vector
|
||||
*/
|
||||
Type angleSin(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv = angleCos(v); return sqrt(Type(1) - tv * tv);}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the angle between of the current vector and vector "v" in Rad.
|
||||
* If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v vector of type PIMathVector
|
||||
* @return value of the angle between two vectors in Rad
|
||||
*/
|
||||
Type angleRad(const _CVector & v) const {if(v.size() != c.size()) return false; return acos(angleCos(v));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns the angle between of the current vector and vector "v" in Deg.
|
||||
* If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v vector of type PIMathVectorT
|
||||
* @return value of the angle between two vectors in Deg
|
||||
*/
|
||||
Type angleDeg(const _CVector & v) const {if(v.size() != c.size()) return false; return toDeg(acos(angleCos(v)));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a vector equal to the projection of the current vector onto the vector "v".
|
||||
* If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v vector of type PIMathVector
|
||||
* @return vector of type PIMathVector equal to the projection of the current vector onto the vector "v"
|
||||
*/
|
||||
_CVector projection(const _CVector & v) {if(v.size() != c.size()) return *this; Type tv = v.length(); return (tv == Type(0) ? _CVector() : v * (((*this) ^ v) / tv));}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
|
||||
*
|
||||
* @return copy of normalized vector of type PIMathVector
|
||||
*/
|
||||
_CVector & normalize() {Type tv = length(); if (tv == Type(1)) return *this; if (piAbs<Type>(tv) <= Type(1E-100)) {fill(Type(0)); return *this;} PIMV_FOR(i, 0) c[i] /= tv; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Method that returns a normalized vector (each element of a vector is divided by the absolute value of this vector)
|
||||
*
|
||||
* @return normalized vector of type PIMathVector
|
||||
*/
|
||||
_CVector normalized() {_CVector tv(*this); tv.normalize(); return tv;}
|
||||
|
||||
/**
|
||||
* @brief Method which checks if every elements of vector are zeros
|
||||
*
|
||||
* @return true if vector is zero, else false
|
||||
*/
|
||||
bool isNull() const {PIMV_FOR(i, 0) if (c[i] != Type(0)) return false; return true;}
|
||||
|
||||
/**
|
||||
* @brief Method which checks if vector is empty
|
||||
*
|
||||
* @return true if vector is valid, else false
|
||||
*/
|
||||
bool isValid() const {return !c.isEmpty();}
|
||||
|
||||
bool isOrtho(const _CVector & v) const {return ((*this) ^ v) == Type(0);}
|
||||
/**
|
||||
* @brief Method which checks if current vector is orthogonal to vector "v".
|
||||
* If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v vector of type PIMathVector
|
||||
* @return true if vectors are orthogonal, else false
|
||||
*/
|
||||
bool isOrtho(const _CVector & v) const {if(v.size() != c.size()) return false; return ((*this) ^ v) == Type(0);}
|
||||
|
||||
Type & at(uint index) {return c[index];}
|
||||
Type at(uint index) const {return c[index];}
|
||||
/**
|
||||
* @brief Read-only access to elements reference by index of the vector element "index"
|
||||
* If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is a parameter that shows the index number of the vector of the selected element
|
||||
* @return reference to element of vector by index
|
||||
*/
|
||||
const Type & at(uint index) {return c[index];}
|
||||
|
||||
/**
|
||||
* @brief Full access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the index of necessary element
|
||||
* @return element of vector
|
||||
*/
|
||||
Type & operator [](uint index) {return c[index];}
|
||||
Type operator [](uint index) const {return c[index];}
|
||||
_CVector & operator =(const _CVector & v) {c = v.c; return *this;}
|
||||
|
||||
/**
|
||||
* @brief Read-only access to the element of vector by index. If you enter an index out of the border of the vector there will be "undefined behavior"
|
||||
*
|
||||
* @param index is the index of necessary element
|
||||
* @return element of vector
|
||||
*/
|
||||
const Type & operator [](uint index) const {return c[index];}
|
||||
|
||||
/**
|
||||
* @brief Assignment all elements of this vector with all elements of vector "v"
|
||||
* If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v vector for the assigment
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & operator =(const _CVector & v) {if(v.size() != c.size()) return *this; c = v.c; return *this;}
|
||||
|
||||
/**
|
||||
|
andrey
commented
здесь бь надо поменять на const Type & здесь бь надо поменять на const Type &
|
||||
* @brief Assignment all elements of this vector with all elements of value "v"
|
||||
*
|
||||
* @param v value for the assigment
|
||||
* @return reference to this
|
||||
*/
|
||||
_CVector & operator =(const Type & v) {PIMV_FOR(i, 0) c[i] = v; return *this;}
|
||||
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if (c[i] != v[i]) return false; return true;}
|
||||
bool operator !=(const _CVector & v) const {return !(*this == c);}
|
||||
void operator +=(const _CVector & v) {PIMV_FOR(i, 0) c[i] += v[i];}
|
||||
void operator -=(const _CVector & v) {PIMV_FOR(i, 0) c[i] -= v[i];}
|
||||
|
||||
/**
|
||||
|
zzuummaa
commented
Ничего не понятно в документации. Ничего не понятно в документации.
Не описан случай несовпадения размерностей.
Нет проверки размерностей в коде
|
||||
* @brief Compare all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v vector for the compare
|
||||
* @return if vectors are equal true, else false
|
||||
*/
|
||||
bool operator ==(const _CVector & v) const {PIMV_FOR(i, 0) if ((c[i] != v[i]) || (v.size() != c.size())) return false; return true;}
|
||||
|
||||
/**
|
||||
* @brief Compare all elements of this vector with all elements of vector "v"
|
||||
*
|
||||
* @param v vector for the compare
|
||||
* @return if vectors are not equal true, else false
|
||||
*/
|
||||
bool operator !=(const _CVector & v) const {return !(*this == v);}
|
||||
|
||||
/**
|
||||
|
andrey
commented
здесь необходимо дописать проверку размеров здесь необходимо дописать проверку размеров
andrey
commented
кстати тут гораздо проще, можно написать вместо всего кстати тут гораздо проще, можно написать вместо всего `return c == v.c;`
|
||||
* @brief Addition all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
|
||||
*
|
||||
* @param v vector for the addition assigment
|
||||
*/
|
||||
void operator +=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] += v[i];}
|
||||
|
||||
/**
|
||||
* @brief Subtraction all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
|
||||
*
|
||||
* @param v vector for the subtraction assigment
|
||||
*/
|
||||
void operator -=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] -= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with value "v"
|
||||
|
zzuummaa
commented
Ничего не понятно в документации. Аналогично: и т.д. Ничего не понятно в документации.
В документации не описан случай несовпадения размерностей.
Код не обрабатывает случай несовпадения размерностей.
Аналогично:
[pimathvector.h#L819](https://git.shs.tools/SHS/pip/src/commit/b7f035178f62ca6f3d7042cc39ebc9711904f6ac/libs/main/math/pimathvector.h#L819)
[pimathvector.h#L833](https://git.shs.tools/SHS/pip/src/commit/b7f035178f62ca6f3d7042cc39ebc9711904f6ac/libs/main/math/pimathvector.h#L833)
[pimathvector.h#L847](https://git.shs.tools/SHS/pip/src/commit/b7f035178f62ca6f3d7042cc39ebc9711904f6ac/libs/main/math/pimathvector.h#L847)
[pimathvector.h#L862](https://git.shs.tools/SHS/pip/src/commit/b7f035178f62ca6f3d7042cc39ebc9711904f6ac/libs/main/math/pimathvector.h#L862)
[pimathvector.h#L869](https://git.shs.tools/SHS/pip/src/commit/b7f035178f62ca6f3d7042cc39ebc9711904f6ac/libs/main/math/pimathvector.h#L869)
и т.д.
|
||||
*
|
||||
* @param v value for the multiplication assigment
|
||||
*/
|
||||
void operator *=(const Type & v) {PIMV_FOR(i, 0) c[i] *= v;}
|
||||
void operator *=(const _CVector & v) {PIMV_FOR(i, 0) c[i] *= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
|
||||
*
|
||||
* @param v vector for the multiplication assigment
|
||||
*/
|
||||
void operator *=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] *= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with value "v"
|
||||
*
|
||||
* @param v value for the division assigment
|
||||
*/
|
||||
void operator /=(const Type & v) {PIMV_FOR(i, 0) c[i] /= v;}
|
||||
void operator /=(const _CVector & v) {PIMV_FOR(i, 0) c[i] /= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with all elements vector "v". If the vectors have different dimensions, it returns void()
|
||||
*
|
||||
* @param v vector for the division assigment
|
||||
*/
|
||||
void operator /=(const _CVector & v) {if(v.size() != c.size()) return void(); PIMV_FOR(i, 0) c[i] /= v[i];}
|
||||
|
||||
/**
|
||||
* @brief Vector substraction this vector
|
||||
*
|
||||
* @return the result of vector substraction
|
||||
*/
|
||||
_CVector operator -() const {_CVector tv; PIMV_FOR(i, 0) tv[i] = -c[i]; return tv;}
|
||||
_CVector operator +(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
|
||||
_CVector operator -(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Addition all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v is vector term
|
||||
* @return the result of vector addition
|
||||
*/
|
||||
_CVector operator +(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] += v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Substraction all elements of this vector with all elements of vector "v". If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v is vector term
|
||||
* @return the result of vector substraction
|
||||
*/
|
||||
_CVector operator -(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] -= v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Multiplication all elements of this vector with value "v"
|
||||
*
|
||||
* @param v is value factor
|
||||
* @return the result of vector multiplication
|
||||
*/
|
||||
_CVector operator *(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Division all elements of this vector with value "v"
|
||||
*
|
||||
* @param v is value divider
|
||||
* @return the result of vector division
|
||||
*/
|
||||
_CVector operator /(const Type & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] /= v; return tv;}
|
||||
_CVector operator *(const _CVector & v) const {if (c.size() < 3) return _CVector(); _CVector tv; tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;}
|
||||
_CVector operator &(const _CVector & v) const {_CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
|
||||
Type operator ^(const _CVector & v) const {Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
|
||||
|
||||
Type distToLine(const _CVector & lp0, const _CVector & lp1) {
|
||||
_CVector a(lp0, lp1), b(lp0, *this), c(lp1, *this);
|
||||
Type f = fabs(a[0]*b[1] - a[1]*b[0]) / a.length();
|
||||
return f;
|
||||
}
|
||||
/**
|
||||
* @brief Cross product of two vectors. Works only with vector containing three elements, otherwise returns current vector
|
||||
*
|
||||
* @param v is vector for cross product
|
||||
* @return the result vector equal of cross product
|
||||
*/
|
||||
_CVector operator *(const _CVector & v) const {if ((c.size() != 3) || (v.size() != 3)) return _CVector(); _CVector tv(3); tv.fill(Type(1)); tv[0] = c[1]*v[2] - v[1]*c[2]; tv[1] = v[0]*c[2] - c[0]*v[2]; tv[2] = c[0]*v[1] - v[0]*c[1]; return tv;}
|
||||
|
||||
template<typename Type1>
|
||||
PIMathVector turnTo(uint size) const {PIMathVector<Type1> tv; uint sz = piMin<uint>(c.size(), size); for (uint i = 0; i < sz; ++i) tv[i] = c[i]; return tv;}
|
||||
/**
|
||||
* @brief Elementwise assignment of multiplication of two vectors. If the vectors have different dimensions, it returns this without changing anything
|
||||
*
|
||||
* @param v is vector for multiplication
|
||||
* @return resulting vector
|
||||
*/
|
||||
_CVector operator &(const _CVector & v) const {if(v.size() != c.size()) return _CVector(*this); _CVector tv = _CVector(*this); PIMV_FOR(i, 0) tv[i] *= v[i]; return tv;}
|
||||
|
||||
|
andrey
commented
в условии должно быть || а не && в условии должно быть || а не &&
странно что тесты этого не показали (наверное тесты не охватывают все случаи)
|
||||
/**
|
||||
* @brief Value of the dot product. If the vectors have different dimensions, it returns false
|
||||
*
|
||||
* @param v is vector for dot product
|
||||
* @return resulting value
|
||||
*/
|
||||
Type operator ^(const _CVector & v) const {if(v.size() != c.size()) return false; Type tv(0); PIMV_FOR(i, 0) tv += c[i] * v[i]; return tv;}
|
||||
|
||||
/**
|
||||
* @brief Converts PIMathVector to PIVector type
|
||||
*
|
||||
* @return vector equal PIMathVector but in PIVector type
|
||||
*/
|
||||
PIVector<Type> toVector() const {return c;}
|
||||
|
||||
/**
|
||||
|
zzuummaa
commented
Документация не соответствует коду: вычисляется скалярное произведение а не его модуль. Документация не соответствует коду: вычисляется скалярное произведение а не его модуль.
Не описан случай несовпадения разменостей.
Код не учитывает случай несовпадения размерностей.
|
||||
* @brief Returns full access data of vector
|
||||
*
|
||||
* @return data of vector
|
||||
*/
|
||||
inline Type * data() {return c.data();}
|
||||
|
||||
/**
|
||||
* @brief Returns read-only data of vector
|
||||
*
|
||||
|
zzuummaa
commented
Документация не соответствует коду. Метод вычисляет расстояние от точки до прямой, задаваемой Документация не соответствует коду. Метод вычисляет расстояние от точки до прямой, задаваемой `lp0` и `lp1`
Описать параметры и возвращаемое значение подробнее.
|
||||
* @return data of vector
|
||||
*/
|
||||
inline const Type * data() const {return c.data();}
|
||||
|
||||
private:
|
||||
@@ -239,11 +932,33 @@ template<typename Type>
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIMathVector<Type> & v) {s << "{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Outputting the vector to the console
|
||||
*
|
||||
* @param s PICout type
|
||||
* @param the vector type PIMathVector that we print to the console
|
||||
* @return PIMathVector printed to the console
|
||||
*/
|
||||
template<typename Type>
|
||||
inline PICout operator <<(PICout s, const PIMathVector<Type> & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;}
|
||||
|
||||
/**
|
||||
* @brief Serializing a vector into a PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathVector type
|
||||
* @return PIBiteArray serialized PIMathVector
|
||||
*/
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector<Type> & v) {s << v.c; return s;}
|
||||
|
||||
/**
|
||||
* @brief Deserializing vector from PIByteArray
|
||||
*
|
||||
* @param s PIByteArray type
|
||||
* @param v PIMathVector type
|
||||
* @return PIMathVector deserialized from PIByteArray
|
||||
*/
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIMathVector<Type> & v) {s >> v.c; return s;}
|
||||
|
||||
|
||||
@@ -17,4 +17,3 @@ endmacro()
|
||||
# Concurrent tests
|
||||
pip_test(concurrent "")
|
||||
pip_test(math "")
|
||||
pip_test(core "")
|
||||
|
||||
@@ -1,2978 +0,0 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pistring.h"
|
||||
#include "pistringlist.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar){
|
||||
PIString str1 = "AB C";
|
||||
const PIChar str2 = " ";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB C ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar_zero1){
|
||||
PIString str1 = "";
|
||||
const PIChar str2 = "D";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "D");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar_zero2){
|
||||
PIString str1 = "AB C";
|
||||
const PIChar str2 = "";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB C");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar_zero_zero){
|
||||
PIString str1;
|
||||
const PIChar str2;
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_char){
|
||||
PIString str1 = "AB C";
|
||||
const char *str2 = "D D ";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB CD D ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_char_zero1){
|
||||
PIString str1 = "";
|
||||
const char *str2 = "D D ";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "D D ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_wchar){
|
||||
PIString str1= "AB C";
|
||||
wchar_t str2[] = L"C";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB CC");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_wchar_zero1){
|
||||
PIString str1 = "";
|
||||
wchar_t str2[] = L"C";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "C");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pistring){
|
||||
PIString str1 = "AB C";
|
||||
PIString str2 = " CD ";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB C CD ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pistring_zero1){
|
||||
PIString str1 = "";
|
||||
PIString str2 = "D DD";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "D DD");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pistring_zero2){
|
||||
PIString str1 = "AB C";
|
||||
PIString str2 = "";
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB C");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pistring_zero_zero){
|
||||
PIString str1;
|
||||
PIString str2;
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_piByteArray){
|
||||
PIString str1 = "AB C";
|
||||
PIByteArray str2;
|
||||
str2.append('g');
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB Cg");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_piByteArray_zero1){
|
||||
PIString str1 = "";
|
||||
PIByteArray str2;
|
||||
str2.append('0');
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "0");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_piByteArray_zero2){
|
||||
PIString str1 = "AB C";
|
||||
PIByteArray str2;
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "AB C");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_piByteArray_zero_zero){
|
||||
PIString str1;
|
||||
PIByteArray str2;
|
||||
str1 += str2;
|
||||
ASSERT_STREQ(str1, "");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_pistring){
|
||||
PIString str1 = "New";
|
||||
ASSERT_STREQ(str1, PIString("New"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_pichar){
|
||||
PIChar str1 = 'n';
|
||||
ASSERT_STREQ("n", PIString(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_char){
|
||||
char str1 = 'n';
|
||||
ASSERT_STREQ("n", PIString(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_chars){
|
||||
char str1[] = "mew";
|
||||
ASSERT_STREQ("mew", PIString(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_wchar_t){
|
||||
wchar_t str1[] = L"gav";
|
||||
ASSERT_STREQ("gav", PIString(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_pibyte_array){
|
||||
PIByteArray str1;
|
||||
str1.append('m');
|
||||
ASSERT_STREQ("m", PIString(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_pichar_size){
|
||||
PIChar *str1 = new PIChar[3];
|
||||
str1[0] = 'n';
|
||||
str1[1] = 'e';
|
||||
str1[2] = 'w';
|
||||
ASSERT_STREQ("new", PIString(str1, 3));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_char_size){
|
||||
char str1[] = "good";
|
||||
ASSERT_STREQ("good", PIString(str1, 4));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_char_len){
|
||||
char str1 = 'n';
|
||||
ASSERT_STREQ("nnn", PIString(3, str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, construct_pichar_len){
|
||||
PIChar str1 = 'n';
|
||||
ASSERT_STREQ("nnnnn", PIString(5, str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_pointer){
|
||||
PIString str1 = "testing";
|
||||
const char *point = str1.operator const char *();
|
||||
ASSERT_STREQ("testing", point);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_symbol){
|
||||
PIString str1 = "testing";
|
||||
PIChar symbo = "i";
|
||||
ASSERT_EQ(symbo, str1[4]);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_pistring_true){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_pistring_false){
|
||||
PIString str1 = "tes";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_FALSE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_pichar_true){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_TRUE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_pichar_false){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "p";
|
||||
ASSERT_FALSE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_char_true){
|
||||
PIString str1 = "test";
|
||||
char str2[] = "test";
|
||||
ASSERT_TRUE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_compare_char_false){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "test";
|
||||
ASSERT_FALSE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_pistring_false){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_FALSE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_pistring_true){
|
||||
PIString str1 = "tes";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_pichar_false){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_FALSE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_pichar_true){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "p";
|
||||
ASSERT_TRUE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_char_false){
|
||||
PIString str1 = "test";
|
||||
char str2[] = "test";
|
||||
ASSERT_FALSE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_encompare_char_true){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "test";
|
||||
ASSERT_TRUE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pistring_true){
|
||||
PIString str1 = "testin";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pistring_false){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testin";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pistring_false_equal){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_true){
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_TRUE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_false){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_false_equal){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_char_true){
|
||||
PIString str1 = "a";
|
||||
char str2[] = "t";
|
||||
ASSERT_TRUE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_char_false){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "a";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_char_false_equal){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "t";
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pistring_true){
|
||||
PIString str1 = "testin";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str2 > str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pistring_false){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testin";
|
||||
ASSERT_FALSE(str2 > str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pistring_false_equal){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pichar_true){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
ASSERT_TRUE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pichar_false){
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_pichar_false_equal){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_char_true){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "a";
|
||||
ASSERT_TRUE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_char_false){
|
||||
PIString str1 = "a";
|
||||
char str2[] = "t";
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_char_false_equal){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "t";
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pistring_true){
|
||||
PIString str1 = "testin";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pistring_false){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testin";
|
||||
ASSERT_FALSE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pistring_true_equal){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_true){
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_false){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
ASSERT_FALSE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_true_equal){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_char_true){
|
||||
PIString str1 = "a";
|
||||
char str2[] = "t";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_char_false){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "a";
|
||||
ASSERT_FALSE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_char_true_equal){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "t";
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pistring_true){
|
||||
PIString str1 = "testin";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str2 >= str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pistring_false){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testin";
|
||||
ASSERT_FALSE(str2 >= str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pistring_true_equal){
|
||||
PIString str1 = "testing";
|
||||
PIString str2 = "testing";
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pichar_true){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pichar_false){
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_FALSE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_pichar_true_equal){
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_char_true){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "a";
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_char_false){
|
||||
PIString str1 = "a";
|
||||
char str2[] = "t";
|
||||
ASSERT_FALSE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_more_eq_char_true_equal){
|
||||
PIString str1 = "t";
|
||||
char str2[] = "t";
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_pistring){
|
||||
PIString str1 = "shift";
|
||||
PIString str2 = " good";
|
||||
str1 << str2;
|
||||
ASSERT_STREQ("shift good", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_pichar){
|
||||
PIString str1 = "shif";
|
||||
PIChar str2 = 't';
|
||||
str1 << str2;
|
||||
ASSERT_STREQ("shift", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_char){
|
||||
PIString str1 = "shif";
|
||||
char str2[] = "t chat";
|
||||
str1 << str2;
|
||||
ASSERT_STREQ("shift chat", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_wchar_t){
|
||||
PIString str1 = "shif";
|
||||
wchar_t str2[] = L"t cc";
|
||||
str1 << str2;
|
||||
ASSERT_STREQ("shift cc", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_int){
|
||||
PIString str1 = "shift ";
|
||||
int numb = -2147483648;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift -2147483648", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_uint){
|
||||
PIString str1 = "shift ";
|
||||
uint numb = 4294967295;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift 4294967295", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_short){
|
||||
PIString str1 = "shift ";
|
||||
short numb = -32768;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift -32768", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_ushort){
|
||||
PIString str1 = "shift ";
|
||||
ushort numb = 65535;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift 65535", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_long){
|
||||
PIString str1 = "shift ";
|
||||
long numb = -2147483648;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift -2147483648", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_ulong){
|
||||
PIString str1 = "shift ";
|
||||
ulong numb = 4294967295;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift 4294967295", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_llong){
|
||||
PIString str1 = "shift ";
|
||||
llong numb = -9223372036854775807;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift -9223372036854775807", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_ullong){
|
||||
PIString str1 = "shift ";
|
||||
ullong numb = 1844674407370955161;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift 1844674407370955161", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_float){
|
||||
PIString str1 = "shift ";
|
||||
float numb = -67.88999939;
|
||||
str1 << numb;
|
||||
ASSERT_STREQ("shift -67.88999939", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_shift_double){
|
||||
PIString str1 = "shift ";
|
||||
double numb = 13.34300000;
|
||||
str1 << numb;
|
||||
|
||||
ASSERT_STREQ("shift 13.34300000", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, prepend){
|
||||
PIString str1 = "idea";
|
||||
PIString str2 = "Good ";
|
||||
str1.prepend(str2);
|
||||
ASSERT_STREQ("Good idea", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, append){
|
||||
PIString str1 = "Good";
|
||||
PIString str2 = " idea";
|
||||
str1.append(str2);
|
||||
ASSERT_STREQ("Good idea", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, mid){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("fo", str1.mid(10, 2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, mid_len_0){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("", str1.mid(10, 0));
|
||||
}
|
||||
|
||||
|
||||
TEST(PIString_Tests, mid_start_more){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("", str1.mid(1000, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, mid_len_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("for new project 144", str1.mid(10, -2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, mid_len_more){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("for new project 144", str1.mid(10, 100));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, subString){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("for new project 144", str1.mid(10, 46));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, mid_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.mid(-10, 47));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, subString_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Go", str1.mid(-10, 12));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, left){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Go", str1.left(2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, left_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("", str1.left(-2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, right){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("44", str1.right(2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, right_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("", str1.right(-2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutMid){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good for new project 144", str1.cutMid(5,5));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutMid_len_zero){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.cutMid(5,0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutMid_len_min){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good ", str1.cutMid(5,-2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutMid_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("ood idea for new project 144", str1.cutMid(-5, 6));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutMid_zero){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.cutMid(-5, 5));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutleft){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("od idea for new project 144", str1.cutLeft(2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutleft_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.cutLeft(-2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutright){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 1", str1.cutRight(2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, cutright_minus){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.cutRight(-2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, trim){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.trim());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, trim_without){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.trim());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, trim_link){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
PIString &str2 = str1.trim();
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, trimmed){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.trimmed());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, trimmed_without){
|
||||
PIString str1 = "Good idea for new project 144";
|
||||
ASSERT_STREQ("Good idea for new project 144", str1.trimmed());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ(" Good thin for new project 144 ", str1.replace(6,4, "thin"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_more){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ(" Good thin", str1.replace(6,100, "thin"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_link){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
PIString &str2 = str1.replace(6,4, "thin");
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_minus){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("BAD idea for new project 144 ", str1.replace(0, 5, "BAD"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_zero){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("thin Good idea for new project 144 ", str1.replace(0, 0, "thin"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_all){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("BAD", str1.replaced(0, 100, "BAD"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ(" Good thin for new project 144 ", str1.replaced(6,4, "thin"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_minus){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("BAD idea for new project 144 ", str1.replaced(0, 5, "BAD"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_zero){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("thin Good idea for new project 144 ", str1.replaced(0, 0, "thin"));
|
||||
}
|
||||
|
||||
|
||||
TEST(PIString_Tests, replaced_all){
|
||||
PIString str1 = " Good idea for new project 144 ";
|
||||
ASSERT_STREQ("thin", str1.replaced(0, 100, "thin"));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_str){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replace("Good", "bad", &ok);
|
||||
ASSERT_STREQ(" bad idea for new Good project 144 ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_str_link){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
PIString &str2 = str1.replace("Good", "bad", &ok);
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_str_zero){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replace("", "bad", &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_str_true){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replace("Good", "bad", &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replace_str_delete){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replace("Good", "", &ok);
|
||||
ASSERT_STREQ(" idea for new Good project 144 ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_str){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
PIString str2 = str1.replaced("Good", "bad", &ok);
|
||||
ASSERT_STREQ(" bad idea for new Good project 144 ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_str_zero){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replaced("", "bad", &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_str_true){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
str1.replaced("Good", "bad", &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaced_delete){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
bool ok = 1;
|
||||
PIString str2 = str1.replaced("Good", "", &ok);
|
||||
ASSERT_STREQ(" idea for new Good project 144 ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
str1.replaceAll("Good", "bad");
|
||||
ASSERT_STREQ(" bad idea for new bad project 144 ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall_no_find){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
str1.replaceAll("God", "bad");
|
||||
ASSERT_STREQ(" Good idea for new Good project 144 ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall_str){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
PIString str2 = str1.replaceAll("Good", "bad");
|
||||
ASSERT_STREQ(" bad idea for new bad project 144 ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall_str_no_find){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
PIString str2 = str1.replaceAll("God", "bad");
|
||||
ASSERT_STREQ(" Good idea for new Good project 144 ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall_link){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
PIString &str2 = str1.replaceAll("Good", "bad");
|
||||
ASSERT_STREQ(" bad idea for new bad project 144 ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, replaceall_link_change){
|
||||
PIString str1 = " Good idea for new Good project 144 ";
|
||||
PIString &str2 = str1.replaceAll("Good", "bad");
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, repeat){
|
||||
PIString str1 = "string ";
|
||||
PIString str2 = str1.repeat(6);
|
||||
ASSERT_STREQ("string string string string string string ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, repeat_zero){
|
||||
PIString str1 = "string ";
|
||||
PIString str2 = str1.repeat(0);
|
||||
ASSERT_STREQ("string ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, repeat_link){
|
||||
PIString str1 = "string ";
|
||||
PIString &str2 = str1.repeat(6);
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, repeated){
|
||||
PIString str1 = "string ";
|
||||
str1.repeat(6);
|
||||
ASSERT_STREQ("string string string string string string ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, repeated_zero){
|
||||
PIString str1 = "string ";
|
||||
str1.repeat(0);
|
||||
ASSERT_STREQ("string ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, insert_char){
|
||||
PIString str1 = "strng ";
|
||||
char sym = 'i';
|
||||
str1.insert(3, sym);
|
||||
ASSERT_STREQ("string ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, insert_pichar){
|
||||
PIString str1 = "strng ";
|
||||
PIChar sym = 'i';
|
||||
str1.insert(3, sym);
|
||||
ASSERT_STREQ("string ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, insert_pistring){
|
||||
PIString str1 = "string out";
|
||||
PIString str2 = " go";
|
||||
str1.insert(6, str2);
|
||||
ASSERT_STREQ("string go out", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, insert_chars){
|
||||
PIString str1 = "see boy";
|
||||
char str2[] = " big";
|
||||
str1.insert(3, str2);
|
||||
ASSERT_STREQ("see big boy", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, expandRightTo){
|
||||
PIString str1 = "see boy ";
|
||||
PIChar symbol = "x";
|
||||
str1.expandRightTo(11, symbol);
|
||||
ASSERT_STREQ("see boy xxx", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, expandRightTo_null){
|
||||
PIString str1 = "see boy ";
|
||||
PIChar symbol = "x";
|
||||
str1.expandRightTo(0, symbol);
|
||||
ASSERT_STREQ("see boy ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, expandLeftTo){
|
||||
PIString str1 = " see boy";
|
||||
PIChar symbol = "x";
|
||||
str1.expandLeftTo(11, symbol);
|
||||
ASSERT_STREQ("xxx see boy", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, expandLeftTo_null){
|
||||
PIString str1 = "see boy ";
|
||||
PIChar symbol = "x";
|
||||
str1.expandLeftTo(0, symbol);
|
||||
ASSERT_STREQ("see boy ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, quote){
|
||||
PIString str1 = "see boy";
|
||||
PIChar symbol = " ";
|
||||
str1.quote(symbol);
|
||||
ASSERT_STREQ(" see boy ", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, quote_link){
|
||||
PIString str1 = "see boy";
|
||||
PIChar symbol = " ";
|
||||
PIString &str2 = str1.quote(symbol);
|
||||
str1 = "link";
|
||||
ASSERT_STREQ("link", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, quoted){
|
||||
PIString str1 = "see boy";
|
||||
PIChar symbol = " ";
|
||||
PIString str2 = str1.quoted(symbol);
|
||||
ASSERT_STREQ(" see boy ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, reverse){
|
||||
PIString str1 = "see boy";
|
||||
PIString &str2 = str1.reverse();
|
||||
ASSERT_STREQ("yob ees", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, reverse_link){
|
||||
PIString str1 = "see boy";
|
||||
PIString &str2 = str1.reverse();
|
||||
str1 = "yes";
|
||||
ASSERT_STREQ("yes", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, reversed){
|
||||
PIString str1 = "see boy";
|
||||
PIString str2 = str1.reversed();
|
||||
ASSERT_STREQ("yob ees", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, elide){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString &str2 = str1.elide(8, 1);
|
||||
ASSERT_STREQ("BMSTU ..", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, elide_small){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString &str2 = str1.elide(2, 1);
|
||||
ASSERT_STREQ("..", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, elide_all){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString &str2 = str1.elide(100, 1);
|
||||
ASSERT_STREQ("BMSTU is best university in space", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, elide_link){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString &str2 = str1.elide(8, 1);
|
||||
str1 = "space";
|
||||
ASSERT_STREQ("space", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, elided){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.elided(8, 1);
|
||||
ASSERT_STREQ("BMSTU ..", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takemid){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeMid(9, 4);
|
||||
ASSERT_STREQ("best", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeleft){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeLeft(5);
|
||||
ASSERT_STREQ("BMSTU", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeright){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeRight(5);
|
||||
ASSERT_STREQ("space", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takesymbol){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeSymbol();
|
||||
ASSERT_STREQ("B", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takesymbol_with_rubbish){
|
||||
PIString str1 = " \t \n \r BMSTU is best university in space";
|
||||
PIString str2 = str1.takeSymbol();
|
||||
ASSERT_STREQ("B", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takesymbol_without){
|
||||
PIString str1 = " \t \n \r ";
|
||||
PIString str2 = str1.takeSymbol();
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeword){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeWord();
|
||||
ASSERT_STREQ("BMSTU", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeword_space){
|
||||
PIString str1 = " \r\n\tBMSTU is best university in space";
|
||||
PIString str2 = str1.takeWord();
|
||||
ASSERT_STREQ("BMSTU", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeword_without_word){
|
||||
PIString str1 = " \r\n\t";
|
||||
PIString str2 = str1.takeWord();
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takecword){
|
||||
PIString str1 = "_6 BMSTU is best university in space";
|
||||
PIString str2 = str1.takeCWord();
|
||||
ASSERT_STREQ("_6", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takecword_space){
|
||||
PIString str1 = " \t\r\n_6 BMSTU is best university in space";
|
||||
PIString str2 = str1.takeCWord();
|
||||
ASSERT_STREQ("_6", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takecword_space_w){
|
||||
PIString str1 = " \t\r\n BMSTU is best university in space";
|
||||
PIString str2 = str1.takeCWord();
|
||||
ASSERT_STREQ("BMSTU", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takecword_not_cword){
|
||||
PIString str1 = " \t\r\n ";
|
||||
PIString str2 = str1.takeCWord();
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeline){
|
||||
PIString str1 = "BMSTU is best\n university in space";
|
||||
PIString str2 = str1.takeLine();
|
||||
ASSERT_STREQ("BMSTU is best", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeline_without){
|
||||
PIString str1 = "BMSTU is best";
|
||||
PIString str2 = str1.takeLine();
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takeline_first){
|
||||
PIString str1 = "\nBMSTU is best";
|
||||
PIString str2 = str1.takeLine();
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takenumber){
|
||||
PIString str1 = "6.6";
|
||||
PIString str2 = str1.takeNumber();
|
||||
ASSERT_STREQ("6.6", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takenumber_sign){
|
||||
PIString str1 = "-66";
|
||||
PIString str2 = str1.takeNumber();
|
||||
ASSERT_STREQ("-66", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takenumber_suffix){
|
||||
PIString str1 = "66L";
|
||||
PIString str2 = str1.takeNumber();
|
||||
ASSERT_STREQ("66L", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takerange){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeRange('B', 'i', ' ');
|
||||
ASSERT_STREQ("MSTU is best un", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takerange_without_shield){
|
||||
PIString str1 = "BMSTU is best university in space";
|
||||
PIString str2 = str1.takeRange('B', 'i');
|
||||
ASSERT_STREQ("MSTU ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takerange_space){
|
||||
PIString str1 = " \t\r\nBMSTU is best university in space";
|
||||
PIString str2 = str1.takeRange('B', 'i', ' ');
|
||||
ASSERT_STREQ("MSTU is best un", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, takerange_without_shield_space){
|
||||
PIString str1 = " \t\r\nBMSTU is best university in space";
|
||||
PIString str2 = str1.takeRange('B', 'i');
|
||||
ASSERT_STREQ("MSTU ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, inBrackets){
|
||||
PIString str1 = "BMSTU is (best) university in space";
|
||||
PIString str2 = str1.inBrackets('(', ')');
|
||||
ASSERT_STREQ("best", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, inBrackets_end_start){
|
||||
PIString str1 = "BMSTU )is (best) university in space";
|
||||
PIString str2 = str1.inBrackets('(', ')');
|
||||
ASSERT_STREQ("best", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, inBrackets_without){
|
||||
PIString str1 = "BMSTU )is (best) university in space";
|
||||
PIString str2 = str1.inBrackets('0', '1');
|
||||
ASSERT_STREQ("", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, lenghtascii){
|
||||
PIString str1 = "BMSTU is (best) university in space";
|
||||
int size = str1.lengthAscii();
|
||||
ASSERT_EQ(35, size);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, data){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
const char *data = str1.data();
|
||||
ASSERT_STREQ("BMSTU is (best) university in space\n", data);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, dataconsole){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
const char *data = str1.dataConsole();
|
||||
ASSERT_STREQ("BMSTU is (best) university in space\n", data);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, dataUTF8){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
const char *data = str1.dataUTF8();
|
||||
ASSERT_STREQ("BMSTU is (best) university in space\n", data);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, dataAScii){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
const char *data = str1.dataAscii();
|
||||
ASSERT_STREQ("BMSTU is (best) university in space\n", data);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, hash){
|
||||
const PIString str1 = "B";
|
||||
uint h = str1.hash();
|
||||
ASSERT_EQ(3912571919, h);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toByteArray){
|
||||
const PIString str1 = "C";
|
||||
PIByteArray h = str1.toByteArray();
|
||||
ASSERT_EQ(67, h.at(0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toUTF8){
|
||||
const PIString str1 = "C";
|
||||
PIByteArray h = str1.toUTF8();
|
||||
ASSERT_EQ(67, h.at(0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, tocharset){
|
||||
const PIString str1 = "B";
|
||||
PIByteArray h = str1.toCharset("c");
|
||||
ASSERT_EQ(66, h.at(0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toUTF8_empty){
|
||||
PIString str1;
|
||||
str1.toUTF8();
|
||||
ASSERT_EQ(0, str1.size());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, tocharset_empty){
|
||||
PIString str1 = "";
|
||||
str1.toCharset("c");
|
||||
ASSERT_EQ(0, str1.size());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, split){
|
||||
PIString str1 = " mirrow best mirrow ";
|
||||
PIStringList list = str1.split("best");
|
||||
ASSERT_STREQ(list[1], list[0]);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, split_sec){
|
||||
PIString str1 = " mirrow best detail ";
|
||||
PIStringList list = str1.split("best");
|
||||
ASSERT_STREQ(" mirrow ", list[0]);
|
||||
ASSERT_STREQ(list[1], " detail ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, split_empty){
|
||||
PIString str1 = "";
|
||||
PIStringList list = str1.split("best");
|
||||
ASSERT_EQ(0, list.size());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, split_empty_delim){
|
||||
PIString str1 = " mirrow best mirrow ";
|
||||
PIStringList list = str1.split("");
|
||||
ASSERT_EQ(0, list.size());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, split_not_delim){
|
||||
PIString str1 = " mirrow best mirrow ";
|
||||
PIStringList list = str1.split("tr");
|
||||
ASSERT_STREQ(list[0], " mirrow best mirrow ");
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toUpperCase){
|
||||
PIString str1 = " miRrow ";
|
||||
PIString str2 = str1.toUpperCase();
|
||||
ASSERT_STREQ(" MIRROW ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toLowerCase){
|
||||
PIString str1 = " MIrROW ";
|
||||
PIString str2 = str1.toLowerCase();
|
||||
ASSERT_STREQ(" mirrow ", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, toNativeDecimalPoints){
|
||||
PIString str1 = "4546,878";
|
||||
PIString str2 = str1.toNativeDecimalPoints();
|
||||
ASSERT_STREQ("4546.878", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_char){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = '\n';
|
||||
ASSERT_TRUE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_char_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = '0';
|
||||
ASSERT_FALSE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_picahr){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIChar s = 'i';
|
||||
ASSERT_TRUE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_pichar_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIChar s = '0';
|
||||
ASSERT_FALSE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_cahrs){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s[] = "BMSTU";
|
||||
ASSERT_TRUE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_chars_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s[] = "out";
|
||||
ASSERT_FALSE(str1.contains(s));
|
||||
}
|
||||
|
||||
|
||||
TEST(PIString_Tests, contains_pistring){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString s = "univer";
|
||||
ASSERT_TRUE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, contains_pistring_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString s = "new";
|
||||
ASSERT_FALSE(str1.contains(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_char){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'i';
|
||||
ASSERT_EQ(6, str1.find(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_char_start){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'i';
|
||||
ASSERT_EQ(18, str1.find(s, 7));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_char_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'o';
|
||||
ASSERT_EQ(-1, str1.find(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_chars){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char str2[] = "is";
|
||||
ASSERT_EQ(6, str1.find(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_chars_start){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char str2[] = "iv";
|
||||
ASSERT_EQ(18, str1.find(str2, 7));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_chars_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s[] = "ouc";
|
||||
ASSERT_EQ(-1, str1.find(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_pistring){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "is";
|
||||
ASSERT_EQ(6, str1.find(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_pistring_start){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "iv";
|
||||
ASSERT_EQ(18, str1.find(str2, 7));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_pistring_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "ouc";
|
||||
ASSERT_EQ(-1, str1.find(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_char){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'i';
|
||||
ASSERT_EQ(27, str1.findLast(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_char_start){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'i';
|
||||
ASSERT_EQ(27, str1.findLast(s, 20));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_char_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char s = 'o';
|
||||
ASSERT_EQ(-1, str1.findLast(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_chars){
|
||||
PIString str1 = "BMSTU is (best) university in is space\n";
|
||||
char str2[] = "is";
|
||||
ASSERT_EQ(30, str1.findLast(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_chars_start){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
char str2[] = "iv";
|
||||
ASSERT_EQ(30, str1.findLast(str2, 25));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_chars_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
char str2[] = "ouc";
|
||||
ASSERT_EQ(-1, str1.findLast(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_pistring){
|
||||
PIString str1 = "BMSTU is (best) university in is space\n";
|
||||
PIString str2 = "is";
|
||||
ASSERT_EQ(30, str1.findLast(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_pistring_start){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "iv";
|
||||
ASSERT_EQ(30, str1.findLast(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_last_pistring_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "ouc";
|
||||
ASSERT_EQ(-1, str1.findLast(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(16, str1.findWord(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_start){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(16, str1.findWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_space_before){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = " university";
|
||||
ASSERT_EQ(-1, str1.findWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_space_after){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university ";
|
||||
ASSERT_EQ(-1, str1.findWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_digit_before){
|
||||
PIString str1 = "BMSTU is (best) _university_ in iv space\n";
|
||||
PIString str2 = "_university";
|
||||
ASSERT_EQ(-1, str1.findWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_digit_after){
|
||||
PIString str1 = "BMSTU is (best) _university_ in iv space\n";
|
||||
PIString str2 = "university_";
|
||||
ASSERT_EQ(-1, str1.findWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_word_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(-1, str1.findWord(str2, 37));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(16, str1.findCWord(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_start){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(16, str1.findCWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_space_before){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = " university";
|
||||
ASSERT_EQ(15, str1.findCWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_space_after){
|
||||
PIString str1 = "BMSTU is (best) university in iv space\n";
|
||||
PIString str2 = "university ";
|
||||
ASSERT_EQ(-1, str1.findCWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_digit_before){
|
||||
PIString str1 = "BMSTU is (best) _university_ in iv space\n";
|
||||
PIString str2 = "_university";
|
||||
ASSERT_EQ(-1, str1.findCWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_digit_after){
|
||||
PIString str1 = "BMSTU is (best) _university_ in iv space\n";
|
||||
PIString str2 = "university_";
|
||||
ASSERT_EQ(-1, str1.findCWord(str2, 10));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_cword_false){
|
||||
PIString str1 = "BMSTU is (best) university in space\n";
|
||||
PIString str2 = "university";
|
||||
ASSERT_EQ(-1, str1.findCWord(str2, 37));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIChar start = "v";
|
||||
PIChar end = "g";
|
||||
ASSERT_EQ(3, str1.findRange(start, end, "n", 1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range_len){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIChar start = "v";
|
||||
PIChar end = "g";
|
||||
int len;
|
||||
str1.findRange(start, end, "n", 1, &len);
|
||||
ASSERT_EQ(14, len);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range_len_without_shield){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIChar start = "v";
|
||||
PIChar end = "g";
|
||||
int len;
|
||||
str1.findRange(start, end, "/", 1, &len);
|
||||
ASSERT_EQ(9, len);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range_start){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIChar start = "g";
|
||||
PIChar end = "o";
|
||||
int len;
|
||||
str1.findRange(start, end, " ", 17, &len);
|
||||
ASSERT_EQ(9, len);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range_eq){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIChar start = "v";
|
||||
PIChar end = "v";
|
||||
int len;
|
||||
str1.findRange(start, end, "n", 1, &len);
|
||||
ASSERT_EQ(0, len);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_range_trim){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIChar start = "A";
|
||||
PIChar end = "v";
|
||||
int len;
|
||||
ASSERT_EQ(2, str1.findRange(start, end, "n", 0, &len));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "doip";
|
||||
ASSERT_EQ(11, str1.findAny(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_not){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "q";
|
||||
ASSERT_EQ(-1, str1.findAny(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_start){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "doip";
|
||||
ASSERT_EQ(15, str1.findAny(str2, 12));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_chars){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "doip";
|
||||
ASSERT_EQ(11, str1.findAny(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_chars_not){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "q";
|
||||
ASSERT_EQ(-1, str1.findAny(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_chars_start){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "doip";
|
||||
ASSERT_EQ(15, str1.findAny(str2, 12));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "doip";
|
||||
ASSERT_EQ(39, str1.findAnyLast(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last_not){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "q";
|
||||
ASSERT_EQ(-1, str1.findAnyLast(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last_start){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "doip";
|
||||
ASSERT_EQ(39, str1.findAnyLast(str2, 12));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last_chars){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "doip";
|
||||
ASSERT_EQ(39, str1.findAnyLast(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last_chars_not){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "q";
|
||||
ASSERT_EQ(-1, str1.findAnyLast(str2, 0));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, find_any_last_chars_start){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char str2[] = "doip";
|
||||
ASSERT_EQ(39, str1.findAnyLast(str2, 12));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, entries){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIChar c = "A";
|
||||
ASSERT_EQ(1, str1.entries(c));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, entries_char){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
char c = 'A';
|
||||
ASSERT_EQ(1, str1.entries(c));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, starts_with){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = " A very";
|
||||
ASSERT_TRUE(str1.startsWith(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, starts_with_false){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = " A veru";
|
||||
ASSERT_FALSE(str1.startsWith(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, ends_with){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = " code";
|
||||
ASSERT_TRUE(str1.endsWith(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, ends_with_false){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
PIString str2 = "c code";
|
||||
ASSERT_FALSE(str1.endsWith(str2));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, length){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
ASSERT_EQ(41, str1.length());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, is_empty_false){
|
||||
PIString str1 = " A very strong programmer wrote this code";
|
||||
ASSERT_FALSE(str1.isEmpty());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, is_empty_true){
|
||||
PIString str1 = "";
|
||||
ASSERT_TRUE(str1.isEmpty());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_bool){
|
||||
PIString str1 = "1";
|
||||
ASSERT_TRUE(str1.toBool());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_bool_yes){
|
||||
PIString str1 = "yes";
|
||||
ASSERT_TRUE(str1.toBool());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_bool_false){
|
||||
PIString str1 = "no";
|
||||
ASSERT_FALSE(str1.toBool());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_bool_false_zero){
|
||||
PIString str1 = "0";
|
||||
ASSERT_FALSE(str1.toBool());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_char){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
ASSERT_EQ(65, str1.toChar());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_short){
|
||||
PIString str1 = "133";
|
||||
ASSERT_EQ(133, str1.toShort(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_short_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toShort(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_short_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toShort(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_short_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toShort(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_short_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(-7, str1.toShort(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ushort){
|
||||
PIString str1 = "133.1";
|
||||
ASSERT_EQ(133, str1.toUShort(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ushort_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toUShort(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ushort_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toUShort(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ushort_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toUShort(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ushort_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(65529, str1.toUShort(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_int){
|
||||
PIString str1 = "133";
|
||||
ASSERT_EQ(133, str1.toInt(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_int_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toInt(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_int_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toInt(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_int_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toInt(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_int_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(-7, str1.toShort(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_uint){
|
||||
PIString str1 = "133.1";
|
||||
ASSERT_EQ(133, str1.toUInt(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_uint_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toUInt(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_uint_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toUInt(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_uint_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toUInt(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_uint_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(4294967289, str1.toUInt(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_long){
|
||||
PIString str1 = "133";
|
||||
ASSERT_EQ(133, str1.toLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_long_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_long_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toLong(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_long_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toLong(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_long_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(-7, str1.toLong(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ulong){
|
||||
PIString str1 = "133.1";
|
||||
ASSERT_EQ(133, str1.toULong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ulong_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toULong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ulong_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toULong(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ulong_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toULong(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ulong_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(4294967289, str1.toULong(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_llong){
|
||||
PIString str1 = "133";
|
||||
ASSERT_EQ(133, str1.toLLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_llong_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toLLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_llong_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toLLong(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_llong_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toLLong(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_llong_neg){
|
||||
PIString str1 = "-7";
|
||||
bool ok;
|
||||
ASSERT_EQ(-7, str1.toLLong(10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ullong){
|
||||
PIString str1 = "133.1";
|
||||
ASSERT_EQ(133, str1.toULLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ullong_0x){
|
||||
PIString str1 = "0x133";
|
||||
ASSERT_EQ(307, str1.toULLong(-1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ullong_false){
|
||||
PIString str1 = "0x133";
|
||||
bool ok;
|
||||
str1.toULLong(1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ullong_false_base){
|
||||
PIString str1 = "7";
|
||||
bool ok;
|
||||
str1.toULLong(6, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_float){
|
||||
PIString str1 = "-7765,54";
|
||||
float f = -7765.54;
|
||||
ASSERT_EQ(f, str1.toFloat());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_double){
|
||||
PIString str1 = "-7765,54656";
|
||||
double f = -7765.54656;
|
||||
ASSERT_EQ(f, str1.toDouble());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, to_ldouble){
|
||||
PIString str1 = "-7765,54656";
|
||||
ldouble f = -7765.54656;
|
||||
ASSERT_EQ(f, str1.toLDouble());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_zero){
|
||||
PIString str1 = " String";
|
||||
const short val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_false_base){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_true){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_base_minus){
|
||||
PIString str1 = " String";
|
||||
const short val = -10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("-A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort_true){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort_zero){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort_false_base){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ushort_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int_zero){
|
||||
PIString str1 = " String";
|
||||
const int val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int_false_base){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int_true){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_int_base_minus){
|
||||
PIString str1 = " String";
|
||||
const int val = -10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("-A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uint){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uint_true){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uintt_zero){
|
||||
PIString str1 = " String";
|
||||
const uint val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uint_false_base){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uint_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_uint_base_minus){
|
||||
PIString str1 = " String";
|
||||
const uint val = 10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long_zero){
|
||||
PIString str1 = " String";
|
||||
const long val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long_false_base){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long_true){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_long_base_minus){
|
||||
PIString str1 = " String";
|
||||
const long val = -10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("-A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong_true){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong_zero){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong_false_base){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ulong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong_zero){
|
||||
PIString str1 = " String";
|
||||
const llong val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong_false_base){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong_true){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_llong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const llong val = -10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("-A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("131", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong_true){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong_zero){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 0;
|
||||
bool ok;
|
||||
str1.setNumber(val, 10, &ok);
|
||||
ASSERT_STREQ("0", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong_false_base){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.setNumber(val, 1, &ok);
|
||||
ASSERT_STREQ("", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ullong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 10;
|
||||
bool ok;
|
||||
str1.setNumber(val, 16, &ok);
|
||||
ASSERT_STREQ("A", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_float){
|
||||
PIString str1 = " String";
|
||||
const float val = 131.132;
|
||||
str1.setNumber(val, 'f', 3);
|
||||
ASSERT_STREQ("131.132", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_double){
|
||||
PIString str1 = " String";
|
||||
const double val = 131.1324334;
|
||||
str1.setNumber(val, 'f', 7);
|
||||
ASSERT_STREQ("131.1324334", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setNumber_ldouble){
|
||||
PIString str1 = " String";
|
||||
const ldouble val = 131.1324334;
|
||||
str1.setNumber(val, 'f', 7);
|
||||
ASSERT_STREQ("131.1324334", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1023 B", str1.setReadableSize(1023));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize_kb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 kB", str1.setReadableSize(1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize_mb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 MB", str1.setReadableSize(1024*1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize_gb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 GB", str1.setReadableSize(1024*1024*1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize_tb){
|
||||
PIString str1 = " ITELMA";
|
||||
llong val = 99999999999999;
|
||||
ASSERT_STREQ("90.9 TB", str1.setReadableSize(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, setReadableSize_pb){
|
||||
PIString str1 = " ITELMA";
|
||||
llong val = 999999999999999999;
|
||||
ASSERT_STREQ("888.1 PB", str1.setReadableSize(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumberr_zero){
|
||||
PIString str1 = " String";
|
||||
const short val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_false_base){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_true){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const short val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_base_minus){
|
||||
PIString str1 = " String";
|
||||
const short val = -10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort_true){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort_zero){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort_false_base){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ushort_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ushort val = 10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int_zero){
|
||||
PIString str1 = " String";
|
||||
const int val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int_false_base){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int_true){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const int val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_int_base_minus){
|
||||
PIString str1 = " String";
|
||||
const int val = -10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uint){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uint_true){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uintt_zero){
|
||||
PIString str1 = " String";
|
||||
const uint val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uint_false_base){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uint_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const uint val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_uint_base_minus){
|
||||
PIString str1 = " String";
|
||||
const uint val = 10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long_zero){
|
||||
PIString str1 = " String";
|
||||
const long val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long_false_base){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long_true){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const long val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_long_base_minus){
|
||||
PIString str1 = " String";
|
||||
const long val = -10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong_true){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong_zero){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong_false_base){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ulong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ulong val = 10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong_zero){
|
||||
PIString str1 = " String";
|
||||
const llong val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong_false_base){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong_true){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const llong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_llong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const llong val = -10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("-A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("131", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong_true){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 10, &ok);
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong_zero){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 0;
|
||||
bool ok;
|
||||
ASSERT_STREQ("0", str1.fromNumber(val, 10, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong_false_base){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
str1.fromNumber(val, 1, &ok);
|
||||
ASSERT_FALSE(ok);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong_false_base_str){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 131;
|
||||
bool ok;
|
||||
ASSERT_STREQ("", str1.fromNumber(val, 1, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ullong_base_minus){
|
||||
PIString str1 = " String";
|
||||
const ullong val = 10;
|
||||
bool ok;
|
||||
ASSERT_STREQ("A", str1.fromNumber(val, 16, &ok));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_float){
|
||||
PIString str1 = " String";
|
||||
const float val = 131.132;
|
||||
ASSERT_STREQ("131.132", str1.fromNumber(val, 'f', 3));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_double){
|
||||
PIString str1 = " String";
|
||||
const double val = 131.1324334;
|
||||
ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromNumber_ldouble){
|
||||
PIString str1 = " String";
|
||||
const ldouble val = 131.1324334;
|
||||
ASSERT_STREQ("131.1324334", str1.fromNumber(val, 'f', 7));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromBool_true){
|
||||
PIString str1;
|
||||
bool val = true;
|
||||
ASSERT_STREQ("true", str1.fromBool(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, fromBool_false){
|
||||
PIString str1;
|
||||
bool val = false;
|
||||
ASSERT_STREQ("false", str1.fromBool(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_Console){
|
||||
PIString str1;
|
||||
char s[] = "true boy";
|
||||
ASSERT_STREQ("true boy", str1.fromConsole(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_System){
|
||||
PIString str1;
|
||||
char s[] = "true boy";
|
||||
ASSERT_STREQ("true boy", str1.fromSystem(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_UTF8){
|
||||
PIString str1;
|
||||
char s[] = "true boy";
|
||||
ASSERT_STREQ("true boy", str1.fromUTF8(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_UTF8_ba){
|
||||
PIString str1;
|
||||
PIByteArray s;
|
||||
s.append('t');
|
||||
s.append('r');
|
||||
s.append('u');
|
||||
s.append('e');
|
||||
ASSERT_STREQ("true", str1.fromUTF8(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_Ascii){
|
||||
PIString str1;
|
||||
char s[] = "true boy";
|
||||
ASSERT_STREQ("true boy", str1.fromAscii(s));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, from_Codepage){
|
||||
PIString str1 = "Nul";
|
||||
char s[] = "true";
|
||||
char c[] = "utf8";
|
||||
PIString str2 = str1.fromCodepage(s, c);
|
||||
ASSERT_STREQ("true", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, ReadableSize){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1023 B", str1.readableSize(1023));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, readableSize_kb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 kB", str1.readableSize(1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, readableSize_mb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 MB", str1.readableSize(1024*1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, readableSize_gb){
|
||||
PIString str1 = " ITELMA";
|
||||
ASSERT_STREQ("1.0 GB", str1.readableSize(1024*1024*1024));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, readableSize_tb){
|
||||
PIString str1 = " ITELMA";
|
||||
llong val = 99999999999999;
|
||||
ASSERT_STREQ("90.9 TB", str1.readableSize(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, readableSize_pb){
|
||||
PIString str1 = " ITELMA";
|
||||
llong val = 999999999999999999;
|
||||
ASSERT_STREQ("888.1 PB", str1.readableSize(val));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, removeAll_char){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
char v = ' ';
|
||||
ASSERT_STREQ("Averystrongprogrammerwrotethiscode", str1.removeAll(v));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, removeAll_pistring){
|
||||
PIString str1 = "A very strong programmer wrote this code";
|
||||
PIString v = "very strong ";
|
||||
ASSERT_STREQ("A programmer wrote this code", str1.removeAll(v));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_ba_pstr){
|
||||
PIString str1 = '1';
|
||||
PIByteArray s;
|
||||
s << str1;
|
||||
ASSERT_STREQ("010000003100", s.toHex());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_pstr_ba){
|
||||
PIString str1 = "1";
|
||||
PIByteArray s;
|
||||
s.append('t');
|
||||
s.append('r');
|
||||
s.append('u');
|
||||
s.append('e');
|
||||
str1 << s;
|
||||
ASSERT_STREQ("1true", str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_plus_pstr_pstr){
|
||||
PIString str1 = "first ";
|
||||
PIString str2 = "second";
|
||||
ASSERT_STREQ("first second", str1 + str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_plus_pstr_chars){
|
||||
PIString str1 = "first ";
|
||||
char str2[] = "second";
|
||||
ASSERT_STREQ("first second", str1 + str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_plus_chars_pstr){
|
||||
PIString str1 = "first";
|
||||
char str2[] = "second ";
|
||||
ASSERT_STREQ("second first", str2 + str1);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, versionCompare2){ //дописать
|
||||
PIString str1 = "first";
|
||||
PIString str2 = "first 1";
|
||||
versionCompare(str1, str2, 0);
|
||||
ASSERT_EQ(898448032, piHash(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, versionNormalize2){
|
||||
PIString str1 = "first second";
|
||||
ASSERT_STREQ("0.0_first second", versionNormalize(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, piHash){
|
||||
PIString str1 = "first";
|
||||
ASSERT_EQ(898448032, piHash(str1));
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, piSwap){
|
||||
PIString str1 = "first";
|
||||
PIString str2 = "second";
|
||||
piSwap(str1, str2);
|
||||
ASSERT_STREQ("first", str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, piSwap_sec){
|
||||
PIString str1 = "first";
|
||||
PIString str2 = "second";
|
||||
piSwap(str1, str2);
|
||||
ASSERT_STREQ("second", str1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,554 +2,553 @@
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
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) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.element(i, j) - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, identity) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(i != j) {
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(i != j) {
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, element) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix.element(i,i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix.element(i,i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixRow) {
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixCol) {
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, setCol) {
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setCol(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setCol(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, setRow) {
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setRow(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setRow(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, swapCols) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
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;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a1[i] = matrix1.element(i, 0);
|
||||
a2[i] = matrix1.element(i, 1);
|
||||
a3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
matrix1.swapCols(i1, i2);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(i, 0);
|
||||
b2[i] = matrix1.element(i, 1);
|
||||
b3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
double a1[3], a2[3], a3[3];
|
||||
double b1[3], b2[3], b3[3];
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
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);
|
||||
a2[i] = matrix1.element(i, 1);
|
||||
a3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
matrix1.swapCols(i1, i2);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(i, 0);
|
||||
b2[i] = matrix1.element(i, 1);
|
||||
b3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, swapRows) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
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;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a1[i] = matrix1.element(0, i);
|
||||
a2[i] = matrix1.element(1, i);
|
||||
a3[i] = matrix1.element(2, i);
|
||||
}
|
||||
matrix1.swapRows(i1, i2);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(0, i);
|
||||
b2[i] = matrix1.element(1, i);
|
||||
b3[i] = matrix1.element(2, i);
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
double a1[3], a2[3], a3[3];
|
||||
double b1[3], b2[3], b3[3];
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
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);
|
||||
a2[i] = matrix1.element(1, i);
|
||||
a3[i] = matrix1.element(2, i);
|
||||
}
|
||||
matrix1.swapRows(i1, i2);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(0, i);
|
||||
b2[i] = matrix1.element(1, i);
|
||||
b3[i] = matrix1.element(2, i);
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
}
|
||||
TEST(PIMathMatrix_Test, fill) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
matrix.fill(7.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3));
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
matrix.fill(7.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 1.0);
|
||||
ASSERT_TRUE(matrix.isSquare());
|
||||
PIMathMatrix<double> matrix(3, 3, 1.0);
|
||||
ASSERT_TRUE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareFalse) {
|
||||
PIMathMatrix<double> matrix(2, 4, 1.0);
|
||||
ASSERT_FALSE(matrix.isSquare());
|
||||
PIMathMatrix<double> matrix(2, 4, 1.0);
|
||||
ASSERT_FALSE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityTrue) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
ASSERT_TRUE(matrix.isIdentity());
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
ASSERT_TRUE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityFalse) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isIdentity());
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
ASSERT_TRUE(matrix.isNull());
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
ASSERT_TRUE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullFalse) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isNull());
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 1.62);
|
||||
ASSERT_TRUE(matrix.isValid());
|
||||
PIMathMatrix<double> matrix(3, 3, 1.62);
|
||||
ASSERT_TRUE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidFalse) {
|
||||
PIMathMatrix<double> matrix;
|
||||
ASSERT_FALSE(matrix.isValid());
|
||||
PIMathMatrix<double> matrix;
|
||||
ASSERT_FALSE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 5.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 7.12);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 5.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 7.12);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_EqualTrue) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_EqualFalse) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualTrue) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualFalse) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition_Aassignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 1.0);
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 1.0);
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Division_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1*4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1*4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3));
|
||||
}
|
||||
TEST(PIMathMatrix_Test, operator_Division) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1/4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1/4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, determinantIfSquare) {
|
||||
double d;
|
||||
double i = 59.0;
|
||||
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;
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d = matrix.determinant();
|
||||
ASSERT_DOUBLE_EQ(d, i);
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d = matrix.determinant();
|
||||
ASSERT_DOUBLE_EQ(d, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, determinantIfNotSquare) {
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.determinant());
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.determinant());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, trace) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double t;
|
||||
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;
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
t = matrix.trace();
|
||||
ASSERT_DOUBLE_EQ(t, i);
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double t;
|
||||
double i = 9.0;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
t = matrix.trace();
|
||||
ASSERT_DOUBLE_EQ(t, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, traceIfNotSquare) {
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.trace());
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.trace());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, toUpperTriangular) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double d1, d2 = 1;
|
||||
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;
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d1 = matrix.determinant();
|
||||
matrix.toUpperTriangular();
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
d2 = d2 * matrix.element(i, i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double d1, d2 = 1;
|
||||
int i;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d1 = matrix.determinant();
|
||||
matrix.toUpperTriangular();
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
d2 = d2 * matrix.element(i, i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, invert) {
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
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;
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix2.invert();
|
||||
d2 = matrix2.determinant();
|
||||
matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix2.invert();
|
||||
d2 = matrix2.determinant();
|
||||
matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, inverted) {
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
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;
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix1 = matrix2.invert();
|
||||
d2 = matrix1.determinant();
|
||||
matrix3 = matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix1 = matrix2.invert();
|
||||
d2 = matrix1.determinant();
|
||||
matrix3 = matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, transposed) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
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);
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix2.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3));
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix2.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, valAndMatrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, hermitian) {
|
||||
complex<double> val;
|
||||
complex<double> res;
|
||||
val.imag(1.0);
|
||||
val.real(1.0);
|
||||
PIMathMatrix<complex<double>> matrix(3, 3, val);
|
||||
res.imag(-1.0);
|
||||
res.real(1.0);
|
||||
auto matr = hermitian(matrix);
|
||||
for(uint i = 0; i < 3; i++) {
|
||||
for(uint j = 0; j < 3; j++) {
|
||||
if(matr.element(i, j) != res) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
complex<double> val;
|
||||
complex<double> res;
|
||||
val.imag(1.0);
|
||||
val.real(1.0);
|
||||
PIMathMatrix<complex<double>> matrix(3, 3, val);
|
||||
res.imag(-1.0);
|
||||
res.real(1.0);
|
||||
auto matr = hermitian(matrix);
|
||||
for(uint i = 0; i < 3; i++) {
|
||||
for(uint j = 0; j < 3; j++) {
|
||||
if(matr.element(i, j) != res) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
@@ -5,558 +5,558 @@ const uint rows = 3;
|
||||
const uint cols = 3;
|
||||
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, 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.at(i, j) != val) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix[i][j] - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, identity) {
|
||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(int i = 0; i < rows; i++){
|
||||
for(int j = 0; j < cols; j++){
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, at) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(uint i = 0; i < rows; i++) {
|
||||
if(matrix1.at(i,i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(uint i = 0; i < rows; i++) {
|
||||
if(matrix1.at(i,i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
TEST(PIMathMatrixT_Test, filled) {
|
||||
auto matr = PIMathMatrixT<rows, cols, double>::filled(1.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
|
||||
auto matr = PIMathMatrixT<rows, cols, double>::filled(1.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, cols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(cols,matr.cols());
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(cols,matr.cols());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(rows,matr.rows());
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(rows,matr.rows());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, col) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
vect = matr.col(g);
|
||||
for(uint i = 0; i < matr.cols(); i++) {
|
||||
if(matr.at(i, g) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
vect = matr.col(g);
|
||||
for(uint i = 0; i < matr.cols(); i++) {
|
||||
if(matr.at(i, g) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, row) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
vect = matr.row(g);
|
||||
for(uint i = 0; i < matr.rows(); i++) {
|
||||
if(matr.at(g, i) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
vect = matr.row(g);
|
||||
for(uint i = 0; i < matr.rows(); i++) {
|
||||
if(matr.at(g, i) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
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;
|
||||
uint g = 1;
|
||||
matr.setCol(g, vect);
|
||||
for(uint i = 0; i < vect.size(); i++) {
|
||||
if(matr.at(i, g) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
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++) {
|
||||
if(matr.at(i, g) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
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;
|
||||
uint g = 1;
|
||||
matr.setRow(g, vect);
|
||||
for(uint i = 0; i < vect.size(); i++) {
|
||||
if(matr.at(g,i) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
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++) {
|
||||
if(matr.at(g,i) != vect.at(i)) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, swapCols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
|
||||
matr.swapCols(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.col(g2);
|
||||
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
|
||||
matr.swapCols(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.col(g2);
|
||||
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, swapRows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
|
||||
matr.swapRows(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.row(g2);
|
||||
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
|
||||
matr.swapRows(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> after_Vect2 = matr.row(g2);
|
||||
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, fill) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
double g = 1.0;
|
||||
matr.fill(g);
|
||||
for(uint i = 0; i < cols; i++) {
|
||||
for(uint j = 0; j < rows; j++) {
|
||||
matrix1.at(j,i) = g;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(matr == matrix1);
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
double g = 1.0;
|
||||
matr.fill(g);
|
||||
for(uint i = 0; i < cols; i++) {
|
||||
for(uint j = 0; j < rows; j++) {
|
||||
matrix1[j][i] = g;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(matr == matrix1);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isSquareTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isSquare());
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isSquareFalse) {
|
||||
const uint new_Cols = 4;
|
||||
PIMathMatrixT<rows, new_Cols, double> matrix2;
|
||||
ASSERT_FALSE(matrix2.isSquare());
|
||||
const uint new_Cols = 4;
|
||||
PIMathMatrixT<rows, new_Cols, double> matrix2;
|
||||
ASSERT_FALSE(matrix2.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isIdentityTrue) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_TRUE(matrix1.isIdentity());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_TRUE(matrix1.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isIdentityFalse) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(2.5);
|
||||
ASSERT_FALSE(matrix1.isIdentity());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(2.5);
|
||||
ASSERT_FALSE(matrix1.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isNullTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isNull());
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
ASSERT_TRUE(matrix1.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, isNullFalse) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_FALSE(matrix1.isNull());
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
ASSERT_FALSE(matrix1.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Assignment) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_EqualTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1.at(0, 0) = 5.1;
|
||||
matrix1.at(0, 1) = 1.21;
|
||||
matrix1.at(1, 1) = 0.671;
|
||||
matrix1.at(1, 0) = 2.623;
|
||||
matrix2.at(0, 0) = 5.1;
|
||||
matrix2.at(0, 1) = 1.21;
|
||||
matrix2.at(1, 1) = 0.671;
|
||||
matrix2.at(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1[0][0] = 5.1;
|
||||
matrix1[0][1] = 1.21;
|
||||
matrix1[1][1] = 0.671;
|
||||
matrix1[1][0] = 2.623;
|
||||
matrix2[0][0] = 5.1;
|
||||
matrix2[0][1] = 1.21;
|
||||
matrix2[1][1] = 0.671;
|
||||
matrix2[1][0] = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_EqualFalse) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1.at(0, 0) = 5.1;
|
||||
matrix1.at(0, 1) = 1.21;
|
||||
matrix1.at(1, 1) = 0.671;
|
||||
matrix1.at(1, 0) = 2.623;
|
||||
matrix2.at(0, 0) = 5.1;
|
||||
matrix2.at(0, 1) = 1.21;
|
||||
matrix2.at(1, 1) = 665.671;
|
||||
matrix2.at(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1[0][0] = 5.1;
|
||||
matrix1[0][1] = 1.21;
|
||||
matrix1[1][1] = 0.671;
|
||||
matrix1[1][0] = 2.623;
|
||||
matrix2[0][0] = 5.1;
|
||||
matrix2[0][1] = 1.21;
|
||||
matrix2[1][1] = 665.671;
|
||||
matrix2[1][0] = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1.at(0, 0) = 5.1;
|
||||
matrix1.at(0, 1) = 1.21;
|
||||
matrix1.at(1, 1) = 0.671;
|
||||
matrix1.at(1, 0) = 2.623;
|
||||
matrix2.at(0, 0) = 5.1;
|
||||
matrix2.at(0, 1) = 1.21;
|
||||
matrix2.at(1, 1) = 665.671;
|
||||
matrix2.at(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1[0][0] = 5.1;
|
||||
matrix1[0][1] = 1.21;
|
||||
matrix1[1][1] = 0.671;
|
||||
matrix1[1][0] = 2.623;
|
||||
matrix2[0][0] = 5.1;
|
||||
matrix2[0][1] = 1.21;
|
||||
matrix2[1][1] = 665.671;
|
||||
matrix2[1][0] = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1.at(0, 0) = 5.1;
|
||||
matrix1.at(0, 1) = 1.21;
|
||||
matrix1.at(1, 1) = 0.671;
|
||||
matrix1.at(1, 0) = 2.623;
|
||||
matrix2.at(0, 0) = 5.1;
|
||||
matrix2.at(0, 1) = 1.21;
|
||||
matrix2.at(1, 1) = 0.671;
|
||||
matrix2.at(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
matrix1[0][0] = 5.1;
|
||||
matrix1[0][1] = 1.21;
|
||||
matrix1[1][1] = 0.671;
|
||||
matrix1[1][0] = 2.623;
|
||||
matrix2[0][0] = 5.1;
|
||||
matrix2[0][1] = 1.21;
|
||||
matrix2[1][1] = 0.671;
|
||||
matrix2[1][0] = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72) ;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(1.0) ;
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72) ;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(1.0) ;
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Division_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
|
||||
}
|
||||
TEST(PIMathMatrixT_Test, operator_Division) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, determinantIfSquare) {
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
d = matr.determinant();
|
||||
ASSERT_DOUBLE_EQ(i, d);
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
d = matr.determinant();
|
||||
ASSERT_DOUBLE_EQ(i, d);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, determinantIfNotSquare) {
|
||||
PIMathMatrixT<rows, 5u, double> matr;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
ASSERT_FALSE(matr.determinant());
|
||||
PIMathMatrixT<rows, 5u, double> matr;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
ASSERT_FALSE(matr.determinant());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, invert) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
matrix2 = matr;
|
||||
matr.invert();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1;
|
||||
matrix1.invert();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2));
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
matrix2 = matr;
|
||||
matr.invert();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1;
|
||||
matrix1.invert();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, inverted) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matrix1 = matr.identity();
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
matrix2 = matr.inverted();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1.inverted();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matrix1 = matr.identity();
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
matrix2 = matr.inverted();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1.inverted();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, toUpperTriangular) {
|
||||
PIMathMatrixT<rows, cols, double> matrix;
|
||||
double d1, d2 = 1;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
matrix = matr.toUpperTriangular();
|
||||
d1 = matrix.determinant();
|
||||
for(uint i = 0; i < cols; i++)
|
||||
{
|
||||
d2 = d2*matrix.at(i,i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
PIMathMatrixT<rows, cols, double> matrix;
|
||||
double d1, d2 = 1;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
matrix = matr.toUpperTriangular();
|
||||
d1 = matrix.determinant();
|
||||
for(uint i = 0; i < cols; i++)
|
||||
{
|
||||
d2 = d2*matrix.at(i,i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, transposed) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr.at(0,0) = 3;
|
||||
matr.at(0,1) = 6;
|
||||
matr.at(0,2) = 8;
|
||||
matr.at(1,0) = 2;
|
||||
matr.at(1,1) = 1;
|
||||
matr.at(1,2) = 4;
|
||||
matr.at(2,0) = 6;
|
||||
matr.at(2,1) = 2;
|
||||
matr.at(2,2) = 5;
|
||||
d1 = matr.determinant();
|
||||
matrix1 = matr.transposed();
|
||||
d2 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matr == matrix2));
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr[0][0] = 3;
|
||||
matr[0][1] = 6;
|
||||
matr[0][2] = 8;
|
||||
matr[1][0] = 2;
|
||||
matr[1][1] = 1;
|
||||
matr[1][2] = 4;
|
||||
matr[2][0] = 6;
|
||||
matr[2][1] = 2;
|
||||
matr[2][2] = 5;
|
||||
d1 = matr.determinant();
|
||||
matrix1 = matr.transposed();
|
||||
d2 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matr == matrix2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, scaleX_two) {
|
||||
double factor = 5.64;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u)));
|
||||
double factor = 5.64;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, scaleY_two) {
|
||||
double factor = 5.64;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor);
|
||||
ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u)));
|
||||
double factor = 5.64;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor);
|
||||
ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotation_2x2) {
|
||||
double angle = 1.0;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u)));
|
||||
double angle = 1.0;
|
||||
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotation_3x3) {
|
||||
double angle = 1.0;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows));
|
||||
double angle = 1.0;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotationX) {
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u)));
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotationY) {
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u)));
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotationZ) {
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u)));
|
||||
double angle = 1.0;
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, scaleX_three) {
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, scaleY_three) {
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u)));
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor);
|
||||
ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, scaleZ_three) {
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor);
|
||||
ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
|
||||
double factor = 23.65;
|
||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor);
|
||||
ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixMultiplication)
|
||||
{
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>::filled(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>::filled(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>::filled(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>::filled(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
}
|
||||
|
||||
622
tests/math/testpimathvector.cpp
Normal file
@@ -0,0 +1,622 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathvector.h"
|
||||
|
||||
const uint SIZE = 3u;
|
||||
const double angle45DegInRad = 0.78539816339744830961566084581988;
|
||||
|
||||
bool cmpVectorWithValue(PIMathVector<double> vector, double val, int num) {
|
||||
|
zzuummaa marked this conversation as resolved
zzuummaa
commented
Не корректно сравнивать значения типа Не корректно сравнивать значения типа `double` оператором `!=` ([см. обсуждение](https://ru.stackoverflow.com/questions/461464/%D0%9A%D0%B0%D0%BA-%D1%81%D1%80%D0%B0%D0%B2%D0%BD%D0%B8%D1%82%D1%8C-%D0%B2%D0%B5%D1%89%D0%B5%D1%81%D1%82%D0%B2%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5-%D1%87%D0%B8%D1%81%D0%BB%D0%B0-%D0%B2-%D0%A1%D0%B8-%D0%BD%D0%B0-%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5-%D0%BC%D0%B5%D0%BD%D1%8C%D1%88%D0%B5)).
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
if(vector[i] - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
zzuummaa
commented
Предпочтительнее использовать ASSERT_EQ Предпочтительнее использовать ASSERT_EQ
|
||||
TEST(PIMathVector_Test, size) {
|
||||
auto vector = PIMathVector<double>(SIZE);
|
||||
ASSERT_EQ(vector.size(), SIZE);
|
||||
|
zzuummaa
commented
Нет проверки на size() вектора перед проверкой значений. Нет проверки на size() вектора перед проверкой значений.
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, resize) {
|
||||
uint newSize = 4u;
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector;
|
||||
|
zzuummaa
commented
Нет проверки на size() вектора перед проверкой значений. Тест составлен не корректно. Нет проверки на size() вектора перед проверкой значений. Тест составлен не корректно.
|
||||
vector.resize(newSize, a);
|
||||
ASSERT_EQ(vector.size(), newSize);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, vector.size()));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, resized) {
|
||||
uint newSize = 4u;
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector;
|
||||
auto vect = vector.resized(newSize, a);
|
||||
ASSERT_EQ(vect.size(), newSize);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vect, a, vect.size()));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, fill) {
|
||||
double a = 5.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, moveVal) {
|
||||
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) {
|
||||
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, a + b, SIZE));
|
||||
|
zzuummaa marked this conversation as resolved
Outdated
zzuummaa
commented
Не корректно сравнивать значения типа Не корректно сравнивать значения типа `double` оператором `==` ([см. обсуждение](https://ru.stackoverflow.com/questions/461464/%D0%9A%D0%B0%D0%BA-%D1%81%D1%80%D0%B0%D0%B2%D0%BD%D0%B8%D1%82%D1%8C-%D0%B2%D0%B5%D1%89%D0%B5%D1%81%D1%82%D0%B2%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5-%D1%87%D0%B8%D1%81%D0%BB%D0%B0-%D0%B2-%D0%A1%D0%B8-%D0%BD%D0%B0-%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5-%D0%BC%D0%B5%D0%BD%D1%8C%D1%88%D0%B5)). Заменить на `EXPECT_DOUBLE_EQ`.
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, moveVecSizeNotEq) {
|
||||
|
zzuummaa
commented
Лучше заполнять вектор чем то не равным еденице. Лучше заполнять вектор чем то не равным еденице.
Не корректно сравнивать значения типа `double` оператором `==`. Заменить на EXPECT_DOUBLE_EQ.
|
||||
double a = 5.0;
|
||||
double b = 7.0;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector.fill(a);
|
||||
|
zzuummaa
commented
Лучше заполнять вектор чем то не равным еденице. Лучше заполнять вектор чем то не равным еденице.
|
||||
vec.fill(b);
|
||||
vector.move(vec);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
ASSERT_EQ(vector.size(), SIZE);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, swap) {
|
||||
double b = 5.12;
|
||||
double c = 3.32;
|
||||
double d = 7.12;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
double a[3];
|
||||
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_DOUBLE_EQ(a[0], vector[1]);
|
||||
ASSERT_DOUBLE_EQ(a[1], vector[0]);
|
||||
ASSERT_DOUBLE_EQ(a[2], vector[2]);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, lengthSqr) {
|
||||
double a = 3.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
|
zzuummaa
commented
Вычисление косинуса вводит в заблуждение. Вычисление косинуса вводит в заблуждение.
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a * a, vector.lengthSqr());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, 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) {
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleCos) {
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
|
zzuummaa
commented
Посчитать проекцию в коде и сравнить Посчитать проекцию в коде и сравнить
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(cos(angle45DegInRad), vector.angleCos(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleCosSizeNotEq) {
|
||||
double a = 3.32;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_FALSE(vector.angleCos(vec));
|
||||
|
zzuummaa
commented
Тест составлен не корректно. Тест составлен не корректно.
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleSin) {
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(sin(angle45DegInRad), vector.angleSin(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleSinSizeNotEq) {
|
||||
double a = 3.32;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_FALSE(vector.angleSin(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleRad) {
|
||||
double a = 3.32;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle45DegInRad, vector.angleRad(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleRadSizeNotEq) {
|
||||
double a = 3.32;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_FALSE(vector.angleRad(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleDeg) {
|
||||
double a = 3.32;
|
||||
double angle45Deg = 45.0;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle45Deg, vector.angleDeg(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, angleDegSizeNotEq) {
|
||||
double a = 3.32;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_FALSE(vector.angleDeg(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, projection) {
|
||||
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_DOUBLE_EQ(res, vecProj[0]);
|
||||
ASSERT_DOUBLE_EQ(0.0, vecProj[1]);
|
||||
ASSERT_DOUBLE_EQ(res, vecProj[2]);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, projectionSizeNotEq) {
|
||||
double a = 2.0;
|
||||
double b = 2.0;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vec[0] = a;
|
||||
vec[2] = b;
|
||||
vector[0] = a;
|
||||
vector[1] = b;
|
||||
vector[2] = a;
|
||||
auto vecProj = vector.projection(vec);
|
||||
ASSERT_DOUBLE_EQ(a, vecProj[0]);
|
||||
ASSERT_DOUBLE_EQ(b, vecProj[1]);
|
||||
ASSERT_DOUBLE_EQ(a, vecProj[2]);
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, normalize) {
|
||||
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) {
|
||||
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(SIZE);
|
||||
ASSERT_TRUE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isNullFalse) {
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector[0] = 6.273;
|
||||
ASSERT_FALSE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isValidTrue) {
|
||||
PIMathVector<double> vector(SIZE);
|
||||
ASSERT_TRUE(vector.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isValidFalse) {
|
||||
PIMathVector<double> vector;
|
||||
ASSERT_FALSE(vector.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, isOrthoTrue) {
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_AssignmentValue) {
|
||||
double a = 5.5;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
vector = a;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_AssignmentVector) {
|
||||
double a = 5.5;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE);
|
||||
vec = a;
|
||||
vector = vec;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_AssignmentVectorSizeNotEq) {
|
||||
double a = 5.5;
|
||||
double b = 1.43;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector(SIZE);
|
||||
PIMathVector<double> vec(SIZE + bias);
|
||||
vector = b;
|
||||
|
zzuummaa
commented
Привести к читаемой форме. Привести к читаемой форме.
Не нужно умножать векторы 3 раза.
|
||||
vec = a;
|
||||
vector = vec;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, b, SIZE));
|
||||
|
zzuummaa
commented
Тест должен называться Тест должен называться `operator_DivisionValue`.
Написать тест `operator_DivisionVector`.
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_EqualTrue) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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_Assignment) {
|
||||
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, a + b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Addition_Assignment_sizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 += vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Subtraction_Assignment) {
|
||||
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, a - b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Subtraction_Assignment_sizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 -= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Multiplication_AssignmentValue) {
|
||||
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) {
|
||||
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, a * b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Multiplication_AssignmentVector_sizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 *= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Division_AssignmentValue) {
|
||||
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) {
|
||||
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, a / b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Division_AssignmentVector_sizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
vector1 /= vector2;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Addition) {
|
||||
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_AdditionSizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 + vector2, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_Subtraction) {
|
||||
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_SubtractionSizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 1.72;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 - vector2, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_MultiplicationValue) {
|
||||
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) {
|
||||
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) {
|
||||
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_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) {
|
||||
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_MultiplVectSizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 5.0;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector1 & vector2, a , SIZE));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
TEST(PIMathVector_Test, operator_DotProductSizeNotEq) {
|
||||
double a = 6.0;
|
||||
double b = 5.0;
|
||||
uint bias = 2u;
|
||||
PIMathVector<double> vector1(SIZE);
|
||||
PIMathVector<double> vector2(SIZE + bias);
|
||||
vector1.fill(a);
|
||||
vector2.fill(b);
|
||||
ASSERT_FALSE(vector1 ^ vector2);
|
||||
}
|
||||
510
tests/math/testpimathvectort.cpp
Normal file
@@ -0,0 +1,510 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathvector.h"
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
const uint SIZE = 3u;
|
||||
const double angle45DegInRad = 0.78539816339744830961566084581988;
|
||||
|
||||
bool cmpVectorWithValue(PIMathVectorT<SIZE, double> vector, double val, int num) {
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
if(vector[i] - val >= double(1E-200)) {
|
||||
b = false;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, size) {
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
ASSERT_TRUE(vector.size() == SIZE);
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, fill) {
|
||||
double a = 5.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector.fill(a), a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, set) {
|
||||
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) {
|
||||
double a = 4.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector.move(a), a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, MoveVector) {
|
||||
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) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a, vector.lengthSqr());
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, length) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(sqrt(SIZE * a), vector.length());
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, manhattanLength) {
|
||||
double a = 5.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
vector.fill(a);
|
||||
ASSERT_DOUBLE_EQ(SIZE * a, vector.manhattanLength());
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, angleCos) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(cos(angle45DegInRad), vector.angleCos(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, angleSin) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(sin(angle45DegInRad), vector.angleSin(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, angleRad) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle45DegInRad, vector.angleRad(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, angleDeg) {
|
||||
double a = 1.0;
|
||||
double angle45inDeg = 45.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(angle45inDeg, vector.angleDeg(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, angleElevation) {
|
||||
double a = 1.0;
|
||||
double angle45inDeg = 45.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vector[0] = a;
|
||||
vector[1] = a;
|
||||
vec[1] = a;
|
||||
ASSERT_DOUBLE_EQ(-angle45inDeg, vector.angleElevation(vec));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, projection) {
|
||||
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_DOUBLE_EQ(res, vecProj[0]);
|
||||
ASSERT_DOUBLE_EQ(0.0, vecProj[1]);
|
||||
ASSERT_DOUBLE_EQ(res, vecProj[2]);
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, normalize) {
|
||||
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) {
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
ASSERT_TRUE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, isNullFalse) {
|
||||
double a = 6.273;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
vector[0] = a;
|
||||
ASSERT_FALSE(vector.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, isOrthoTrue) {
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_AssignmentValue) {
|
||||
double a = 3.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
vector = a;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_AssignmentVector) {
|
||||
double a = 5.0;
|
||||
PIMathVectorT<SIZE, double> vector;
|
||||
PIMathVectorT<SIZE, double> vec;
|
||||
vec = a;
|
||||
vector = vec;
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_EqualTrue) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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_Assignment) {
|
||||
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, a + b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_Subtraction_Assignment) {
|
||||
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, a - b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_Multiplication_AssignmentValue) {
|
||||
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) {
|
||||
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, a * b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_Division_AssignmentValue) {
|
||||
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) {
|
||||
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, a / b, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_Addition) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
double a = 1.0;
|
||||
PIMathVectorT<SIZE, double> vector1;
|
||||
PIMathVectorT<SIZE,double> vector2;
|
||||
vector1[0] = a;
|
||||
vector2[1] = a;
|
||||
auto vect = vector1 * vector2;
|
||||
ASSERT_TRUE(vect[0] < double(1E-200));
|
||||
ASSERT_TRUE(vect[1] < double(1E-200));
|
||||
ASSERT_TRUE(vect[2] - a < double(1E-200));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, operator_DivisionVal) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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] != a)
|
||||
{
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, filled) {
|
||||
double a = 6.0;
|
||||
auto vector = PIMathVectorT<SIZE, double>::filled(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(vector, a, SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, turnTo) {
|
||||
double a = 6.0;
|
||||
PIMathVectorT<SIZE, double> vect;
|
||||
vect.fill(a);
|
||||
auto vector = vect.turnTo<2u, double>();
|
||||
ASSERT_TRUE(vector.size() == 2);
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, LogicalOrTrue) {
|
||||
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) {
|
||||
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) {
|
||||
double a = 36.0;
|
||||
PIMathVectorT<SIZE, double> vector1;
|
||||
vector1.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(sqrt(vector1), sqrt(a), SIZE));
|
||||
}
|
||||
|
||||
TEST(PIMathVectorT_Test, sqr) {
|
||||
double a = 6.0;
|
||||
PIMathVectorT<SIZE, double> vector1;
|
||||
vector1.fill(a);
|
||||
ASSERT_TRUE(cmpVectorWithValue(sqr(vector1), sqr(a), SIZE));
|
||||
}
|
||||
здесь бь надо поменять на
const Type &