|
1 | 1 | /* |
2 | 2 | * Copyright (C) 2020-2024 MEmilio |
3 | 3 | * |
4 | | -* Authors: Daniel Abele |
| 4 | +* Authors: Daniel Abele, Khoa Nguyen |
5 | 5 | * |
6 | 6 | * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> |
7 | 7 | * |
@@ -380,3 +380,48 @@ TEST(CustomIndexArray, resize_one_dimension) |
380 | 380 | ASSERT_EQ(array.size().indices, std::make_tuple(Tag0{3}, Tag1{2})); |
381 | 381 | ASSERT_EQ(array.numel(), 6); |
382 | 382 | } |
| 383 | + |
| 384 | +// Additional test for checking the set_multiple functionality |
| 385 | +TEST(CustomIndexArray, setMultiple_validIndices) { |
| 386 | + using ArrayType = mio::CustomIndexArray<int, Dim1, Dim2>; |
| 387 | + // Initialize with zeros |
| 388 | + ArrayType array({mio::Index<Dim1>(3), Dim2::Count}, 0); |
| 389 | + |
| 390 | + // Define indices to set |
| 391 | + std::vector<ArrayType::Index> indices = { |
| 392 | + {mio::Index<Dim1>(0), Dim2::Male}, |
| 393 | + {mio::Index<Dim1>(2), Dim2::Female} |
| 394 | + }; |
| 395 | + |
| 396 | + // Set these indices to 42 |
| 397 | + array.set_multiple(indices, 42); |
| 398 | + |
| 399 | + // Verify that the correct indices have been updated |
| 400 | + EXPECT_EQ((array[{mio::Index<Dim1>(0), Dim2::Male}]), 42); |
| 401 | + EXPECT_EQ((array[{mio::Index<Dim1>(2), Dim2::Female}]), 42); |
| 402 | + |
| 403 | + // Verify that other indices are unchanged |
| 404 | + EXPECT_EQ((array[{mio::Index<Dim1>(0), Dim2::Female}]), 0); |
| 405 | + EXPECT_EQ((array[{mio::Index<Dim1>(1), Dim2::Male}]), 0); |
| 406 | + EXPECT_EQ((array[{mio::Index<Dim1>(1), Dim2::Female}]), 0); |
| 407 | + EXPECT_EQ((array[{mio::Index<Dim1>(2), Dim2::Male}]), 0); |
| 408 | +} |
| 409 | + |
| 410 | +TEST(CustomIndexArray, setMultiple_emptyIndices) { |
| 411 | + using ArrayType = mio::CustomIndexArray<int, Dim1, Dim2>; |
| 412 | + // Initialize with fives |
| 413 | + ArrayType array({mio::Index<Dim1>(2), Dim2::Count}, 5); |
| 414 | + |
| 415 | + // Empty vector of indices |
| 416 | + std::vector<ArrayType::Index> indices; |
| 417 | + |
| 418 | + // Attempt to set multiple indices to 42 |
| 419 | + array.set_multiple(indices, 42); |
| 420 | + |
| 421 | + // Verify that all entries remain unchanged |
| 422 | + for (int age = 0; age < 2; ++age) { |
| 423 | + for (int gender = 0; gender < static_cast<int>(Dim2::Count); ++gender) { |
| 424 | + EXPECT_EQ((array[{mio::Index<Dim1>(age), static_cast<Dim2>(gender)}]), 5); |
| 425 | + } |
| 426 | + } |
| 427 | +} |
0 commit comments