add PIVector2D Index
This commit is contained in:
@@ -1431,3 +1431,61 @@ TEST_F(Vector2DTest, iostream_operator_works) {
|
||||
// No assertion, just ensure it runs
|
||||
}
|
||||
#endif
|
||||
|
||||
// ==================== INDEX STRUCTURE ACCESS TESTS ====================
|
||||
TEST_F(Vector2DTest, operator_bracket_with_index_allows_read_access) {
|
||||
PIVector2D<int>::Index idx = {5, 7};
|
||||
int value = vec[idx];
|
||||
int expected = vec.element(5, 7);
|
||||
EXPECT_EQ(value, expected);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, operator_bracket_with_index_allows_write_access) {
|
||||
PIVector2D<int>::Index idx = {10, 15};
|
||||
vec[idx] = 999;
|
||||
EXPECT_EQ(vec.element(10, 15), 999);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, operator_bracket_with_const_index_works) {
|
||||
const auto & constVec = vec;
|
||||
PIVector2D<int>::Index idx = {3, 12};
|
||||
int value = constVec[idx];
|
||||
int expected = vec.element(3, 12);
|
||||
EXPECT_EQ(value, expected);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, element_function_with_index_works) {
|
||||
PIVector2D<int>::Index idx = {8, 20};
|
||||
int value = vec.element(idx);
|
||||
int expected = vec.element(8, 20);
|
||||
EXPECT_EQ(value, expected);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, element_function_with_index_modifies_value) {
|
||||
PIVector2D<int>::Index idx = {12, 8};
|
||||
vec.element(idx) = 555;
|
||||
EXPECT_EQ(vec.element(12, 8), 555);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, element_function_with_const_index_works) {
|
||||
const auto & constVec = vec;
|
||||
PIVector2D<int>::Index idx = {7, 5};
|
||||
int value = constVec.element(idx);
|
||||
int expected = vec.element(7, 5);
|
||||
EXPECT_EQ(value, expected);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, at_function_with_index_works) {
|
||||
PIVector2D<int>::Index idx = {4, 11};
|
||||
int value = vec.at(idx);
|
||||
int expected = vec.at(4, 11);
|
||||
EXPECT_EQ(value, expected);
|
||||
}
|
||||
|
||||
TEST_F(Vector2DTest, index_structure_with_brace_initialization_works) {
|
||||
vec[{0, 0}] = 100;
|
||||
EXPECT_EQ(vec.element(0, 0), 100);
|
||||
|
||||
vec[{static_cast<ssize_t>(ROWS_COUNT_INIT - 1), static_cast<ssize_t>(COLS_COUNT_INIT - 1)}] = 200;
|
||||
EXPECT_EQ(vec.element(ROWS_COUNT_INIT - 1, COLS_COUNT_INIT - 1), 200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user