Browse Source

perf: update test modules

legacy
Dnomd343 2 years ago
parent
commit
a0ecbdfb71
  1. 8
      test/basic/all_cases.cc
  2. 8
      test/codec/short_code.cc
  3. 16
      test/group/advance.cc
  4. 5
      test/group/basic.cc
  5. 5
      test/group/group_info.cc

8
test/basic/all_cases.cc

@ -26,9 +26,7 @@ TEST(AllCases, basic_ranges_mutex) {
} }
usleep(1000); // wait 1ms -> avoid mutex unlocked usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING); EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING);
for (auto &t : threads) { for (auto &t : threads) { t.join(); }
t.join();
}
EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE); EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE);
} }
@ -59,9 +57,7 @@ TEST(AllCases, all_cases_mutex) {
} }
usleep(1000); // wait 1ms -> avoid mutex unlocked usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(AllCases::status(), AllCases::BUILDING); EXPECT_EQ(AllCases::status(), AllCases::BUILDING);
for (auto &t : threads) { for (auto &t : threads) { t.join(); }
t.join();
}
EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE); EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE);
} }

8
test/codec/short_code.cc

@ -54,9 +54,7 @@ TEST(ShortCode, speed_up) {
} }
usleep(1000); // wait 1ms -> avoid mutex unlocked usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING); EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING);
for (auto &t : threads) { for (auto &t : threads) { t.join(); }
t.join();
}
EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE); EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE);
/// speed up to fast mode /// speed up to fast mode
@ -66,9 +64,7 @@ TEST(ShortCode, speed_up) {
} }
usleep(1000); // wait 1ms -> avoid mutex unlocked usleep(1000); // wait 1ms -> avoid mutex unlocked
EXPECT_EQ(AllCases::status(), AllCases::BUILDING); EXPECT_EQ(AllCases::status(), AllCases::BUILDING);
for (auto &t : threads) { for (auto &t : threads) { t.join(); }
t.join();
}
EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE); EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE);
} }

16
test/group/advance.cc

@ -42,8 +42,7 @@ TEST(Group, all_cases) {
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
pool.submit(build, GroupType(type_id)); pool.submit(build, GroupType(type_id));
} }
pool.boot(); pool.boot().join(); // wait data build complete
pool.join(); // wait data build complete
std::vector<CommonCode> combine; std::vector<CommonCode> combine;
combine.reserve(ALL_CASES_SIZE_SUM); combine.reserve(ALL_CASES_SIZE_SUM);
@ -60,8 +59,7 @@ TEST(Group, all_cases) {
TEST(Group, group_cases) { TEST(Group, group_cases) {
auto build = [](CommonCode seed) -> std::vector<CommonCode> { auto build = [](CommonCode seed) -> std::vector<CommonCode> {
auto group = Group(seed); auto group = Group(seed);
auto tmp = group.cases(); auto cases = CommonCode::convert(group.cases()); // convert as CommonCodes
std::vector<CommonCode> cases(tmp.begin(), tmp.end()); // convert as CommonCodes
EXPECT_EQ(seed, std::min_element(cases.begin(), cases.end())->unwrap()); // confirm min seed EXPECT_EQ(seed, std::min_element(cases.begin(), cases.end())->unwrap()); // confirm min seed
EXPECT_EQ(cases.size(), group.size()); // verify group size EXPECT_EQ(cases.size(), group.size()); // verify group size
EXPECT_EQ(seed, group.seed()); // verify group seed EXPECT_EQ(seed, group.seed()); // verify group seed
@ -84,8 +82,8 @@ TEST(Group, group_cases) {
pool.boot(); pool.boot();
std::vector<CommonCode> all_cases; std::vector<CommonCode> all_cases;
all_cases.reserve(ALL_CASES_SIZE_SUM); all_cases.reserve(ALL_CASES_SIZE_SUM);
for (auto &&f : futures) { for (auto &&tmp : futures) {
auto cases = f.get(); auto cases = tmp.get();
all_cases.insert(all_cases.end(), cases.begin(), cases.end()); // combine build result all_cases.insert(all_cases.end(), cases.begin(), cases.end()); // combine build result
} }
std::sort(all_cases.begin(), all_cases.end()); std::sort(all_cases.begin(), all_cases.end());
@ -127,8 +125,7 @@ TEST(Group, build_groups) {
std::map<uint32_t, std::vector<CommonCode>> group_seeds; // <group_size, group_seeds> std::map<uint32_t, std::vector<CommonCode>> group_seeds; // <group_size, group_seeds>
for (uint32_t group_id = 0; group_id < groups.size(); ++group_id) { for (uint32_t group_id = 0; group_id < groups.size(); ++group_id) {
auto tmp = Group(type_id, group_id).cases(); auto group = CommonCode::convert(Group(type_id, group_id).cases());
std::vector<CommonCode> group(tmp.begin(), tmp.end());
std::sort(group.begin(), group.end()); std::sort(group.begin(), group.end());
std::sort(groups[group_id].begin(), groups[group_id].end()); std::sort(groups[group_id].begin(), groups[group_id].end());
@ -163,8 +160,7 @@ TEST(Group, build_groups) {
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
pool.submit(test, GroupType(type_id)); pool.submit(test, GroupType(type_id));
} }
pool.boot(); pool.boot().join();
pool.join();
char buffer[9]; char buffer[9];
std::string group_info_str; std::string group_info_str;

5
test/group/basic.cc

@ -127,12 +127,11 @@ TEST(Group, group_id) {
EXPECT_EQ(cases, sort(Group::cases(seed.to_raw_code()))); EXPECT_EQ(cases, sort(Group::cases(seed.to_raw_code())));
}; };
TinyPool pool; auto pool = TinyPool();
for (auto &&seed : GROUP_SEEDS) { for (auto &&seed : GROUP_SEEDS) {
pool.submit(test, CommonCode(seed)); pool.submit(test, CommonCode(seed));
} }
pool.boot(); pool.boot().join();
pool.join();
} }
TEST(Group, operators) { TEST(Group, operators) {

5
test/group/group_info.cc

@ -12,7 +12,6 @@ using klotski::Group;
using klotski::GroupCase; using klotski::GroupCase;
using klotski::GroupType; using klotski::GroupType;
using klotski::CommonCode; using klotski::CommonCode;
using klotski::TYPE_ID_LIMIT; using klotski::TYPE_ID_LIMIT;
TEST(Group, group_info_invalid) { TEST(Group, group_info_invalid) {
@ -38,9 +37,7 @@ TEST(Group, group_info_invalid) {
TEST(Group, group_info) { TEST(Group, group_info) {
auto test = [](GroupType group_type) { auto test = [](GroupType group_type) {
for (uint32_t group_id = 0; group_id < group_type.group_num(); ++group_id) { for (uint32_t group_id = 0; group_id < group_type.group_num(); ++group_id) {
auto tmp = Group(group_type, group_id).cases(); auto cases = CommonCode::convert(Group(group_type, group_id).cases());
std::vector<CommonCode> cases(tmp.begin(), tmp.end());
auto min = *std::min_element(cases.begin(), cases.end()); auto min = *std::min_element(cases.begin(), cases.end());
auto max = *std::max_element(cases.begin(), cases.end()); auto max = *std::max_element(cases.begin(), cases.end());

Loading…
Cancel
Save