diff --git a/tests/unit/test_api_info.cc b/tests/unit/test_api_info.cc index 7ca62ca8ac..34d8f01058 100644 --- a/tests/unit/test_api_info.cc +++ b/tests/unit/test_api_info.cc @@ -57,21 +57,29 @@ namespace vt::tv::tests::unit { +/** + * Represents a sample set of data for the tests Info class tests + */ struct Sample { public: std::unordered_map ranks; - std::unordered_map objects; + std::unordered_map object_work_map; std::unordered_map object_info_map; }; +/** + * Provides unit tests for the vttv.api.Info class + */ struct TestInfo : TestHarness { + /** + * Generates sample data using a single phase and a default phase load + */ auto create_sample(int num_ranks, int num_objects_per_rank) { std::unordered_map ranks = std::unordered_map(); - std::unordered_map objects = std::unordered_map(); + std::unordered_map object_work_map = std::unordered_map(); std::unordered_map object_info_map = std::unordered_map(); - std::vector in_index; for (NodeType rank_id = 0; rank_id < num_ranks; rank_id++) { @@ -79,18 +87,21 @@ struct TestInfo : TestHarness { for (auto object_index = 0; object_index < num_objects_per_rank; object_index++) { auto object_id = rank_id * num_objects_per_rank + object_index; auto phase_load = 2.0; + + // object work std::unordered_map sub_phase_loads = std::unordered_map(); - auto object = ObjectWork(object_id, phase_load, sub_phase_loads); - objects.insert(std::make_pair(object_id, object)); + auto object_work = ObjectWork(object_id, phase_load, sub_phase_loads); + object_work_map.insert(std::make_pair(object_id, object_work)); + // object info ObjectInfo object_info = ObjectInfo(object_id, rank_id, true, in_index); object_info_map.insert(std::make_pair(object_id, object_info)); } } - // Add some phase 0 + // Add a phase (id 0) std::unordered_map phase_info = std::unordered_map(); - auto phase = PhaseWork(0, objects); + auto phase = PhaseWork(0, object_work_map); phase_info.insert(std::make_pair(0, phase)); // Add some ranks @@ -99,10 +110,11 @@ struct TestInfo : TestHarness { ranks.insert(std::make_pair(rank_id, rank)); } + // Return sample data auto sample = Sample(); sample.ranks = ranks; sample.object_info_map = object_info_map; - sample.objects = objects; + sample.object_work_map = object_work_map; return sample; } @@ -112,35 +124,27 @@ struct TestInfo : TestHarness { } }; -/* - Common Assertions: EXPECT_EQ(a, b), EXPECT_TRUE(condition) - Common print: fmt::print( - format, var1, var2 etc. - ); +/** + * Test Info:get* methods */ +TEST_F(TestInfo, test_info_getter_methods) { - - - -TEST_F(TestInfo, test_info_get_num_ranks_empty) { - std::unique_ptr info = std::make_unique(); - EXPECT_EQ(info->getNumRanks(), 0); -} + std::cout << "Testing empty" << std::endl; + std::unique_ptr info_00 = std::make_unique(); + EXPECT_EQ(info_00->getNumRanks(), 0); + EXPECT_EQ(info_00->getAllObjectIDs().size(), 0) << "getAllObjectIDs() ok"; -TEST_F(TestInfo, test_info_get_num_ranks) { - // Initialize a info object, that will hold data for all ranks for all phases - auto sample_01 = create_sample(2, 5); std::unique_ptr info_01 = std::make_unique(sample_01.object_info_map, sample_01.ranks); - std::cout << "Test sample_01 (2 ranks, 5 objects per rank)" << std::endl; + std::cout << "Testing sample_01 (2 ranks, 5 objects per rank)" << std::endl; EXPECT_EQ(info_01->getNumRanks(), 2); - EXPECT_EQ(info_01->getAllObjectIDs().size(), sample_01.objects.size()) << "getAllObjectIDs() ok"; + EXPECT_EQ(info_01->getAllObjectIDs().size(), sample_01.object_work_map.size()) << "getAllObjectIDs() ok"; auto sample_02 = create_sample(6, 1); printf("Test sample_01 (6 ranks, 1 object per rank)\n"); std::unique_ptr info_02 = std::make_unique(sample_02.object_info_map, sample_02.ranks); EXPECT_EQ(info_02->getNumRanks(), 6); - EXPECT_EQ(info_02->getAllObjectIDs().size(), sample_02.objects.size()) << "getAllObjectIDs() ok"; + EXPECT_EQ(info_02->getAllObjectIDs().size(), sample_02.object_work_map.size()) << "getAllObjectIDs() ok"; } } // end namespace vt::tv::tests::unit