89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
#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);
|
|
}
|