Skip to content

Commit

Permalink
#2168: Tests: Use LoadType in LB unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Jun 22, 2023
1 parent a57ff78 commit 6535815
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 129 deletions.
4 changes: 2 additions & 2 deletions tests/unit/collection/test_lb.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ TEST_F(TestRestoreLBData, test_restore_lb_data_data_1) {
for (int i=0; i<num_elms; ++i) {
vt::Index1D idx(i);

TimeType dur = (i % 10 + 1) * 0.1;
LoadType dur = (i % 10 + 1) * 0.1;
uint64_t ntocm = (i+1) % 3 + 2;
CommBytesType ntoc = (i+1) * 100;
uint64_t ctonm = (i+1) % 2 + 1;
Expand All @@ -551,7 +551,7 @@ TEST_F(TestRestoreLBData, test_restore_lb_data_data_1) {
if (elm_ptr != nullptr) {
auto elm_id = elm_ptr->getElmID();

std::vector<TimeType> dur_vec(2);
std::vector<LoadType> dur_vec(2);
dur_vec[i % 2] = dur;
lbdh.node_data_[phase][elm_id].whole_phase_load = dur;
lbdh.node_data_[phase][elm_id].subphase_loads = dur_vec;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/collection/test_model_comm_overhead.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
const auto work = proc_load_->at(0).at(id).whole_phase_load;

if (phase.subphase == PhaseOffset::WHOLE_PHASE) {
Expand Down Expand Up @@ -122,7 +122,7 @@ TEST_F(TestModelCommOverhead, test_model_comm_overhead_1) {
// Element 3 (home node == 3)
ElementIDStruct const elem3 = {3, 3};

ProcLoadMap proc_load = {{0, LoadMapType{{elem2, {TimeType{150}, {}}}}}};
ProcLoadMap proc_load = {{0, LoadMapType{{elem2, {LoadType{150}, {}}}}}};

ProcCommMap proc_comm = {
{0,
Expand Down Expand Up @@ -154,8 +154,8 @@ TEST_F(TestModelCommOverhead, test_model_comm_overhead_1) {
);
test_model->setLoads(&proc_load, &proc_comm);

std::unordered_map<PhaseType, TimeType> expected_work = {
{0, TimeType{296}}, {1, TimeType{295.5}}
std::unordered_map<PhaseType, LoadType> expected_work = {
{0, LoadType{296}}, {1, LoadType{295.5}}
};

for (; num_phases < 2; ++num_phases) {
Expand Down
44 changes: 22 additions & 22 deletions tests/unit/collection/test_model_linear_model.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
// Most recent phase will be at the end of vector
return proc_load_->at(num_phases + phase.phases).at(id).whole_phase_load;
}
Expand All @@ -106,41 +106,41 @@ TEST_F(TestLinearModel, test_model_linear_model_1) {
// For linear regression there needs to be at least 2 phases completed
// so we begin with 1 phase already done
std::unordered_map<PhaseType, LoadMapType> proc_loads{{0, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{10}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}
{ElementIDStruct{1,this_node}, {LoadType{10}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}
}}};
test_model->setLoads(&proc_loads, nullptr);
test_model->updateLoads(0);

// Work loads to be added in each test iteration
std::vector<LoadMapType> load_holder{
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{5}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{5}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{30}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{100}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{30}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{100}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{50}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{50}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{2}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{50}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{2}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{50}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{60}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{20}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{60}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{20}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{100}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{100}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}},
};

std::array<std::pair<TimeType, TimeType>, num_test_interations> expected_data{
std::make_pair(TimeType{0}, TimeType{-20}), // iter 0 results
std::make_pair(TimeType{35}, TimeType{110}), // iter 1 results
std::make_pair(TimeType{60}, TimeType{70}), // iter 2 results
std::make_pair(TimeType{24.5}, TimeType{65}), // iter 3 results
std::make_pair(TimeType{46}, TimeType{-5}), // iter 4 results
std::make_pair(TimeType{105}, TimeType{0}) // iter 5 results
std::array<std::pair<LoadType, LoadType>, num_test_interations> expected_data{
std::make_pair(LoadType{0}, LoadType{-20}), // iter 0 results
std::make_pair(LoadType{35}, LoadType{110}), // iter 1 results
std::make_pair(LoadType{60}, LoadType{70}), // iter 2 results
std::make_pair(LoadType{24.5}, LoadType{65}), // iter 3 results
std::make_pair(LoadType{46}, LoadType{-5}), // iter 4 results
std::make_pair(LoadType{105}, LoadType{0}) // iter 5 results
};

for (auto iter = 0; iter < num_test_interations; ++iter) {
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/collection/test_model_multiple_phases.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
// Here we return predicted loads for future phases
// For the sake of the test we use values from the past phases
return proc_load_->at(phase.phases).at(id).whole_phase_load;
Expand All @@ -100,17 +100,17 @@ TEST_F(TestModelMultiplePhases, test_model_multiple_phases_1) {
NodeType this_node = 0;
std::unordered_map<PhaseType, LoadMapType> proc_loads = {
{0, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{10}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{10}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}}},
{1, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{20}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{30}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{20}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{30}, {}}}}},
{2, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{30}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{30}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}}},
{3, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{40}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{5}, {}}}}}};
{ElementIDStruct{1,this_node}, {LoadType{40}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{5}, {}}}}}};

