From ac911d9b3e47b362081ecc59f151548d29eb4330 Mon Sep 17 00:00:00 2001 From: Stepan Fomenko Date: Mon, 19 Oct 2020 17:34:51 +0300 Subject: [PATCH] Increase reduce cols tests granularity --- tests/math/testpivector2d.cpp | 54 ++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/tests/math/testpivector2d.cpp b/tests/math/testpivector2d.cpp index 0657f8df..9a42f8ed 100644 --- a/tests/math/testpivector2d.cpp +++ b/tests/math/testpivector2d.cpp @@ -1,12 +1,12 @@ #include "gtest/gtest.h" #include "pivector2d.h" -int ROWS_COUNT_INIT = 4; -int ROWS_COUNT_INCREASE = 6; +int ROWS_COUNT_INIT = 3; +int ROWS_COUNT_INCREASE = 4; int ROWS_COUNT_REDUCE = 2; -int COLS_COUNT_INIT = 4; -int COLS_COUNT_INCREASE = 6; +int COLS_COUNT_INIT = 3; +int COLS_COUNT_INCREASE = 4; int COLS_COUNT_REDUCE = 2; void assert_fill_with(PIVector2D vec, int rows, int cols) { @@ -19,6 +19,8 @@ void assert_fill_with(PIVector2D vec, int rows, int cols) { class Vector2D : public ::testing::Test { protected: + PIVector2D vec = PIVector2D(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) { @@ -27,7 +29,26 @@ protected: } } - PIVector2D vec = PIVector2D(ROWS_COUNT_INIT, COLS_COUNT_INIT); + 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) { @@ -50,17 +71,18 @@ TEST_F(Vector2D, resize_is_reduce_rows_count) { ASSERT_EQ(vec.rows(), ROWS_COUNT_REDUCE); } -TEST_F(Vector2D, resize_increase_is_data_stay_consistent) { - vec.resize(ROWS_COUNT_INCREASE, COLS_COUNT_INCREASE, 0); - assert_fill_with(vec, ROWS_COUNT_INIT, COLS_COUNT_INIT); +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_is_data_stay_consistent) { - piCout << "Before:"; - piCout << vec; - piCout << ""; - vec.resize(ROWS_COUNT_REDUCE, COLS_COUNT_REDUCE, 0); - piCout << "After:"; - piCout << vec; - assert_fill_with(vec, ROWS_COUNT_REDUCE, COLS_COUNT_REDUCE); +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); } \ No newline at end of file