Merge pull request 'tests' (#36) from tests into master

Reviewed-on: https://git.shs.tools/SHS/pip/pulls/36
This commit was merged in pull request #36.
This commit is contained in:
2020-09-15 15:40:56 +03:00
6 changed files with 4564 additions and 1161 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
/.svn /.svn
/doc/rtf /doc/rtf
_unsused _unsused
CMakeLists.txt.user*

View File

@@ -1,5 +1,7 @@
/*! \file pimathmatrix.h /*! \file pimathmatrix.h
* \brief PIMathMatrix * \brief PIMathMatrix
*
* This file declare math matrix class, which performs various matrix operations
*/ */
/* /*
PIP - Platform Independent Primitives PIP - Platform Independent Primitives
@@ -26,18 +28,35 @@
#include "pimathvector.h" #include "pimathvector.h"
#include "pimathcomplex.h" #include "pimathcomplex.h"
/**
* @brief Inline funtion of compare with zero different types
*
* @param v is input parameter of type T
* @return true if zero, false if not zero
*/
template<typename T> template<typename T>
inline bool _PIMathMatrixNullCompare(const T v) { inline bool _PIMathMatrixNullCompare(const T v) {
static_assert(std::is_floating_point<T>::value, "Type must be floating point"); static_assert(std::is_floating_point<T>::value, "Type must be floating point");
return (piAbs(v) < T(1E-200)); return (piAbs(v) < T(1E-200));
} }
/**
* @brief Inline funtion of compare with zero colmplexf type
*
* @param v is input parameter of type colmplexf
* @return true if zero, false if not zero
*/
template<> template<>
inline bool _PIMathMatrixNullCompare<complexf>(const complexf v) { inline bool _PIMathMatrixNullCompare<complexf>(const complexf v) {
return (abs(v) < float(1E-200)); return (abs(v) < float(1E-200));
} }
/**
* @brief Inline funtion of compare with zero complexd type
*
* @param v is input parameter of type colmplexd
* @return true if zero, false if not zero
*/
template<> template<>
inline bool _PIMathMatrixNullCompare<complexd>(const complexd v) { inline bool _PIMathMatrixNullCompare<complexd>(const complexd v) {
return (abs(v) < double(1E-200)); return (abs(v) < double(1E-200));
@@ -54,6 +73,12 @@ inline bool _PIMathMatrixNullCompare<complexd >(const complexd v) {
#define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++v) #define PIMM_FOR_R(v) for (uint v = 0; v < Rows; ++v)
#pragma pack(push, 1) #pragma pack(push, 1)
//! \brief A class that works with square matrix operations, the input data of which are columns, rows and the data type of the matrix
//! @tparam Rows rows number of matrix
//! @tparam Сols columns number of matrix
//! @tparam Type is the data type of the matrix. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /)
//! of the C++ language are implemented
template<uint Rows, uint Cols = Rows, typename Type = double> template<uint Rows, uint Cols = Rows, typename Type = double>
class PIP_EXPORT PIMathMatrixT { class PIP_EXPORT PIMathMatrixT {
typedef PIMathMatrixT<Rows, Cols, Type> _CMatrix; typedef PIMathMatrixT<Rows, Cols, Type> _CMatrix;
@@ -64,49 +89,410 @@ class PIP_EXPORT PIMathMatrixT {
static_assert(Rows > 0, "Row count must be > 0"); static_assert(Rows > 0, "Row count must be > 0");
static_assert(Cols > 0, "Column count must be > 0"); static_assert(Cols > 0, "Column count must be > 0");
public: public:
/**
* @brief Constructor that calls the private resize method
*
* @return identitied matrix of type PIMathMatrixT
*/
PIMathMatrixT() { resize(Rows, Cols); } PIMathMatrixT() { resize(Rows, Cols); }
PIMathMatrixT(const PIVector<Type> & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];}
static _CMatrix identity() {_CMatrix tm = _CMatrix(); PIMM_FOR_WB(r, c) tm.m[r][c] = (c == r ? Type(1) : Type(0)); return tm;} /**
static _CMatrix filled(const Type & v) {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = v; return tm;} * @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
*/
PIMathMatrixT(const PIVector<Type> &val) {
resize(Rows, Cols);
int i = 0;
PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];
}
/**
* @brief Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros
*
* @return identity matrix of type PIMathMatrixT
*/
static _CMatrix identity() {
_CMatrix tm = _CMatrix();
PIMM_FOR_WB(r, c) tm.m[r][c] = (c == r ? Type(1) : Type(0));
return tm;
}
/**
* @brief Creates a matrix that is filled with elements
*
* @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
*/
static _CMatrix filled(const Type &v) {
_CMatrix tm;
PIMM_FOR_WB(r, c) tm.m[r][c] = v;
return tm;
}
/**
* @brief Rotation the matrix by an "angle". Works only with 2x2 matrix,
* else return default construction of PIMathMatrixT
*
* @param angle is the angle of rotation of the matrix
* @return rotated matrix
*/
static _CMatrix rotation(double angle) { return _CMatrix(); } static _CMatrix rotation(double angle) { return _CMatrix(); }
/**
* @brief Rotation of the matrix by an "angle" along the X axis. Works only with 3x3 matrix,
* else return default construction of PIMathMatrixT
*
* @param angle is the angle of rotation of the matrix along the X axis
* @return rotated matrix
*/
static _CMatrix rotationX(double angle) { return _CMatrix(); } static _CMatrix rotationX(double angle) { return _CMatrix(); }
/**
* @brief Rotation of the matrix by an "angle" along the Y axis. Works only with 3x3 matrix,
* else return default construction of PIMathMatrixT
*
* @param angle is the angle of rotation of the matrix along the Y axis
* @return rotated matrix
*/
static _CMatrix rotationY(double angle) { return _CMatrix(); } static _CMatrix rotationY(double angle) { return _CMatrix(); }
/**
* @brief Rotation of the matrix by an "angle" along the Z axis. Works only with 3x3 matrix,
* else return default construction of PIMathMatrixT
*
* @param angle is the angle of rotation of the matrix along the Z axis
* @return rotated matrix
*/
static _CMatrix rotationZ(double angle) { return _CMatrix(); } static _CMatrix rotationZ(double angle) { return _CMatrix(); }
/**
* @brief Scaling the matrix along the X axis by the value "factor". Works only with 3x3 and 2x2 matrix,
* else return default construction of PIMathMatrixT
*
* @param factor is the value of scaling by X axis
* @return rotated matrix
*/
static _CMatrix scaleX(double factor) { return _CMatrix(); } static _CMatrix scaleX(double factor) { return _CMatrix(); }
/**
* @brief Scaling the matrix along the Y axis by the value "factor". Works only with 3x3 and 2x2 matrix,
* else return default construction of PIMathMatrixT
*
* @param factor is the value of scaling by Y axis
* @return rotated matrix
*/
static _CMatrix scaleY(double factor) { return _CMatrix(); } static _CMatrix scaleY(double factor) { return _CMatrix(); }
/**
* @brief Scaling the matrix along the Z axis by the value "factor". Works only with 3x3 matrix,
* else return default construction of PIMathMatrixT
*
* @param factor is the value of scaling by Z axis
* @return rotated matrix
*/
static _CMatrix scaleZ(double factor) { return _CMatrix(); } static _CMatrix scaleZ(double factor) { return _CMatrix(); }
/**
* @brief Method which returns number of columns in matrix
*
* @return type uint shows number of columns
*/
uint cols() const { return Cols; } uint cols() const { return Cols; }
/**
* @brief Method which returns number of rows in matrix
*
* @return type uint shows number of rows
*/
uint rows() const { return Rows; } uint rows() const { return Rows; }
_CMCol col(uint index) {_CMCol tv; PIMM_FOR_R(i) tv[i] = m[i][index]; return tv;}
_CMRow row(uint index) {_CMRow tv; PIMM_FOR_C(i) tv[i] = m[index][i]; return tv;} /**
_CMatrix & setCol(uint index, const _CMCol & v) {PIMM_FOR_R(i) m[i][index] = v[i]; return *this;} * @brief Method which returns the selected column in PIMathVectorT format.
_CMatrix & setRow(uint index, const _CMRow & v) {PIMM_FOR_C(i) m[index][i] = v[i]; return *this;} * If you enter an index out of the border of the matrix there will be "undefined behavior"
_CMatrix & swapRows(uint r0, uint r1) {Type t; PIMM_FOR_C(i) {t = m[r0][i]; m[r0][i] = m[r1][i]; m[r1][i] = t;} return *this;} *
_CMatrix & swapCols(uint c0, uint c1) {Type t; PIMM_FOR_R(i) {t = m[i][c0]; m[i][c0] = m[i][c1]; m[i][c1] = t;} return *this;} * @param index is the number of the selected column
_CMatrix & fill(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] = v; return *this;} * @return column in PIMathVectorT format
*/
_CMCol col(uint index) {
_CMCol tv;
PIMM_FOR_R(i) tv[i] = m[i][index];
return tv;
}
/**
* @brief Method which returns the selected row 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
* @return row in PIMathVectorT format
*/
_CMRow row(uint index) {
_CMRow tv;
PIMM_FOR_C(i) tv[i] = m[index][i];
return tv;
}
/**
* @brief Set the selected column in 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
*/
_CMatrix &setCol(uint index, const _CMCol &v) {
PIMM_FOR_R(i) m[i][index] = v[i];
return *this;
}
/**
* @brief Set the selected row in 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
*/
_CMatrix &setRow(uint index, const _CMRow &v) {
PIMM_FOR_C(i) m[index][i] = v[i];
return *this;
}
/**
* @brief Method which changes selected rows in a 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
*/
_CMatrix &swapRows(uint r0, uint r1) {
Type t;
PIMM_FOR_C(i) {
t = m[r0][i];
m[r0][i] = m[r1][i];
m[r1][i] = t;
}
return *this;
}
/**
* @brief Method which changes selected columns in a 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
*/
_CMatrix &swapCols(uint c0, uint c1) {
Type t;
PIMM_FOR_R(i) {
t = m[i][c0];
m[i][c0] = m[i][c1];
m[i][c1] = t;
}
return *this;
}
/**
* @brief Method which fills the matrix 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
*/
_CMatrix &fill(const Type &v) {
PIMM_FOR_WB(r, c) m[r][c] = v;
return *this;
}
/**
* @brief Method which checks if matrix is square
*
* @return true if matrix is square, else false
*/
bool isSquare() const { return cols() == rows(); } bool isSquare() const { return cols() == rows(); }
bool isIdentity() const {PIMM_FOR_WB(r, c) if ((c == r) ? m[r][c] != Type(1) : m[r][c] != Type(0)) return false; return true;}
bool isNull() const {PIMM_FOR_WB(r, c) if (m[r][c] != Type(0)) return false; return true;}
/**
* @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros
*
* @return true if matrix is identitied, else false
*/
bool isIdentity() const {
PIMM_FOR_WB(r, c) if ((c == r) ? m[r][c] != Type(1) : m[r][c] != Type(0)) return false;
return true;
}
/**
* @brief Method which checks if every elements of matrix are zeros
*
* @return true if matrix is null, else false
*/
bool isNull() const {
PIMM_FOR_WB(r, c) if (m[r][c] != Type(0)) return false;
return true;
}
/**
* @brief Full access to elements reference 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 reference to element of matrix by row "row" and col "col"
*/
Type &at(uint row, uint col) { return m[row][col]; } Type &at(uint row, uint col) { return m[row][col]; }
Type at(uint row, uint col) const {return m[row][col];}
Type * operator [](uint row) {return m[row];}
const Type * operator [](uint row) const {return m[row];}
_CMatrix & operator =(const _CMatrix & sm) {memcpy(m, sm.m, sizeof(Type) * Cols * Rows); return *this;}
bool operator ==(const _CMatrix & sm) const {PIMM_FOR_WB(r, c) if (m[r][c] != sm.m[r][c]) return false; return true;}
bool operator !=(const _CMatrix & sm) const {return !(*this == sm);}
void operator +=(const _CMatrix & sm) {PIMM_FOR_WB(r, c) m[r][c] += sm.m[r][c];}
void operator -=(const _CMatrix & sm) {PIMM_FOR_WB(r, c) m[r][c] -= sm.m[r][c];}
void operator *=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] *= v;}
void operator /=(const Type & v) {PIMM_FOR_WB(r, c) m[r][c] /= v;}
_CMatrix operator -() const {_CMatrix tm; PIMM_FOR_WB(r, c) tm.m[r][c] = -m[r][c]; return tm;}
_CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] += sm.m[r][c]; return tm;}
_CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] -= sm.m[r][c]; return tm;}
_CMatrix operator *(const Type & v) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] *= v; return tm;}
_CMatrix operator /(const Type & v) const {_CMatrix tm = _CMatrix(*this); PIMM_FOR_WB(r, c) tm.m[r][c] /= v; return tm;}
/**
* @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]; }
/**
* @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"
*
* @param row is a row of necessary matrix
* @return matrix row pointer
*/
Type *operator[](uint row) { return m[row]; }
/**
* @brief Read-only access to the matrix row pointer. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param row is a row of necessary matrix
* @return matrix row pointer
*/
const Type *operator[](uint row) const { return m[row]; }
/**
* @brief Matrix assignment to matrix "sm"
*
* @param sm matrix for the assigment
* @return matrix equal with sm
*/
_CMatrix &operator=(const _CMatrix &sm) {
memcpy(m, sm.m, sizeof(Type) * Cols * Rows);
return *this;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are equal true, else false
*/
bool operator==(const _CMatrix &sm) const {
PIMM_FOR_WB(r, c) if (m[r][c] != sm.m[r][c]) return false;
return true;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix 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"
*
* @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"
*
* @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"
*
* @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"
*
* @param v value for the division assigment
*/
void operator/=(const Type &v) { PIMM_FOR_WB(r, c) m[r][c] /= v; }
/**
* @brief Matrix substraction
*
* @return the result of matrix substraction
*/
_CMatrix operator-() const {
_CMatrix tm;
PIMM_FOR_WB(r, c) tm.m[r][c] = -m[r][c];
return tm;
}
/**
* @brief Matrix addition
*
* @param sm is matrix term
* @return the result of matrix addition
*/
_CMatrix operator+(const _CMatrix &sm) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] += sm.m[r][c];
return tm;
}
/**
* @brief Matrix substraction
*
* @param sm is matrix subtractor
* @return the result of matrix substraction
*/
_CMatrix operator-(const _CMatrix &sm) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] -= sm.m[r][c];
return tm;
}
/**
* @brief Matrix multiplication
*
* @param v is value factor
* @return the result of matrix multiplication
*/
_CMatrix operator*(const Type &v) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] *= v;
return tm;
}
/**
* @brief Matrix division
*
* @param v is value divider
* @return the result of matrix division
*/
_CMatrix operator/(const Type &v) const {
_CMatrix tm = _CMatrix(*this);
PIMM_FOR_WB(r, c) tm.m[r][c] /= v;
return tm;
}
/**
* @brief Determinant of the matrix is calculated. 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 matrix determinant
*/
Type determinant(bool *ok = 0) const { Type determinant(bool *ok = 0) const {
_CMatrix m(*this); _CMatrix m(*this);
bool k; bool k;
@@ -122,6 +508,12 @@ public:
return ret; return ret;
} }
/**
* @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
*/
_CMatrix &toUpperTriangular(bool *ok = 0) { _CMatrix &toUpperTriangular(bool *ok = 0) {
if (Cols != Rows) { if (Cols != Rows) {
if (ok != 0) *ok = false; if (ok != 0) *ok = false;
@@ -159,6 +551,12 @@ public:
return *this; return *this;
} }
/**
* @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
*/
_CMatrix &invert(bool *ok = 0) { _CMatrix &invert(bool *ok = 0) {
static_assert(Cols == Rows, "Only square matrix invertable"); static_assert(Cols == Rows, "Only square matrix invertable");
_CMatrix mtmp = _CMatrix::identity(), smat(*this); _CMatrix mtmp = _CMatrix::identity(), smat(*this);
@@ -206,38 +604,157 @@ public:
memcpy(m, mtmp.m, sizeof(Type) * Cols * Rows); memcpy(m, mtmp.m, sizeof(Type) * Cols * Rows);
return *this; return *this;
} }
_CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;}
_CMatrixI transposed() const {_CMatrixI tm; PIMM_FOR_WB(r, c) tm[c][r] = m[r][c]; return tm;} /**
* @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 inverted matrix
*/
_CMatrix inverted(bool *ok = 0) const {
_CMatrix tm(*this);
tm.invert(ok);
return tm;
}
/**
* @brief Matrix transposition operation. Works only with square matrix, nonzero matrices and invertible matrix
*
* @return transposed matrix
*/
_CMatrixI transposed() const {
_CMatrixI tm;
PIMM_FOR_WB(r, c) tm[c][r] = m[r][c];
return tm;
}
private: private:
void resize(uint rows_, uint cols_, const Type & new_value = Type()) {r_ = rows_; c_ = cols_; PIMM_FOR_WB(r, c) m[r][c] = new_value;} void resize(uint rows_, uint cols_, const Type &new_value = Type()) {
r_ = rows_;
c_ = cols_;
PIMM_FOR_WB(r, c) m[r][c] = new_value;
}
int c_, r_; int c_, r_;
Type m[Rows][Cols]; Type m[Rows][Cols];
}; };
#pragma pack(pop) #pragma pack(pop)
template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<2u, 2u> tm; tm[0][0] = tm[1][1] = c; tm[0][1] = -s; tm[1][0] = s; return tm;} template<>
template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = factor; tm[1][1] = 1.; return tm;} inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::rotation(double angle) {
template<> inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) {PIMathMatrixT<2u, 2u> tm; tm[0][0] = 1.; tm[1][1] = factor; return tm;} double c = cos(angle), s = sin(angle);
PIMathMatrixT<2u, 2u> tm;
tm[0][0] = tm[1][1] = c;
tm[0][1] = -s;
tm[1][0] = s;
return tm;
}
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[0][0] = 1.; tm[1][1] = tm[2][2] = c; tm[2][1] = s; tm[1][2] = -s; return tm;} template<>
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[1][1] = 1.; tm[0][0] = tm[2][2] = c; tm[2][0] = -s; tm[0][2] = s; return tm;} inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleX(double factor) {
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) {double c = cos(angle), s = sin(angle); PIMathMatrixT<3u, 3u> tm; tm[2][2] = 1.; tm[0][0] = tm[1][1] = c; tm[1][0] = s; tm[0][1] = -s; return tm;} PIMathMatrixT<2u, 2u> tm;
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) {PIMathMatrixT<3u, 3u> tm; tm[1][1] = tm[2][2] = 1.; tm[0][0] = factor; return tm;} tm[0][0] = factor;
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[2][2] = 1.; tm[1][1] = factor; return tm;} tm[1][1] = 1.;
template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;} return tm;
}
template<>
inline PIMathMatrixT<2u, 2u> PIMathMatrixT<2u, 2u>::scaleY(double factor) {
PIMathMatrixT<2u, 2u> tm;
tm[0][0] = 1.;
tm[1][1] = factor;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationX(double angle) {
double c = cos(angle), s = sin(angle);
PIMathMatrixT<3u, 3u> tm;
tm[0][0] = 1.;
tm[1][1] = tm[2][2] = c;
tm[2][1] = s;
tm[1][2] = -s;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationY(double angle) {
double c = cos(angle), s = sin(angle);
PIMathMatrixT<3u, 3u> tm;
tm[1][1] = 1.;
tm[0][0] = tm[2][2] = c;
tm[2][0] = -s;
tm[0][2] = s;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::rotationZ(double angle) {
double c = cos(angle), s = sin(angle);
PIMathMatrixT<3u, 3u> tm;
tm[2][2] = 1.;
tm[0][0] = tm[1][1] = c;
tm[1][0] = s;
tm[0][1] = -s;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double factor) {
PIMathMatrixT<3u, 3u> tm;
tm[1][1] = tm[2][2] = 1.;
tm[0][0] = factor;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {
PIMathMatrixT<3u, 3u> tm;
tm[0][0] = tm[2][2] = 1.;
tm[1][1] = factor;
return tm;
}
template<>
inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {
PIMathMatrixT<3u, 3u> tm;
tm[0][0] = tm[1][1] = 1.;
tm[2][2] = factor;
return tm;
}
#ifdef PIP_STD_IOSTREAM #ifdef PIP_STD_IOSTREAM
template<uint Rows, uint Cols, typename Type> template<uint Rows, uint Cols, typename Type>
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << " ";} s << "}"; return s;} inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << " ";} s << "}"; return s;}
#endif #endif
/**
* @brief Add matrix "m" at the end of matrix and return reference to matrix
*
* @param s PICout type
* @param m PIMathMatrixT type
* @return bitwise left PICout
*/
template<uint Rows, uint Cols, typename Type> template<uint Rows, uint Cols, typename Type>
inline PICout operator <<(PICout s, const PIMathMatrixT<Rows, Cols, Type> & m) {s << "{"; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} inline PICout operator<<(PICout s, const PIMathMatrixT<Rows, Cols, Type> &m) {
s << "{";
PIMM_FOR_I(r, c) s << m[r][c];
if (c < Cols - 1 || r < Rows - 1) s << ", "; }
if (r < Rows - 1) s << PICoutManipulators::NewLine << " "; }
s << "}";
return s;
}
/// Multiply matrices {Rows0 x CR} on {CR x Cols1}, result is {Rows0 x Cols1} /**
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param fm first matrix multiplier
* @param sm second matrix multiplier
* @return matrix that is the result of multiplication
*/
template<uint CR, uint Rows0, uint Cols1, typename Type> template<uint CR, uint Rows0, uint Cols1, typename Type>
inline PIMathMatrixT<Rows0, Cols1, Type> operator*(const PIMathMatrixT<Rows0, CR, Type> &fm, inline PIMathMatrixT<Rows0, Cols1, Type> operator*(const PIMathMatrixT<Rows0, CR, Type> &fm,
const PIMathMatrixT<CR, Cols1, Type> &sm) { const PIMathMatrixT<CR, Cols1, Type> &sm) {
@@ -254,7 +771,13 @@ inline PIMathMatrixT<Rows0, Cols1, Type> operator *(const PIMathMatrixT<Rows0, C
return tm; return tm;
} }
/// Multiply matrix {Rows x Cols} on vector {Cols}, result is vector {Rows} /**
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param fm first matrix multiplier
* @param sv second vector multiplier
* @return vector that is the result of multiplication
*/
template<uint Cols, uint Rows, typename Type> template<uint Cols, uint Rows, typename Type>
inline PIMathVectorT<Rows, Type> operator*(const PIMathMatrixT<Rows, Cols, Type> &fm, inline PIMathVectorT<Rows, Type> operator*(const PIMathMatrixT<Rows, Cols, Type> &fm,
const PIMathVectorT<Cols, Type> &sv) { const PIMathVectorT<Cols, Type> &sv) {
@@ -269,7 +792,13 @@ inline PIMathVectorT<Rows, Type> operator *(const PIMathMatrixT<Rows, Cols, Type
return tv; return tv;
} }
/// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols} /**
* @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param sv first vector multiplier
* @param fm second matrix multiplier
* @return vector that is the result of multiplication
*/
template<uint Cols, uint Rows, typename Type> template<uint Cols, uint Rows, typename Type>
inline PIMathVectorT<Cols, Type> operator*(const PIMathVectorT<Rows, Type> &sv, inline PIMathVectorT<Cols, Type> operator*(const PIMathVectorT<Rows, Type> &sv,
const PIMathMatrixT<Rows, Cols, Type> &fm) { const PIMathMatrixT<Rows, Cols, Type> &fm) {
@@ -284,7 +813,13 @@ inline PIMathVectorT<Cols, Type> operator *(const PIMathVectorT<Rows, Type> & sv
return tv; return tv;
} }
/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} /**
* @brief Multiplying value of type Type and matrix
*
* @param x first multiplier of type Type
* @param fm second matrix multiplier
* @return matrix that is the result of multiplication
*/
template<uint Cols, uint Rows, typename Type> template<uint Cols, uint Rows, typename Type>
inline PIMathMatrixT<Rows, Cols, Type> operator*(const Type &x, const PIMathMatrixT<Rows, Cols, Type> &v) { inline PIMathMatrixT<Rows, Cols, Type> operator*(const Type &x, const PIMathMatrixT<Rows, Cols, Type> &v) {
return v * x; return v * x;
@@ -321,52 +856,309 @@ class PIMathMatrix;
#define PIMM_FOR_C(v) for (uint v = 0; v < _V2D::cols_; ++v) #define PIMM_FOR_C(v) for (uint v = 0; v < _V2D::cols_; ++v)
#define PIMM_FOR_R(v) for (uint v = 0; v < _V2D::rows_; ++v) #define PIMM_FOR_R(v) for (uint v = 0; v < _V2D::rows_; ++v)
//! \brief A class that works with matrix operations, the input data of which is the data type of the matrix
//! @tparam There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /)
//! of the C++ language are implemented
template<typename Type> template<typename Type>
class PIP_EXPORT PIMathMatrix : public PIVector2D<Type> { class PIP_EXPORT PIMathMatrix : public PIVector2D<Type> {
typedef PIVector2D<Type> _V2D; typedef PIVector2D<Type> _V2D;
typedef PIMathMatrix<Type> _CMatrix; typedef PIMathMatrix<Type> _CMatrix;
typedef PIMathVector<Type> _CMCol; typedef PIMathVector<Type> _CMCol;
public: public:
/**
* @brief Constructor of class PIMathMatrix, which creates a matrix
*
* @param cols is number of matrix column uint type
* @param rows is number of matrix row uint type
* @param f is type of matrix elements
*/
PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); } PIMathMatrix(const uint cols = 0, const uint rows = 0, const Type &f = Type()) { _V2D::resize(rows, cols, f); }
PIMathMatrix(const uint cols, const uint rows, const PIVector<Type> & val) {_V2D::resize(rows, cols); int i=0; PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];}
PIMathMatrix(const PIVector<PIVector<Type> > & val) {if(!val.isEmpty()) {_V2D::resize(val.size(), val[0].size()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];}}
PIMathMatrix(const PIVector2D<Type> & val) {if(!val.isEmpty()) {_V2D::resize(val.rows(), val.cols()); PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);}}
static _CMatrix identity(const uint cols, const uint rows) {_CMatrix tm(cols, rows); for (uint r = 0; r < rows; ++r) for (uint c = 0; c < cols; ++c) tm.element(r, c) = (c == r ? Type(1) : Type(0)); return tm;} /**
* @brief Constructor of class PIMathMatrix, which creates a matrix
*
* @param cols is number of matrix column uint type
* @param rows is number of matrix row uint type
* @param val is PIVector<Type> of matrix elements
*/
PIMathMatrix(const uint cols, const uint rows, const PIVector<Type> &val) {
_V2D::resize(rows, cols);
int i = 0;
PIMM_FOR_I(c, r) _V2D::element(r, c) = val[i++];
}
/**
* @brief Constructor of class PIMathMatrix, which creates a matrix
*
* @param val is PIVector<Type> of PIVector, which creates matrix
*/
PIMathMatrix(const PIVector<PIVector<Type> > &val) {
if (!val.isEmpty()) {
_V2D::resize(val.size(), val[0].size());
PIMM_FOR_I(c, r) _V2D::element(r, c) = val[r][c];
}
}
/**
* @brief Constructor of class PIMathMatrix, which creates a matrix
*
* @param val is PIVector2D<Type>, which creates matrix
*/
PIMathMatrix(const PIVector2D<Type> &val) {
if (!val.isEmpty()) {
_V2D::resize(val.rows(), val.cols());
PIMM_FOR_I(c, r) _V2D::element(r, c) = val.element(r, c);
}
}
/**
* @brief Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros
*
* @param cols is number of matrix column uint type
* @param rows is number of matrix row uint type
* @return identity matrix of type PIMathMatrix
*/
static _CMatrix identity(const uint cols, const uint rows) {
_CMatrix tm(cols, rows);
for (uint r = 0; r < rows; ++r) for (uint c = 0; c < cols; ++c) tm.element(r, c) = (c == r ? Type(1) : Type(0));
return tm;
}
/**
* @brief Creates a row matrix of every element that is equal to every element of the vector
*
* @param val is the vector type PIMathVector
* @return row matrix of every element that is equal to every element of the vector
*/
static _CMatrix matrixRow(const PIMathVector<Type> &val) { return _CMatrix(val.size(), 1, val.toVector()); } static _CMatrix matrixRow(const PIMathVector<Type> &val) { return _CMatrix(val.size(), 1, val.toVector()); }
/**
* @brief Creates a column matrix of every element that is equal to every element of the vector
*
* @param val is the vector type PIMathVector
* @return column matrix of every element that is equal to every element of the vector
*/
static _CMatrix matrixCol(const PIMathVector<Type> &val) { return _CMatrix(1, val.size(), val.toVector()); } static _CMatrix matrixCol(const PIMathVector<Type> &val) { return _CMatrix(1, val.size(), val.toVector()); }
_CMatrix & setCol(uint index, const _CMCol & v) {PIMM_FOR_R(i) _V2D::element(i, index) = v[i]; return *this;} /**
_CMatrix & setRow(uint index, const _CMCol & v) {PIMM_FOR_C(i) _V2D::element(index, i) = v[i]; return *this;} * @brief Set the selected column in matrix. If there are more elements of the vector than elements in the column of the matrix
_CMatrix & swapCols(uint r0, uint r1) {PIMM_FOR_C(i) {piSwap(_V2D::element(i, r0), _V2D::element(i, r1));} return *this;} * or index larger than the number of columns otherwise there will be "undefined behavior"
_CMatrix & swapRows(uint c0, uint c1) {PIMM_FOR_R(i) {piSwap(_V2D::element(c0, i), _V2D::element(c1, i));} return *this;} *
_CMatrix & fill(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] = v; return *this;} * @param index is the number of the selected column
bool isSquare() const {return _V2D::cols_ == _V2D::rows_;} * @param v is a vector of the type _CMCol that needs to fill the column
bool isIdentity() const {PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0)) return false; return true;} * @return matrix type _CMatrix
bool isNull() const {PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false; return true;} */
bool isValid() const {return !PIVector2D<Type>::isEmpty();} _CMatrix &setCol(uint index, const _CMCol &v) {
PIMM_FOR_R(i) _V2D::element(i, index) = v[i];
_CMatrix & operator =(const PIVector<PIVector<Type> > & v) {*this = _CMatrix(v); return *this;} return *this;
bool operator ==(const _CMatrix & sm) const {
if(_V2D::mat.size() != sm.mat.size())
return false;
PIMM_FOR_A(i) {
if (_V2D::mat[i] != sm.mat[i])
return false;
} }
/**
* @brief Set the selected row in 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
*/
_CMatrix &setRow(uint index, const _CMCol &v) {
PIMM_FOR_C(i) _V2D::element(index, i) = v[i];
return *this;
}
/**
* @brief Method which replace selected columns in a 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
*/
_CMatrix &swapCols(uint r0, uint r1) {
PIMM_FOR_C(i) { piSwap(_V2D::element(i, r0), _V2D::element(i, r1)); }
return *this;
}
/**
* @brief Method which replace selected rows in a 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
*/
_CMatrix &swapRows(uint c0, uint c1) {
PIMM_FOR_R(i) { piSwap(_V2D::element(c0, i), _V2D::element(c1, i)); }
return *this;
}
/**
* @brief Method which fills the matrix 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
*/
_CMatrix &fill(const Type &v) {
PIMM_FOR_A(i) _V2D::mat[i] = v;
return *this;
}
/**
* @brief Method which checks if matrix is square
*
* @return true if matrix is square, else false
*/
bool isSquare() const { return _V2D::cols_ == _V2D::rows_; }
/**
* @brief Method which checks if main diagonal of matrix consists of ones and another elements are zeros
*
* @return true if matrix is identity, else false
*/
bool isIdentity() const {
PIMM_FOR(c, r) if ((c == r) ? _V2D::element(r, c) != Type(1) : _V2D::element(r, c) != Type(0))return false;
return true; return true;
} }
bool operator !=(const _CMatrix & sm) const {return !(*this == sm);}
void operator +=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] += sm.mat[i];}
void operator -=(const _CMatrix & sm) {PIMM_FOR_A(i) _V2D::mat[i] -= sm.mat[i];}
void operator *=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] *= v;}
void operator /=(const Type & v) {PIMM_FOR_A(i) _V2D::mat[i] /= v;}
_CMatrix operator -() const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i]; return tm;}
_CMatrix operator +(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] += sm.mat[i]; return tm;}
_CMatrix operator -(const _CMatrix & sm) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i]; return tm;}
_CMatrix operator *(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] *= v; return tm;}
_CMatrix operator /(const Type & v) const {_CMatrix tm(*this); PIMM_FOR_A(i) tm.mat[i] /= v; return tm;}
/**
* @brief Method which checks if every elements of matrix are zeros
*
* @return true if matrix elements equal to zero, else false
*/
bool isNull() const {
PIMM_FOR_A(i) if (_V2D::mat[i] != Type(0)) return false;
return true;
}
/**
* @brief Method which checks if matrix is empty
*
* @return true if matrix is valid, else false
*/
bool isValid() const { return !PIVector2D<Type>::isEmpty(); }
/**
* @brief Matrix assignment to matrix "v"
*
* @param v matrix for the assigment
* @return matrix equal with v
*/
_CMatrix &operator=(const PIVector<PIVector<Type> > &v) {
*this = _CMatrix(v);
return *this;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix for the compare
* @return if matrices are equal true, else false
*/
bool operator==(const _CMatrix &sm) const {
PIMM_FOR_A(i) if (_V2D::mat[i] != sm.mat[i]) return false;
return true;
}
/**
* @brief Compare with matrix "sm"
*
* @param sm matrix 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"
*
* @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"
*
* @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"
*
* @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"
*
* @param v value for the division assigment
*/
void operator/=(const Type &v) { PIMM_FOR_A(i) _V2D::mat[i] /= v; }
/**
* @brief Matrix substraction
*
* @return the result of matrix substraction
*/
_CMatrix operator-() const {
_CMatrix tm(*this);
PIMM_FOR_A(i) tm.mat[i] = -_V2D::mat[i];
return tm;
}
/**
* @brief Matrix addition
*
* @param sm is matrix term
* @return the result of matrix addition
*/
_CMatrix operator+(const _CMatrix &sm) const {
_CMatrix tm(*this);
PIMM_FOR_A(i) tm.mat[i] += sm.mat[i];
return tm;
}
/**
* @brief Matrix subtraction
*
* @param sm is matrix subtractor
* @return the result of matrix subtraction
*/
_CMatrix operator-(const _CMatrix &sm) const {
_CMatrix tm(*this);
PIMM_FOR_A(i) tm.mat[i] -= sm.mat[i];
return tm;
}
/**
* @brief Matrix multiplication
*
* @param v is value factor
* @return the result of matrix multiplication
*/
_CMatrix operator*(const Type &v) const {
_CMatrix tm(*this);
PIMM_FOR_A(i) tm.mat[i] *= v;
return tm;
}
/**
* @brief Matrix division
*
* @param v is value divider
* @return the result of matrix division
*/
_CMatrix operator/(const Type &v) const {
_CMatrix tm(*this);
PIMM_FOR_A(i) tm.mat[i] /= v;
return tm;
}
/**
* @brief Determinant of the self matrix is calculated. 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 matrix determinant
*/
Type determinant(bool *ok = 0) const { Type determinant(bool *ok = 0) const {
_CMatrix m(*this); _CMatrix m(*this);
bool k; bool k;
@@ -382,6 +1174,12 @@ public:
return ret; return ret;
} }
/**
* @brief Trace of the matrix is calculated. 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 matrix trace
*/
Type trace(bool *ok = 0) const { Type trace(bool *ok = 0) const {
Type ret = Type(0); Type ret = Type(0);
if (!isSquare()) { if (!isSquare()) {
@@ -395,6 +1193,12 @@ public:
return ret; return ret;
} }
/**
* @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
*/
_CMatrix &toUpperTriangular(bool *ok = 0) { _CMatrix &toUpperTriangular(bool *ok = 0) {
if (!isSquare()) { if (!isSquare()) {
if (ok != 0) *ok = false; if (ok != 0) *ok = false;
@@ -432,6 +1236,13 @@ public:
return *this; return *this;
} }
/**
* @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
* @param sv is a vector multiplier
* @return copy of inverted matrix
*/
_CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) { _CMatrix &invert(bool *ok = 0, _CMCol *sv = 0) {
if (!isSquare()) { if (!isSquare()) {
if (ok != 0) *ok = false; if (ok != 0) *ok = false;
@@ -486,8 +1297,29 @@ public:
PIVector2D<Type>::swap(mtmp); PIVector2D<Type>::swap(mtmp);
return *this; return *this;
} }
_CMatrix inverted(bool * ok = 0) const {_CMatrix tm(*this); tm.invert(ok); return tm;}
_CMatrix transposed() const {_CMatrix tm(_V2D::rows_, _V2D::cols_); PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c); return tm;} /**
* @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 inverted matrix
*/
_CMatrix inverted(bool *ok = 0) const {
_CMatrix tm(*this);
tm.invert(ok);
return tm;
}
/**
* @brief Matrix transposition operation
*
* @return transposed matrix
*/
_CMatrix transposed() const {
_CMatrix tm(_V2D::rows_, _V2D::cols_);
PIMM_FOR(c, r) tm.element(c, r) = _V2D::element(r, c);
return tm;
}
}; };
@@ -496,16 +1328,61 @@ template<typename Type>
inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m) {s << "{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << " ";} s << "}"; return s;} inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix<Type> & m) {s << "{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << " ";} s << "}"; return s;}
#endif #endif
/**
* @brief Inline operator for outputting the matrix to the console
*
* @param s PICout type
* @param the matrix type PIMathMatrix that we print to the console
* @return PIMathMatrix printed to the console
*/
template<typename Type> template<typename Type>
inline PICout operator <<(PICout s, const PIMathMatrix<Type> & m) {s << "Matrix{"; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m.element(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " ";} s << "}"; return s;} inline PICout operator<<(PICout s, const PIMathMatrix<Type> &m) {
s << "Matrix{";
for (uint r = 0; r < m.rows(); ++r) {
for (uint c = 0; c < m.cols(); ++c) {
s << m.element(r, c);
if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";
}
if (r < m.rows() - 1) s << PICoutManipulators::NewLine << " ";
}
s << "}";
return s;
}
/**
* @brief Inline operator for serializing a matrix into a PIByteArray
*
* @param s PIByteArray type
* @param v PIMathMatrix type
* @return PIBiteArray serialized PIMathMatrix
*/
template<typename Type> template<typename Type>
inline PIByteArray & operator <<(PIByteArray & s, const PIMathMatrix<Type> & v) {s << (const PIVector2D<Type> &)v; return s;} inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
s << (const PIVector2D<Type> &) v;
return s;
}
/**
* @brief Inline operator to deserialize matrix from PIByteArray
*
* @param s PIByteArray type
* @param v PIMathMatrix type
* @return PIMathMatrix deserialized from PIByteArray
*/
template<typename Type> template<typename Type>
inline PIByteArray & operator >>(PIByteArray & s, PIMathMatrix<Type> & v) {s >> (PIVector2D<Type> &)v; return s;} inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix<Type> &v) {
s >> (PIVector2D<Type> &) v;
return s;
}
/// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0} /**
* @brief Multiplying matrices by each other. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param fm first matrix multiplier
* @param sm second matrix multiplier
* @return matrix that is the result of multiplication
*/
template<typename Type> template<typename Type>
inline PIMathMatrix<Type> operator*(const PIMathMatrix<Type> &fm, inline PIMathMatrix<Type> operator*(const PIMathMatrix<Type> &fm,
const PIMathMatrix<Type> &sm) { const PIMathMatrix<Type> &sm) {
@@ -524,7 +1401,13 @@ inline PIMathMatrix<Type> operator *(const PIMathMatrix<Type> & fm,
return tm; return tm;
} }
/// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows} /**
* @brief Multiplying matrix and vector. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param fm first matrix multiplier
* @param sv second vector multiplier
* @return vector that is the result of multiplication
*/
template<typename Type> template<typename Type>
inline PIMathVector<Type> operator*(const PIMathMatrix<Type> &fm, inline PIMathVector<Type> operator*(const PIMathMatrix<Type> &fm,
const PIMathVector<Type> &sv) { const PIMathVector<Type> &sv) {
@@ -541,8 +1424,13 @@ inline PIMathVector<Type> operator *(const PIMathMatrix<Type> & fm,
return tv; return tv;
} }
/**
/// Multiply vector {Rows} on matrix {Rows x Cols}, result is vector {Cols} * @brief Multiplying vector and matrix. If you enter an index out of the border of the matrix there will be "undefined behavior"
*
* @param sv first vector multiplier
* @param fm second matrix multiplier
* @return vector that is the result of multiplication
*/
template<typename Type> template<typename Type>
inline PIMathVector<Type> operator*(const PIMathVector<Type> &sv, inline PIMathVector<Type> operator*(const PIMathVector<Type> &sv,
const PIMathMatrix<Type> &fm) { const PIMathMatrix<Type> &fm) {
@@ -558,7 +1446,13 @@ inline PIMathVector<Type> operator *(const PIMathVector<Type> & sv,
return tv; return tv;
} }
/// Multiply value(T) on matrix {Rows x Cols}, result is vector {Rows} /**
* @brief Multiplying value of type Type and matrix
*
* @param x first multiplier of type Type
* @param fm second matrix multiplier
* @return matrix that is the result of multiplication
*/
template<typename Type> template<typename Type>
inline PIMathMatrix<Type> operator*(const Type &x, const PIMathMatrix<Type> &v) { inline PIMathMatrix<Type> operator*(const Type &x, const PIMathMatrix<Type> &v) {
return v * x; return v * x;
@@ -567,10 +1461,18 @@ inline PIMathMatrix<Type> operator *(const Type & x, const PIMathMatrix<Type> &
typedef PIMathMatrix<int> PIMathMatrixi; typedef PIMathMatrix<int> PIMathMatrixi;
typedef PIMathMatrix<double> PIMathMatrixd; typedef PIMathMatrix<double> PIMathMatrixd;
/**
* @brief Searching hermitian matrix
*
* @param m conjugate transpose matrix
* @return result of the hermitian
*/
template<typename T> template<typename T>
PIMathMatrix<complex<T> > hermitian(const PIMathMatrix<complex<T> > &m) { PIMathMatrix<complex<T> > hermitian(const PIMathMatrix<complex<T> > &m) {
PIMathMatrix<complex<T> > ret(m); PIMathMatrix<complex<T> > ret(m);
for (uint r = 0; r < ret.rows(); ++r) for (uint c = 0; c < ret.cols(); ++c) ret.element(r, c).imag(-(ret.element(r, c).imag())); for (uint r = 0; r < ret.rows(); ++r)
for (uint c = 0; c < ret.cols(); ++c)
ret.element(r, c).imag(-(ret.element(r, c).imag()));
return ret.transposed(); return ret.transposed();
} }

View File

@@ -17,3 +17,4 @@ endmacro()
# Concurrent tests # Concurrent tests
pip_test(concurrent "") pip_test(concurrent "")
pip_test(math "") pip_test(math "")
pip_test(core "")

2978
tests/core/pistringTest.cpp Normal file
View File

@@ -0,0 +1,2978 @@
#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);
}

View File

@@ -1,172 +1,115 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "pimathmatrix.h" #include "pimathmatrix.h"
bool cmpMatrixWithValue(PIMathMatrix<double> matrix, double val) bool cmpSquareMatrixWithValue(PIMathMatrix<double> matrix, double val, int num) {
{ bool b = true;
int i = 0; for(int i = 0; i < num; i++) {
int j = 0; for(int j = 0; j < num; j++) {
int k = 0; if(matrix.element(i, j) != val) {
bool b;
while(i < 9)
{
if(k < 3)
{
if(matrix.element(j,k) == val)
{
b = true;
}
else
{
b = false; b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
} }
} }
i++;
} }
return b; return b;
} }
TEST(PIMathMatrix_Test, identity) TEST(PIMathMatrix_Test, identity) {
{ auto matrix = PIMathMatrix<double>::identity(3, 3);
PIMathMatrix<double> origMatr; for(int i = 0; i < 3; i++) {
PIMathMatrix<double> matrix; for(int j = 0; j < 3; j++) {
int i; if(i != j) {
bool b; if(matrix[i][j] != 0.0){
matrix = origMatr.identity(3, 3); ASSERT_TRUE(false);
for(i = 0; i < 3; i++)
{
if(matrix[i][i] == 1.0)
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); else {
if(matrix[i][i] != 1.0){
ASSERT_TRUE(false);
}
}
}
}
ASSERT_TRUE(true);
} }
TEST(PIMathMatrix_Test, matrixRow) TEST(PIMathMatrixT_Test, element) {
{ auto matrix = PIMathMatrix<double>::identity(3, 3);
PIMathMatrix<double> origMatr; for(int i = 0; i < 3; i++){
PIMathMatrix<double> matrix; for(int j = 0; j < 3; j++){
PIMathVector<double> vector; if(i != j){
uint i; if(matrix[i][j] != 0.0){
bool b; ASSERT_TRUE(false);
vector.resize(3, 3.0);
vector.fill(5.0);
matrix = origMatr.matrixRow(vector);
for(i = 0; i < vector.size(); i++)
{
if(matrix[0][i] == 5.0)
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); else {
if(matrix.element(i,i) != 1.0) {
ASSERT_TRUE(false);
}
}
}
}
ASSERT_TRUE(true);
} }
TEST(PIMathMatrix_Test, matrixCol) TEST(PIMathMatrix_Test, matrixRow) {
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector; PIMathVector<double> vector;
uint i;
bool b;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.fill(5.0); auto matrix = PIMathMatrix<double>::matrixRow(vector);
matrix = origMatr.matrixCol(vector); for(uint i = 0; i < vector.size(); i++) {
for(i = 0; i < vector.size(); i++) if(matrix[0][i] != 3.0) {
{ ASSERT_TRUE(false);
if(matrix[i][0] == 5.0)
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrix_Test, setCol) TEST(PIMathMatrix_Test, matrixCol) {
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector; PIMathVector<double> vector;
uint i;
bool b;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.fill(5.0); auto matrix = PIMathMatrix<double>::matrixCol(vector);
matrix = origMatr.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); vector.fill(10.0);
matrix.setCol(0, vector); matrix.setCol(0, vector);
for(i = 0; i < vector.size(); i++) for(uint i = 0; i < vector.size(); i++) {
{ if(matrix[i][0] != 10.0) {
if(matrix[i][0] == 10.0) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrix_Test, setRow) TEST(PIMathMatrix_Test, setRow) {
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector; PIMathVector<double> vector;
uint i;
bool b;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.fill(5.0); auto matrix = PIMathMatrix<double>::matrixRow(vector);
matrix = origMatr.matrixRow(vector);
vector.fill(10.0); vector.fill(10.0);
matrix.setRow(0, vector); matrix.setRow(0, vector);
for(i = 0; i < vector.size(); i++) for(uint i = 0; i < vector.size(); i++) {
{ if(matrix[0][i] != 10.0) {
if(matrix[0][i] == 10.0) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrix_Test, swapCols) TEST(PIMathMatrix_Test, swapCols) {
{
PIMathMatrix<double> origMatr; PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix1;
PIMathVector<double> vector; PIMathVector<double> vector;
uint i1 = 0; uint i2 = 1; uint i1 = 0; uint i2 = 1;
double a1[3], a2[3], a3[3]; double a1[3], a2[3], a3[3];
double b1[3], b2[3], b3[3]; double b1[3], b2[3], b3[3];
bool b;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
@@ -181,39 +124,27 @@ TEST(PIMathMatrix_Test, swapCols)
vector.at(1) = 2.0; vector.at(1) = 2.0;
vector.at(2) = 5.0; vector.at(2) = 5.0;
matrix1.setCol(2, vector); matrix1.setCol(2, vector);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++) {
{
a1[i] = matrix1.element(i, 0); a1[i] = matrix1.element(i, 0);
a2[i] = matrix1.element(i, 1); a2[i] = matrix1.element(i, 1);
a3[i] = matrix1.element(i, 2); a3[i] = matrix1.element(i, 2);
} }
matrix1.swapCols(i1, i2); matrix1.swapCols(i1, i2);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++) {
{
b1[i] = matrix1.element(i, 0); b1[i] = matrix1.element(i, 0);
b2[i] = matrix1.element(i, 1); b2[i] = matrix1.element(i, 1);
b3[i] = matrix1.element(i, 2); b3[i] = matrix1.element(i, 2);
} }
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, swapRows) TEST(PIMathMatrix_Test, swapRows) {
{
PIMathMatrix<double> origMatr; PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix1;
PIMathVector<double> vector; PIMathVector<double> vector;
uint i1 = 0; uint i2 = 1; uint i1 = 0; uint i2 = 1;
double a1[3], a2[3], a3[3]; double a1[3], a2[3], a3[3];
double b1[3], b2[3], b3[3]; double b1[3], b2[3], b3[3];
bool b;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
@@ -228,350 +159,189 @@ TEST(PIMathMatrix_Test, swapRows)
vector.at(1) = 2.0; vector.at(1) = 2.0;
vector.at(2) = 5.0; vector.at(2) = 5.0;
matrix1.setCol(2, vector); matrix1.setCol(2, vector);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++) {
{
a1[i] = matrix1.element(0, i); a1[i] = matrix1.element(0, i);
a2[i] = matrix1.element(1, i); a2[i] = matrix1.element(1, i);
a3[i] = matrix1.element(2, i); a3[i] = matrix1.element(2, i);
} }
matrix1.swapRows(i1, i2); matrix1.swapRows(i1, i2);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++) {
{
b1[i] = matrix1.element(0, i); b1[i] = matrix1.element(0, i);
b2[i] = matrix1.element(1, i); b2[i] = matrix1.element(1, i);
b3[i] = matrix1.element(2, i); b3[i] = matrix1.element(2, i);
} }
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
{
b = true;
} }
else TEST(PIMathMatrix_Test, fill) {
{ PIMathMatrix<double> matrix(3, 3, 5.0);
b = false; matrix.fill(7.0);
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3));
} }
ASSERT_TRUE(b);
TEST(PIMathMatrix_Test, isSquareTrue) {
PIMathMatrix<double> matrix(3, 3, 1.0);
ASSERT_TRUE(matrix.isSquare());
} }
TEST(PIMathMatrix_Test, fill)
{ TEST(PIMathMatrix_Test, isSquareFalse) {
PIMathMatrix<double> origMatr; 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());
}
TEST(PIMathMatrix_Test, isIdentityFalse) {
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());
}
TEST(PIMathMatrix_Test, isNullFalse) {
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());
}
TEST(PIMathMatrix_Test, isValidFalse) {
PIMathMatrix<double> matrix; PIMathMatrix<double> matrix;
bool b; ASSERT_FALSE(matrix.isValid());
matrix = origMatr.identity(3, 3);
matrix.fill(5.0);
b = cmpMatrixWithValue(matrix, 5.0);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, isSquare) TEST(PIMathMatrix_Test, operator_Assignment) {
{ PIMathMatrix<double> matrix1(3, 3, 5.72);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 7.12);
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(4,3);
if((matrix1.isSquare() == true) && (matrix2.isSquare() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, isIdentity)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(3.932);
if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, isNull)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(0.0);
matrix2.fill(3.932);
if((matrix1.isNull() == true) && (matrix2.isNull() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, isValid)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
if((matrix1.isValid() == true) && (matrix2.isValid() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Assignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(6.72);
matrix1 = matrix2; matrix1 = matrix2;
b = cmpMatrixWithValue(matrix1, 6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Equal) TEST(PIMathMatrix_Test, operator_EqualTrue) {
{ PIMathMatrix<double> matrix1(2, 2, 2.0);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(2, 2, 2.0);
PIMathMatrix<double> matrix1; matrix1.element(0, 0) = 5.1;
PIMathMatrix<double> matrix2; matrix1.element(0, 1) = 1.21;
PIMathMatrix<double> matrix3; matrix1.element(1, 1) = 0.671;
PIMathVector<double> vector; matrix1.element(1, 0) = 2.623;
bool b; matrix2.element(0, 0) = 5.1;
matrix1 = origMatr.identity(3,3); matrix2.element(0, 1) = 1.21;
matrix2 = origMatr.identity(3,3); matrix2.element(1, 1) = 0.671;
matrix3 = origMatr.identity(3,3); matrix2.element(1, 0) = 2.623;
vector.resize(3, 3.0); ASSERT_TRUE(matrix1 == matrix2);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
matrix1.setCol(0, vector);
matrix2.setCol(0, vector);
matrix3.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
matrix1.setCol(1, vector);
matrix2.setCol(1, vector);
matrix3.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
matrix1.setCol(2, vector);
matrix2.setCol(2, vector);
vector.at(0) = 566.0;
vector.at(1) = 564.0;
vector.at(2) = 543.0;
matrix3.setCol(2, vector);
if(((matrix1 == matrix2) == true) && ((matrix1 == matrix3) == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Not_Equal) TEST(PIMathMatrix_Test, operator_EqualFalse) {
{ PIMathMatrix<double> matrix1(2, 2, 2.0);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(2, 2, 2.0);
PIMathMatrix<double> matrix1; matrix1.element(0, 0) = 5.1;
PIMathMatrix<double> matrix2; matrix1.element(0, 1) = 1.21;
PIMathMatrix<double> matrix3; matrix1.element(1, 1) = 0.671;
PIMathVector<double> vector; matrix1.element(1, 0) = 2.623;
bool b; matrix2.element(0, 0) = 5.1;
matrix1 = origMatr.identity(3,3); matrix2.element(0, 1) = 1.21;
matrix2 = origMatr.identity(3,3); matrix2.element(1, 1) = 665.671;
matrix3 = origMatr.identity(3,3); matrix2.element(1, 0) = 2.623;
vector.resize(3, 3.0); ASSERT_FALSE(matrix1 == matrix2);
vector.at(0) = 3.0;
vector.at(1) = 6.0;
vector.at(2) = 8.0;
matrix1.setCol(0, vector);
matrix2.setCol(0, vector);
matrix3.setCol(0, vector);
vector.at(0) = 2.0;
vector.at(1) = 1.0;
vector.at(2) = 4.0;
matrix1.setCol(1, vector);
matrix2.setCol(1, vector);
matrix3.setCol(1, vector);
vector.at(0) = 6.0;
vector.at(1) = 2.0;
vector.at(2) = 5.0;
matrix1.setCol(2, vector);
matrix2.setCol(2, vector);
vector.at(0) = 566.0;
vector.at(1) = 564.0;
vector.at(2) = 543.0;
matrix3.setCol(2, vector);
if(((matrix1 != matrix2) == false) && ((matrix1 != matrix3) == true))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Addition_Aassignment) TEST(PIMathMatrix_Test, operator_Not_EqualTrue) {
{ PIMathMatrix<double> matrix1(2, 2, 2.0);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(2, 2, 2.0);
PIMathMatrix<double> matrix1; matrix1.element(0, 0) = 5.1;
PIMathMatrix<double> matrix2; matrix1.element(0, 1) = 1.21;
bool b; matrix1.element(1, 1) = 0.671;
matrix1 = origMatr.identity(3,3); matrix1.element(1, 0) = 2.623;
matrix2 = origMatr.identity(3,3); matrix2.element(0, 0) = 5.1;
matrix2.fill(6.72); matrix2.element(0, 1) = 1.21;
matrix1.fill(1.0); 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);
}
TEST(PIMathMatrix_Test, operator_Addition_Aassignment) {
PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> matrix2(3, 3, 1.0);
matrix1 += matrix2; matrix1 += matrix2;
b = cmpMatrixWithValue(matrix1, 7.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) {
{ PIMathMatrix<double> matrix1(3, 3, 1.0);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 6.72);
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 -= matrix2; matrix1 -= matrix2;
b = cmpMatrixWithValue(matrix1, -5.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) {
{ PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
bool b;
matrix1 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix1 *= 2.0; matrix1 *= 2.0;
b = cmpMatrixWithValue(matrix1, 13.44); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Division_Assignment) TEST(PIMathMatrix_Test, operator_Division_Assignment) {
{ PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
bool b;
matrix1 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix1 /= 2.0; matrix1 /= 2.0;
b = cmpMatrixWithValue(matrix1, 3.36); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Addition) TEST(PIMathMatrix_Test, operator_Addition) {
{ PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 8.28);
PIMathMatrix<double> matrix1; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3));
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2.fill(8.28);
b = cmpMatrixWithValue(matrix1 + matrix2, 15.0);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Subtraction) TEST(PIMathMatrix_Test, operator_Subtraction) {
{ PIMathMatrix<double> matrix1(3, 3, 6.0);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 5.0);
PIMathMatrix<double> matrix1; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3));
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3, 3);
matrix2 = origMatr.identity(3, 3);
origMatr.fill(8.0);
matrix1.fill(8.28);
origMatr = origMatr - matrix1;
matrix2.fill(-0.28);
if(origMatr == matrix2)
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Multiplication) TEST(PIMathMatrix_Test, operator_Multiplication) {
{ PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 5.0);
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2 = matrix1*4.0; matrix2 = matrix1*4.0;
b = cmpMatrixWithValue(matrix2, 26.88); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, operator_Division) TEST(PIMathMatrix_Test, operator_Division) {
{ PIMathMatrix<double> matrix1(3, 3, 6.72);
PIMathMatrix<double> origMatr; PIMathMatrix<double> matrix2(3, 3, 5.0);
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2 = matrix1/4.0; matrix2 = matrix1/4.0;
b = cmpMatrixWithValue(matrix2, 1.68); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, determinant) TEST(PIMathMatrix_Test, determinantIfSquare) {
{
PIMathMatrix<double> origMatr;
double d; double d;
double i = 59.0; double i = 59.0;
PIMathMatrix<double> matrix; PIMathMatrix<double> matrix(3, 3, 0.0);
PIMathVector<double> vector; PIMathVector<double> vector;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
vector.at(2) = 8.0; vector.at(2) = 8.0;
matrix = origMatr.identity(3, 3);
matrix.setCol(0, vector); matrix.setCol(0, vector);
vector.at(0) = 2.0; vector.at(0) = 2.0;
vector.at(1) = 1.0; vector.at(1) = 1.0;
@@ -585,18 +355,21 @@ TEST(PIMathMatrix_Test, determinant)
ASSERT_DOUBLE_EQ(d, i); ASSERT_DOUBLE_EQ(d, i);
} }
TEST(PIMathMatrix_Test, trace) TEST(PIMathMatrix_Test, determinantIfNotSquare) {
{ PIMathMatrix<double> matrix(3, 5, 1.0);
PIMathMatrix<double> origMatr; matrix.element(1,1) = 5.0;
ASSERT_FALSE(matrix.determinant());
}
TEST(PIMathMatrix_Test, trace) {
PIMathMatrix<double> matrix(3, 3, 0.0);
double t; double t;
double i = 9.0; double i = 9.0;
PIMathMatrix<double> matrix;
PIMathVector<double> vector; PIMathVector<double> vector;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
vector.at(2) = 8.0; vector.at(2) = 8.0;
matrix = origMatr.identity(3, 3);
matrix.setCol(0, vector); matrix.setCol(0, vector);
vector.at(0) = 2.0; vector.at(0) = 2.0;
vector.at(1) = 1.0; vector.at(1) = 1.0;
@@ -610,18 +383,21 @@ TEST(PIMathMatrix_Test, trace)
ASSERT_DOUBLE_EQ(t, i); ASSERT_DOUBLE_EQ(t, i);
} }
TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, traceIfNotSquare) {
{ PIMathMatrix<double> matrix(3, 5, 1.0);
PIMathMatrix<double> origMatr; 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; double d1, d2 = 1;
int i; int i;
PIMathMatrix<double> matrix;
PIMathVector<double> vector; PIMathVector<double> vector;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
vector.at(2) = 8.0; vector.at(2) = 8.0;
matrix = origMatr.identity(3, 3);
matrix.setCol(0, vector); matrix.setCol(0, vector);
vector.at(0) = 2.0; vector.at(0) = 2.0;
vector.at(1) = 1.0; vector.at(1) = 1.0;
@@ -640,21 +416,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular)
ASSERT_DOUBLE_EQ(d1, d2); ASSERT_DOUBLE_EQ(d1, d2);
} }
TEST(PIMathMatrix_Test, invert) TEST(PIMathMatrix_Test, invert) {
{
PIMathMatrix<double> origMatr;
double d1, d2; double d1, d2;
bool b; PIMathMatrix<double> matrix1(3, 3, 0.0);
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix2(3, 3, 0.0);
PIMathMatrix<double> matrix2; PIMathMatrix<double> matrix3(3, 3, 0.0);
PIMathMatrix<double> matrix3; PIMathMatrix<double> matrix4(3, 3, 0.0);
PIMathMatrix<double> matrix4;
PIMathVector<double> vector; PIMathVector<double> vector;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
vector.at(2) = 8.0; vector.at(2) = 8.0;
matrix1 = origMatr.identity(3, 3);
matrix1.setCol(0, vector); matrix1.setCol(0, vector);
vector.at(0) = 2.0; vector.at(0) = 2.0;
vector.at(1) = 1.0; vector.at(1) = 1.0;
@@ -668,35 +440,21 @@ TEST(PIMathMatrix_Test, invert)
matrix2 = matrix1; matrix2 = matrix1;
matrix2.invert(); matrix2.invert();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = origMatr.identity(3, 3);
matrix4 = origMatr.identity(3, 3);
matrix4.invert(); matrix4.invert();
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, inverted) TEST(PIMathMatrix_Test, inverted) {
{
PIMathMatrix<double> origMatr;
double d1, d2; double d1, d2;
bool b; PIMathMatrix<double> matrix1(3, 3, 0.0);
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix2(3, 3, 0.0);
PIMathMatrix<double> matrix2; PIMathMatrix<double> matrix3(3, 3, 0.0);
PIMathMatrix<double> matrix3; PIMathMatrix<double> matrix4(3, 3, 0.0);
PIMathMatrix<double> matrix4;
PIMathVector<double> vector; PIMathVector<double> vector;
vector.resize(3, 3.0); vector.resize(3, 3.0);
vector.at(0) = 3.0; vector.at(0) = 3.0;
vector.at(1) = 6.0; vector.at(1) = 6.0;
vector.at(2) = 8.0; vector.at(2) = 8.0;
matrix1 = origMatr.identity(3, 3);
matrix1.setCol(0, vector); matrix1.setCol(0, vector);
vector.at(0) = 2.0; vector.at(0) = 2.0;
vector.at(1) = 1.0; vector.at(1) = 1.0;
@@ -710,25 +468,13 @@ TEST(PIMathMatrix_Test, inverted)
matrix2 = matrix1; matrix2 = matrix1;
matrix1 = matrix2.invert(); matrix1 = matrix2.invert();
d2 = matrix1.determinant(); d2 = matrix1.determinant();
matrix3 = origMatr.identity(3, 3);
matrix4 = origMatr.identity(3, 3);
matrix3 = matrix4.invert(); matrix3 = matrix4.invert();
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, transposed) TEST(PIMathMatrix_Test, transposed) {
{
PIMathMatrix<double> origMatr; PIMathMatrix<double> origMatr;
double d1, d2; double d1, d2;
bool b;
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2; PIMathMatrix<double> matrix2;
PIMathMatrix<double> matrix3; PIMathMatrix<double> matrix3;
@@ -751,13 +497,59 @@ TEST(PIMathMatrix_Test, transposed)
matrix2 = matrix1.transposed(); matrix2 = matrix1.transposed();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix2.transposed(); matrix3 = matrix2.transposed();
if((d1 == d2) && (matrix1 == matrix3)) ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3));
{
b = true;
} }
else
{ TEST(PIMathMatrix_Test, matrixMultiplication) {
b = false; PIMathMatrix<double> matrix1(2, 2, 1.5);
PIMathMatrix<double> matrix2(2, 2, 2.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
} }
ASSERT_TRUE(b);
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);
}
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);
}
TEST(PIMathMatrix_Test, valAndMatrixMultiplication) {
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);
} }

View File

@@ -4,128 +4,65 @@
const uint rows = 3; const uint rows = 3;
const uint cols = 3; const uint cols = 3;
bool cmpMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val) bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val, int num) {
{ bool b = true;
int i = 0; for(int i = 0; i < num; i++) {
int j = 0; for(int j = 0; j < num; j++) {
int k = 0; if(matrix.at(i, j) != val) {
bool b;
while(i < 9)
{
if(k < 3)
{
if(matrix.at(j,k) == val)
{
b = true;
}
else
{
b = false; b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
} }
} }
i++;
} }
return b; return b;
} }
TEST(PIMathMatrixT_Test, identity) {
TEST(PIMathMatrixT_Test, identity) auto matrix = PIMathMatrixT<rows, cols, double>::identity();
{ for(int i = 0; i < 3; i++){
PIMathMatrixT<rows, cols, double> matr; for(int j = 0; j < 3; j++){
PIMathMatrixT<rows, cols, double> matrix; if(i != j){
double d; if(matrix[i][j] != 0.0){
double i = 1.0; ASSERT_TRUE(false);
bool a;
bool output;
matrix = matr.identity();
d = matrix.determinant();
uint j;
for(j = 0; j < cols; j++)
{
if(matrix.at(i, i) == 1.0) a = true;
else
{
a = false;
break;
} }
} }
if((i == d) && (a == true)){
output = true;
}
else { else {
output = false; if(matrix[i][i] != 1.0){
ASSERT_TRUE(false);
} }
ASSERT_TRUE(output); }
}
}
ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, at) TEST(PIMathMatrixT_Test, at) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
uint i; for(uint i = 0; i < rows; i++) {
bool b; if(matrix1.at(i,i) != 1.0) {
PIMathMatrixT<rows, cols, double> matr; ASSERT_TRUE(false);
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
matrix1 = matr.identity();
matrix2 = matr.identity();
for(i = 0; i < rows; i++)
{
if(matrix1.at(i,i) == 1.0)
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, filled) TEST(PIMathMatrixT_Test, filled) {
{ auto matr = PIMathMatrixT<rows, cols, double>::filled(1.0);
PIMathMatrixT<rows, cols, double> matrix1; ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect;
double g = 1.0;
matrix2 = matr.fill(g);
uint j = 0, i = 0;
for(i = 0; i < cols; i++)
{
for(j = 0; j < rows; j++)
{
matrix1.at(j,i) = g;
}
}
ASSERT_TRUE(matrix2 == matrix1);
} }
TEST(PIMathMatrixT_Test, cols) TEST(PIMathMatrixT_Test, cols) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
ASSERT_EQ(cols,matr.cols()); ASSERT_EQ(cols,matr.cols());
} }
TEST(PIMathMatrixT_Test, rows) TEST(PIMathMatrixT_Test, rows) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
ASSERT_EQ(rows,matr.rows()); ASSERT_EQ(rows,matr.rows());
} }
TEST(PIMathMatrixT_Test, col) TEST(PIMathMatrixT_Test, col) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
uint i;
uint g = 2; uint g = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -136,28 +73,18 @@ TEST(PIMathMatrixT_Test, col)
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
vect = matr.col(g); vect = matr.col(g);
for(i = 0; i < matr.cols(); i++) for(uint i = 0; i < matr.cols(); i++) {
{ if(matr.at(i, g) != vect.at(i)) {
if(matr.at(i,g) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, row) TEST(PIMathMatrixT_Test, row) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
uint i;
uint g = 2; uint g = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -168,82 +95,49 @@ TEST(PIMathMatrixT_Test, row)
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
vect = matr.row(g); vect = matr.row(g);
for(i = 0; i < matr.rows(); i++) for(uint i = 0; i < matr.rows(); i++) {
{ if(matr.at(g, i) != vect.at(i)) {
if(matr.at(g,i) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, setCol) TEST(PIMathMatrixT_Test, setCol) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
vect.at(0) = 1.0; vect.at(0) = 1.0;
vect.at(1) = 3.0; vect.at(1) = 3.0;
vect.at(2) = 5.0; vect.at(2) = 5.0;
uint g = 1; uint g = 1;
uint i = 0;
bool b;
matr.setCol(g, vect); matr.setCol(g, vect);
for(i = 0; i < vect.size(); i++) for(uint i = 0; i < vect.size(); i++) {
{ if(matr.at(i, g) != vect.at(i)) {
if(matr.at(i,g) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, setRow) TEST(PIMathMatrixT_Test, setRow) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
vect.at(0) = 1.0; vect.at(0) = 1.0;
vect.at(1) = 3.0; vect.at(1) = 3.0;
vect.at(2) = 5.0; vect.at(2) = 5.0;
uint g = 1; uint g = 1;
uint i = 0;
bool b;
matr.setRow(g, vect); matr.setRow(g, vect);
for(i = 0; i < vect.size(); i++) for(uint i = 0; i < vect.size(); i++) {
{ if(matr.at(g,i) != vect.at(i)) {
if(matr.at(g,i) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, swapCols) TEST(PIMathMatrixT_Test, swapCols) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> before_Vect1;
PIMathVectorT<rows, double> before_Vect2;
PIMathVectorT<rows, double> after_Vect1;
PIMathVectorT<rows, double> after_Vect2;
int g1 = 1, g2 = 2; int g1 = 1, g2 = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -253,31 +147,22 @@ TEST(PIMathMatrixT_Test, swapCols)
matr.at(2,0) = 6; matr.at(2,0) = 6;
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
before_Vect1 = matr.col(g1); const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
before_Vect2 = matr.col(g2); const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
matr.swapCols(g1, g2); matr.swapCols(g1, g2);
after_Vect1 = matr.col(g1); const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
after_Vect2 = matr.col(g2); const PIMathVectorT<rows, double> after_Vect2 = matr.col(g2);
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
{ ASSERT_TRUE(true);
b = true;
} }
else else {
{ ASSERT_TRUE(false);
b = false;
} }
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, swapRows) TEST(PIMathMatrixT_Test, swapRows) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> before_Vect1;
PIMathVectorT<rows, double> before_Vect2;
PIMathVectorT<rows, double> after_Vect1;
PIMathVectorT<rows, double> after_Vect2;
int g1 = 1, g2 = 2; int g1 = 1, g2 = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -287,254 +172,174 @@ TEST(PIMathMatrixT_Test, swapRows)
matr.at(2,0) = 6; matr.at(2,0) = 6;
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
before_Vect1 = matr.row(g1); const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
before_Vect2 = matr.row(g2); const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
matr.swapRows(g1, g2); matr.swapRows(g1, g2);
after_Vect1 = matr.row(g1); const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
after_Vect2 = matr.row(g2); const PIMathVectorT<rows, double> after_Vect2 = matr.row(g2);
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
{ ASSERT_TRUE(true);
b = true;
} }
else else {
{ ASSERT_TRUE(false);
b = false;
} }
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, fill) TEST(PIMathMatrixT_Test, fill) {
{
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
double g = 1.0; double g = 1.0;
matr.fill(g); matr.fill(g);
uint j = 0, i = 0; for(uint i = 0; i < cols; i++) {
for(i = 0; i < cols; i++) for(uint j = 0; j < rows; j++) {
{
for(j = 0; j < rows; j++)
{
matrix1.at(j,i) = g; matrix1.at(j,i) = g;
} }
} }
ASSERT_TRUE(matr == matrix1); ASSERT_TRUE(matr == matrix1);
} }
TEST(PIMathMatrixT_Test, isSquare) TEST(PIMathMatrixT_Test, isSquareTrue) {
{
PIMathMatrixT<rows, cols, double> matr;
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
ASSERT_TRUE(matrix1.isSquare());
}
TEST(PIMathMatrixT_Test, isSquareFalse) {
const uint new_Cols = 4; const uint new_Cols = 4;
PIMathMatrixT<rows, new_Cols, double> matrix2; PIMathMatrixT<rows, new_Cols, double> matrix2;
bool b; ASSERT_FALSE(matrix2.isSquare());
if((matrix1.isSquare() == true) && (matrix2.isSquare() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, isIdentity) TEST(PIMathMatrixT_Test, isIdentityTrue) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
PIMathMatrixT<rows, cols, double> matr; ASSERT_TRUE(matrix1.isIdentity());
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2;
bool b;
matrix1 = matr.identity();
matrix2 = matr.filled(3.67);
if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, isNull) TEST(PIMathMatrixT_Test, isIdentityFalse) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(2.5);
PIMathMatrixT<rows, cols, double> matrix1; ASSERT_FALSE(matrix1.isIdentity());
PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr;
bool b;
matrix2 = matr.filled(3.67);
if((matrix1.isNull() == true) && (matrix2.isNull() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Assignment) TEST(PIMathMatrixT_Test, isNullTrue) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(matrix1.isNull());
PIMathMatrixT<rows, cols, double> matr; }
bool b;
matrix2.fill(6.72); TEST(PIMathMatrixT_Test, isNullFalse) {
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; matrix1 = matrix2;
b = cmpMatrixWithValue(matrix1, 6.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Equal) TEST(PIMathMatrixT_Test, operator_EqualTrue) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr; matrix1.at(0, 0) = 5.1;
bool b; matrix1.at(0, 1) = 1.21;
matr.at(0,0) = 3; matrix1.at(1, 1) = 0.671;
matr.at(0,1) = 6; matrix1.at(1, 0) = 2.623;
matr.at(0,2) = 8; matrix2.at(0, 0) = 5.1;
matr.at(1,0) = 2; matrix2.at(0, 1) = 1.21;
matr.at(1,1) = 1; matrix2.at(1, 1) = 0.671;
matr.at(1,2) = 4; matrix2.at(1, 0) = 2.623;
matr.at(2,0) = 6; ASSERT_TRUE(matrix1 == matrix2);
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matrix1 = matr;
matrix2 = matr;
matrix2.at(2, 2) = 232;
if(((matr == matrix1) == true) && ((matr == matrix2) == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Not_Equal) TEST(PIMathMatrixT_Test, operator_EqualFalse) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
bool b; matrix1.at(0, 0) = 5.1;
PIMathMatrixT<rows, cols, double> matr; matrix1.at(0, 1) = 1.21;
matr.at(0,0) = 3; matrix1.at(1, 1) = 0.671;
matr.at(0,1) = 6; matrix1.at(1, 0) = 2.623;
matr.at(0,2) = 8; matrix2.at(0, 0) = 5.1;
matr.at(1,0) = 2; matrix2.at(0, 1) = 1.21;
matr.at(1,1) = 1; matrix2.at(1, 1) = 665.671;
matr.at(1,2) = 4; matrix2.at(1, 0) = 2.623;
matr.at(2,0) = 6; ASSERT_FALSE(matrix1 == matrix2);
matr.at(2,1) = 2;
matr.at(2,2) = 5;
matrix1 = matr;
matrix2 = matr;
matrix2.at(2, 2) = 232;
if(((matr != matrix1) == false) && ((matr != matrix2) == true))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
bool b; matrix1.at(0, 0) = 5.1;
matrix2.fill(6.72); matrix1.at(0, 1) = 1.21;
matrix1.fill(1.0); 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);
}
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);
}
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; matrix1 += matrix2;
b = cmpMatrixWithValue(matrix1, 7.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.0);
PIMathMatrixT<rows, cols, double> matrix1; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix2;
bool b;
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 -= matrix2; matrix1 -= matrix2;
b = cmpMatrixWithValue(matrix1, -5.72); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix1;
bool b;
matrix1.fill(6.72);
matrix1 *= 2.0; matrix1 *= 2.0;
b = cmpMatrixWithValue(matrix1, 13.44); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Division_Assignment) TEST(PIMathMatrixT_Test, operator_Division_Assignment) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix1;
bool b;
matrix1.fill(6.72);
matrix1 /= 2.0; matrix1 /= 2.0;
b = cmpMatrixWithValue(matrix1, 3.36); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Addition) TEST(PIMathMatrixT_Test, operator_Addition) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix1; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(8.28);
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
bool b;
matrix1.fill(6.72);
matrix2.fill(8.28);
b = cmpMatrixWithValue(matrix1 + matrix2, 15.0);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Subtraction) TEST(PIMathMatrixT_Test, operator_Subtraction) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.0);
PIMathMatrixT<rows, cols, double> matrix1; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(5.0);
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
bool b;
matrix1.fill(6.0);
matrix2.fill(5.0);
b = cmpMatrixWithValue(matrix1 - matrix2, 1.0);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Multiplication) TEST(PIMathMatrixT_Test, operator_Multiplication) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix1; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
PIMathMatrixT<rows, cols, double> matrix2;
bool b;
matrix1.fill(6.72);
matrix2 = matrix1*4.0;
b = cmpMatrixWithValue(matrix2, 26.88);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Division) TEST(PIMathMatrixT_Test, operator_Division) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix1; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
PIMathMatrixT<rows, cols, double> matrix2;
bool b;
matrix1.fill(6.72);
matrix2 = matrix1/4.0;
b = cmpMatrixWithValue(matrix2, 1.68);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, determinantIfSquare) {
TEST(PIMathMatrixT_Test, determinant)
{
double d; double d;
double i = 59.0; double i = 59.0;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
@@ -551,15 +356,26 @@ TEST(PIMathMatrixT_Test, determinant)
ASSERT_DOUBLE_EQ(i, d); ASSERT_DOUBLE_EQ(i, d);
} }
TEST(PIMathMatrixT_Test, invert) 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());
}
TEST(PIMathMatrixT_Test, invert) {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matrix3; PIMathMatrixT<rows, cols, double> matrix3;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matrix1 = matr.identity();
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -575,25 +391,15 @@ TEST(PIMathMatrixT_Test, invert)
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix1; matrix3 = matrix1;
matrix1.invert(); matrix1.invert();
if((matrix1 == matrix3) && (d1 == 1/d2)) ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, inverted) TEST(PIMathMatrixT_Test, inverted) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matrix3; PIMathMatrixT<rows, cols, double> matrix3;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matrix1 = matr.identity(); matrix1 = matr.identity();
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
@@ -608,22 +414,12 @@ TEST(PIMathMatrixT_Test, inverted)
d1 = matr.determinant(); d1 = matr.determinant();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix1.inverted(); matrix3 = matrix1.inverted();
if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, toUpperTriangular) TEST(PIMathMatrixT_Test, toUpperTriangular) {
{
PIMathMatrixT<rows, cols, double> matrix; PIMathMatrixT<rows, cols, double> matrix;
double d1, d2 = 1; double d1, d2 = 1;
uint i;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
@@ -636,20 +432,18 @@ TEST(PIMathMatrixT_Test, toUpperTriangular)
matr.at(2,2) = 5; matr.at(2,2) = 5;
matrix = matr.toUpperTriangular(); matrix = matr.toUpperTriangular();
d1 = matrix.determinant(); d1 = matrix.determinant();
for(i = 0; i < cols; i++) for(uint i = 0; i < cols; i++)
{ {
d2 = d2*matrix.at(i,i); d2 = d2*matrix.at(i,i);
} }
ASSERT_DOUBLE_EQ(d1, d2); ASSERT_DOUBLE_EQ(d1, d2);
} }
TEST(PIMathMatrixT_Test, transposed) TEST(PIMathMatrixT_Test, transposed) {
{
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -663,171 +457,106 @@ TEST(PIMathMatrixT_Test, transposed)
matrix1 = matr.transposed(); matrix1 = matr.transposed();
d2 = matrix1.determinant(); d2 = matrix1.determinant();
matrix2 = matrix1.transposed(); matrix2 = matrix1.transposed();
if((d1 == d2) && (matr == matrix2)) ASSERT_TRUE((d1 == d2) && (matr == matrix2));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotation) 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)));
}
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)));
}
TEST(PIMathMatrixT_Test, rotation_2x2) {
double angle = 1.0; double angle = 1.0;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u)));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleX_two) TEST(PIMathMatrixT_Test, rotation_3x3) {
{ double angle = 1.0;
double factor = 5.64; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
bool b; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows));
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); }
if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))) TEST(PIMathMatrixT_Test, rotationX) {
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrixT_Test, scaleY_two)
{
double factor = 5.64;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor);
if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
}
TEST(PIMathMatrixT_Test, rotationX)
{
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(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)));
if((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)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotationY) TEST(PIMathMatrixT_Test, rotationY) {
{
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(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)));
if((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)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotationZ) TEST(PIMathMatrixT_Test, rotationZ) {
{
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(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)));
if((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)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleX_three) TEST(PIMathMatrixT_Test, scaleX_three) {
{
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor);
if((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleY_three) TEST(PIMathMatrixT_Test, scaleY_three) {
{
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor);
if((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))) ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u)));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleZ_three) TEST(PIMathMatrixT_Test, scaleZ_three) {
{
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor);
if((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u)));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
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));
}
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);
}
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);
}
}
}
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) {
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
}