Skip to content

Commit

Permalink
#32: add comments to the Info class unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlamonthezie committed Jul 1, 2024
1 parent 265e1e3 commit 8c42bee
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions tests/unit/test_api_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,51 @@

namespace vt::tv::tests::unit {

/**
* Represents a sample set of data for the tests Info class tests
*/
struct Sample {

public:
std::unordered_map<NodeType, Rank> ranks;
std::unordered_map<ElementIDType, ObjectWork> objects;
std::unordered_map<ElementIDType, ObjectWork> object_work_map;
std::unordered_map<ElementIDType, ObjectInfo> 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<NodeType, Rank> ranks = std::unordered_map<NodeType, Rank>();
std::unordered_map<ElementIDType, ObjectWork> objects = std::unordered_map<ElementIDType, ObjectWork>();
std::unordered_map<ElementIDType, ObjectWork> object_work_map = std::unordered_map<ElementIDType, ObjectWork>();
std::unordered_map<ElementIDType, ObjectInfo> object_info_map = std::unordered_map<ElementIDType, ObjectInfo>();

std::vector<size_t> in_index;

for (NodeType rank_id = 0; rank_id < num_ranks; rank_id++) {
// Add some objects
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<SubphaseType, TimeType> sub_phase_loads = std::unordered_map<SubphaseType, TimeType>();
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<PhaseType, PhaseWork> phase_info = std::unordered_map<PhaseType, PhaseWork>();
auto phase = PhaseWork(0, objects);
auto phase = PhaseWork(0, object_work_map);
phase_info.insert(std::make_pair(0, phase));

// Add some ranks
Expand All @@ -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;
}
Expand All @@ -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> info = std::make_unique<Info>();
EXPECT_EQ(info->getNumRanks(), 0);
}
std::cout << "Testing empty" << std::endl;
std::unique_ptr<Info> info_00 = std::make_unique<Info>();
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> info_01 = std::make_unique<Info>(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> info_02 = std::make_unique<Info>(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

0 comments on commit 8c42bee

Please sign in to comment.