auto test_model =
std::make_shared<MultiplePhases>(std::make_shared<StubModel>(), 4);
Expand All @@ -122,7 +122,7 @@ TEST_F(TestModelMultiplePhases, test_model_multiple_phases_1) {
auto work_val = test_model->getModeledLoad(
obj, {PhaseOffset::NEXT_PHASE, PhaseOffset::WHOLE_PHASE}
);
EXPECT_EQ(work_val, obj.id == 1 ? TimeType{100} : TimeType{85});
EXPECT_EQ(work_val, obj.id == 1 ? LoadType{100} : LoadType{85});
}
}

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/collection/test_model_naive_persistence.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
EXPECT_LE(phase.phases, -1);
return proc_load_->at(getIndexFromPhase(phase.phases)).at(id).whole_phase_load;
}
Expand All @@ -103,17 +103,17 @@ TEST_F(TestModelNaivePersistence, test_model_naive_persistence_1) {
NodeType this_node = 0;
std::unordered_map<PhaseType, LoadMapType> proc_loads = {
{0, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{10}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{10}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}}},
{1, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{4}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{4}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}}},
{2, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{20}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{50}, {}}}}},
{ElementIDStruct{1,this_node}, {LoadType{20}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{50}, {}}}}},
{3, LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{40}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{100}, {}}}}}};
{ElementIDStruct{1,this_node}, {LoadType{40}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{100}, {}}}}}};

auto test_model =
std::make_shared<NaivePersistence>(std::make_shared<StubModel>());
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/collection/test_model_norm.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
return proc_load_->at(0).at(id).subphase_loads.at(phase.subphase);
}

Expand All @@ -107,8 +107,8 @@ TEST_F(TestModelNorm, test_model_norm_1) {
ProcLoadMap proc_load = {
{0,
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{60}, {TimeType{10}, TimeType{20}, TimeType{30}}}},
{ElementIDStruct{2,this_node}, {TimeType{150}, {TimeType{40}, TimeType{50}, TimeType{60}}}}}}};
{ElementIDStruct{1,this_node}, {LoadType{60}, {LoadType{10}, LoadType{20}, LoadType{30}}}},
{ElementIDStruct{2,this_node}, {LoadType{150}, {LoadType{40}, LoadType{50}, LoadType{60}}}}}}};

