Compare commits
6 Commits
94fc54159b
...
ff6d5cedaa
| Author | SHA1 | Date | |
|---|---|---|---|
| ff6d5cedaa | |||
| a7851ecf3e | |||
| d84adf2bc7 | |||
| ac911d9b3e | |||
| b6430c0863 | |||
| 16f22f38c7 |
@@ -218,7 +218,7 @@ public:
|
|||||||
int cs = (cols - cols_);
|
int cs = (cols - cols_);
|
||||||
if (cs < 0) {
|
if (cs < 0) {
|
||||||
for (size_t r=0; r<rows; ++r) {
|
for (size_t r=0; r<rows; ++r) {
|
||||||
mat.remove(r*cols_ + cols_, -cs);
|
mat.remove(r*cols + cols, -cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mat.resize(rows*cols, f);
|
mat.resize(rows*cols, f);
|
||||||
|
|||||||
11
main.cpp
11
main.cpp
@@ -40,12 +40,11 @@ inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << ">>"
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
PIMathMatrixd m = PIMathMatrixd::identity(3,3);
|
PIMathMatrixd m = PIMathMatrixd::identity(5,5);
|
||||||
m.fill(0);
|
// m.fill(9);
|
||||||
PIMathMatrixd m2 = PIMathMatrixd::identity(3,4);
|
//PIMathMatrixd m2 = PIMathMatrixd::identity(3,4);
|
||||||
|
piCout << m;
|
||||||
|
m.resize(3,3);
|
||||||
piCout << m;
|
piCout << m;
|
||||||
piCout << m2;
|
|
||||||
piCout << m * m2;
|
|
||||||
piCout << m2 * m;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
88
tests/math/testpivector2d.cpp
Normal file
88
tests/math/testpivector2d.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "pivector2d.h"
|
||||||
|
|
||||||
|
int ROWS_COUNT_INIT = 31;
|
||||||
|
int ROWS_COUNT_INCREASE = 41;
|
||||||
|
int ROWS_COUNT_REDUCE = 22;
|
||||||
|
|
||||||
|
int COLS_COUNT_INIT = 34;
|
||||||
|
int COLS_COUNT_INCREASE = 44;
|
||||||
|
int COLS_COUNT_REDUCE = 13;
|
||||||
|
|
||||||
|
void assert_fill_with(PIVector2D<int> vec, int rows, int cols) {
|
||||||
|
for(int r = 0; r < rows; r++) {
|
||||||
|
for(int c = 0; c < cols; c++) {
|
||||||
|
ASSERT_EQ(vec.element(r, c), r * COLS_COUNT_INIT + c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Vector2D : public ::testing::Test {
|
||||||
|
protected:
|
||||||
|
PIVector2D<int> vec = PIVector2D<int>(ROWS_COUNT_INIT, COLS_COUNT_INIT);
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
for (int r = 0; r < ROWS_COUNT_INIT; ++r) {
|
||||||
|
for (int c = 0; c < COLS_COUNT_INIT; ++c) {
|
||||||
|
vec.element(r, c) = r * COLS_COUNT_INIT + c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void resize_reduce_is_data_stay_consistent(int newRowsCount, int newColsCount) {
|
||||||
|
piCout << "Before:";
|
||||||
|
piCout << vec;
|
||||||
|
piCout << "";
|
||||||
|
vec.resize(newRowsCount, newColsCount, 0);
|
||||||
|
piCout << "After:";
|
||||||
|
piCout << vec;
|
||||||
|
assert_fill_with(vec, newRowsCount, newColsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resize_increase_is_data_stay_consistent(int newRowsCount, int newColsCount) {
|
||||||
|
vec.resize(newRowsCount, newColsCount, 0);
|
||||||
|
assert_fill_with(vec, ROWS_COUNT_INIT, COLS_COUNT_INIT);
|
||||||
|
|
||||||
|
for (int r = ROWS_COUNT_INIT; r < newRowsCount; ++r) {
|
||||||
|
for (int c = COLS_COUNT_INIT; c < newColsCount; ++c) {
|
||||||
|
ASSERT_EQ(vec.element(r, c), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_is_increase_col_count) {
|
||||||
|
vec.resize(ROWS_COUNT_INIT, COLS_COUNT_INCREASE, 0);
|
||||||
|
ASSERT_EQ(vec.cols(), COLS_COUNT_INCREASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_is_reduce_col_count) {
|
||||||
|
vec.resize(ROWS_COUNT_INIT, COLS_COUNT_REDUCE, 0);
|
||||||
|
ASSERT_EQ(vec.cols(), COLS_COUNT_REDUCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_is_increase_rows_count) {
|
||||||
|
vec.resize(ROWS_COUNT_INCREASE, COLS_COUNT_INIT, 0);
|
||||||
|
ASSERT_EQ(vec.rows(), ROWS_COUNT_INCREASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_is_reduce_rows_count) {
|
||||||
|
vec.resize(ROWS_COUNT_REDUCE, COLS_COUNT_INIT, 0);
|
||||||
|
ASSERT_EQ(vec.rows(), ROWS_COUNT_REDUCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_increase_both_is_data_stay_consistent) {
|
||||||
|
resize_increase_is_data_stay_consistent(ROWS_COUNT_INCREASE, COLS_COUNT_INCREASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_reduce_cols_is_data_stay_consistent) {
|
||||||
|
resize_reduce_is_data_stay_consistent(ROWS_COUNT_INIT, COLS_COUNT_REDUCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_reduce_rows_is_data_stay_consistent) {
|
||||||
|
resize_reduce_is_data_stay_consistent(ROWS_COUNT_REDUCE, COLS_COUNT_INIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(Vector2D, resize_reduce_both_is_data_stay_consistent) {
|
||||||
|
resize_reduce_is_data_stay_consistent(ROWS_COUNT_REDUCE, COLS_COUNT_REDUCE);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user