Files
pip/tests/math/testpivector2d.cpp
2022-12-14 14:13:52 +03:00

86 lines
2.4 KiB
C++

#include "pivector2d.h"
#include "gtest/gtest.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) {
vec.resize(newRowsCount, newColsCount, 0);
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 = 0; r < newRowsCount; ++r) {
for (int c = 0; c < newColsCount; ++c) {
if (r < ROWS_COUNT_INIT || c < COLS_COUNT_INIT) continue;
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);
}