auto test_model = std::make_shared<Norm>(std::make_shared<StubModel>(), 3.0);
test_model->setLoads(&proc_load, nullptr);
Expand Down Expand Up @@ -138,16 +138,16 @@ TEST_F(TestModelNorm, test_model_norm_2) {
ProcLoadMap proc_load = {
{0,
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{60}, {TimeType{10}, TimeType{20}, TimeType{30}}}},
{ElementIDStruct{2,this_node}, {TimeType{150}, {TimeType{40}, TimeType{50}, TimeType{60}}}}}}};
{ElementIDStruct{1,this_node}, {LoadType{60}, {LoadType{10}, LoadType{20}, LoadType{30}}}},
{ElementIDStruct{2,this_node}, {LoadType{150}, {LoadType{40}, LoadType{50}, LoadType{60}}}}}}};

// finite 'power' value
auto test_model = std::make_shared<Norm>(std::make_shared<StubModel>(), 3.0);
test_model->setLoads(&proc_load, nullptr);
test_model->updateLoads(0);

std::array<TimeType, 2> expected_norms = {
TimeType{33.019}, TimeType{73.986}};
std::array<LoadType, 2> expected_norms = {
LoadType{33.019}, LoadType{73.986}};

int objects_seen = 0;
for (auto&& obj : *test_model) {
Expand All @@ -167,16 +167,16 @@ TEST_F(TestModelNorm, test_model_norm_3) {
ProcLoadMap proc_load = {
{0,
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{60}, {TimeType{10}, TimeType{20}, TimeType{30}}}},
{ElementIDStruct{2,this_node}, {TimeType{150}, {TimeType{40}, TimeType{50}, TimeType{60}}}}}}};
{ElementIDStruct{1,this_node}, {LoadType{60}, {LoadType{10}, LoadType{20}, LoadType{30}}}},
{ElementIDStruct{2,this_node}, {LoadType{150}, {LoadType{40}, LoadType{50}, LoadType{60}}}}}}};

// infinite 'power' value
auto test_model = std::make_shared<Norm>(
std::make_shared<StubModel>(), std::numeric_limits<double>::infinity());
test_model->setLoads(&proc_load, nullptr);
test_model->updateLoads(0);

std::array<TimeType, 2> expected_norms = {TimeType{30}, TimeType{60}};
std::array<LoadType, 2> expected_norms = {LoadType{30}, LoadType{60}};

int objects_seen = 0;
for (auto&& obj : *test_model) {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/collection/test_model_per_collection.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ struct ConstantTestModel : ComposedModel {
proxy_(in_proxy)
{ }

TimeType getModeledLoad(ElementIDStruct, PhaseOffset) const override {
return static_cast<TimeType>(proxy_);
LoadType getModeledLoad(ElementIDStruct, PhaseOffset) const override {
return static_cast<LoadType>(proxy_);
}

private:
Expand Down Expand Up @@ -158,7 +158,7 @@ TEST_F(TestModelPerCollection, test_model_per_collection_1) {
obj, {PhaseOffset::NEXT_PHASE, PhaseOffset::WHOLE_PHASE}
);
if (id_proxy_map.find(obj) != id_proxy_map.end()) {
EXPECT_DOUBLE_EQ(work_val, static_cast<TimeType>(id_proxy_map[obj]));
EXPECT_DOUBLE_EQ(work_val, static_cast<LoadType>(id_proxy_map[obj]));
}
if (model->hasRawLoad()) {
auto raw_load_val = model->getRawLoad(obj, {PhaseOffset::NEXT_PHASE, PhaseOffset::WHOLE_PHASE});
Expand Down
46 changes: 23 additions & 23 deletions tests/unit/collection/test_model_persistence_median_last_n.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct StubModel : LoadModel {

void updateLoads(PhaseType) override {}

TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
LoadType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override {
// Most recent phase will be at the end of vector
return proc_load_->at(num_phases + phase.phases).at(id).whole_phase_load;
}
Expand Down Expand Up @@ -110,36 +110,36 @@ TEST_F(TestModelPersistenceMedianLastN, test_model_persistence_median_last_n_1)
// Work loads to be added in each test iteration
std::vector<LoadMapType> load_holder{
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{10}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{10}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{4}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{4}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{20}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{100}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{20}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{100}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{50}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{40}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{50}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{40}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{2}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{50}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{2}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{50}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{60}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{20}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{60}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{20}, {}}}},
LoadMapType{
{ElementIDStruct{1,this_node}, {TimeType{100}, {}}},
{ElementIDStruct{2,this_node}, {TimeType{10}, {}}}},
{ElementIDStruct{1,this_node}, {LoadType{100}, {}}},
{ElementIDStruct{2,this_node}, {LoadType{10}, {}}}},
};

std::array<std::pair<TimeType, TimeType>, num_total_phases> expected_medians{
std::make_pair(TimeType{10}, TimeType{40}), // iter 0 results
std::make_pair(TimeType{7}, TimeType{25}), // iter 1 results
std::make_pair(TimeType{10}, TimeType{40}), // iter 2 results
std::make_pair(TimeType{15}, TimeType{40}), // iter 3 results
std::make_pair(TimeType{12}, TimeType{45}), // iter 4 results
std::make_pair(TimeType{35}, TimeType{45}), // iter 5 results
std::make_pair(TimeType{55}, TimeType{30}) // iter 6 results
std::array<std::pair<LoadType, LoadType>, num_total_phases> expected_medians{
std::make_pair(LoadType{10}, LoadType{40}), // iter 0 results
std::make_pair(LoadType{7}, LoadType{25}), // iter 1 results
std::make_pair(LoadType{10}, LoadType{40}), // iter 2 results
std::make_pair(LoadType{15}, LoadType{40}), // iter 3 results
std::make_pair(LoadType{12}, LoadType{45}), // iter 4 results
std::make_pair(LoadType{35}, LoadType{45}), // iter 5 results
std::make_pair(LoadType{55}, LoadType{30}) // iter 6 results
};

for (auto iter = 0; iter < num_total_phases; ++iter) {
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/collection/test_model_raw_data.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ TEST_F(TestRawData, test_model_raw_data_scalar) {

// Work loads to be added in each test iteration
std::vector<LoadMapType> load_holder{
LoadMapType{{id1, {TimeType{5}, {TimeType{5}}}}, {id2, {TimeType{10}, {TimeType{10}}}}},
LoadMapType{{id1, {TimeType{30}, {TimeType{30}}}}, {id2, {TimeType{100}, {TimeType{100}}}}},
LoadMapType{{id1, {TimeType{50}, {TimeType{50}}}}, {id2, {TimeType{40}, {TimeType{40}}}}},
LoadMapType{{id1, {TimeType{2}, {TimeType{2}}}}, {id2, {TimeType{50}, {TimeType{50}}}}},
LoadMapType{{id1, {TimeType{60}, {TimeType{60}}}}, {id2, {TimeType{20}, {TimeType{20}}}}},
LoadMapType{{id1, {TimeType{100}, {TimeType{100}}}}, {id2, {TimeType{10}, {TimeType{10}}}}},
LoadMapType{{id1, {LoadType{5}, {LoadType{5}}}}, {id2, {LoadType{10}, {LoadType{10}}}}},
LoadMapType{{id1, {LoadType{30}, {LoadType{30}}}}, {id2, {LoadType{100}, {LoadType{100}}}}},
LoadMapType{{id1, {LoadType{50}, {LoadType{50}}}}, {id2, {LoadType{40}, {LoadType{40}}}}},
LoadMapType{{id1, {LoadType{2}, {LoadType{2}}}}, {id2, {LoadType{50}, {LoadType{50}}}}},
LoadMapType{{id1, {LoadType{60}, {LoadType{60}}}}, {id2, {LoadType{20}, {LoadType{20}}}}},
LoadMapType{{id1, {LoadType{100}, {LoadType{100}}}}, {id2, {LoadType{10}, {LoadType{10}}}}},
};

for (size_t iter = 0; iter < load_holder.size(); ++iter) {
Expand Down
Loading

0 comments on commit 6535815

Please sign in to comment.