From a0ecbdfb716e97d81a9d9d2ad940d3308cef6739 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 30 Apr 2023 02:09:58 +0800 Subject: [PATCH] perf: update test modules --- test/basic/all_cases.cc | 8 ++------ test/codec/short_code.cc | 8 ++------ test/group/advance.cc | 16 ++++++---------- test/group/basic.cc | 5 ++--- test/group/group_info.cc | 5 +---- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/test/basic/all_cases.cc b/test/basic/all_cases.cc index a678250..4239eba 100644 --- a/test/basic/all_cases.cc +++ b/test/basic/all_cases.cc @@ -26,9 +26,7 @@ TEST(AllCases, basic_ranges_mutex) { } usleep(1000); // wait 1ms -> avoid mutex unlocked EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING); - for (auto &t : threads) { - t.join(); - } + for (auto &t : threads) { t.join(); } EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE); } @@ -59,9 +57,7 @@ TEST(AllCases, all_cases_mutex) { } usleep(1000); // wait 1ms -> avoid mutex unlocked EXPECT_EQ(AllCases::status(), AllCases::BUILDING); - for (auto &t : threads) { - t.join(); - } + for (auto &t : threads) { t.join(); } EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE); } diff --git a/test/codec/short_code.cc b/test/codec/short_code.cc index 6bb0313..01a60b5 100644 --- a/test/codec/short_code.cc +++ b/test/codec/short_code.cc @@ -54,9 +54,7 @@ TEST(ShortCode, speed_up) { } usleep(1000); // wait 1ms -> avoid mutex unlocked EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING); - for (auto &t : threads) { - t.join(); - } + for (auto &t : threads) { t.join(); } EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE); /// speed up to fast mode @@ -66,9 +64,7 @@ TEST(ShortCode, speed_up) { } usleep(1000); // wait 1ms -> avoid mutex unlocked EXPECT_EQ(AllCases::status(), AllCases::BUILDING); - for (auto &t : threads) { - t.join(); - } + for (auto &t : threads) { t.join(); } EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE); } diff --git a/test/group/advance.cc b/test/group/advance.cc index edf09a6..9867aee 100644 --- a/test/group/advance.cc +++ b/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) { pool.submit(build, GroupType(type_id)); } - pool.boot(); - pool.join(); // wait data build complete + pool.boot().join(); // wait data build complete std::vector combine; combine.reserve(ALL_CASES_SIZE_SUM); @@ -60,8 +59,7 @@ TEST(Group, all_cases) { TEST(Group, group_cases) { auto build = [](CommonCode seed) -> std::vector { auto group = Group(seed); - auto tmp = group.cases(); - std::vector cases(tmp.begin(), tmp.end()); // convert as CommonCodes + auto cases = CommonCode::convert(group.cases()); // convert as CommonCodes 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(seed, group.seed()); // verify group seed @@ -84,8 +82,8 @@ TEST(Group, group_cases) { pool.boot(); std::vector all_cases; all_cases.reserve(ALL_CASES_SIZE_SUM); - for (auto &&f : futures) { - auto cases = f.get(); + for (auto &&tmp : futures) { + auto cases = tmp.get(); all_cases.insert(all_cases.end(), cases.begin(), cases.end()); // combine build result } std::sort(all_cases.begin(), all_cases.end()); @@ -127,8 +125,7 @@ TEST(Group, build_groups) { std::map> group_seeds; // for (uint32_t group_id = 0; group_id < groups.size(); ++group_id) { - auto tmp = Group(type_id, group_id).cases(); - std::vector group(tmp.begin(), tmp.end()); + auto group = CommonCode::convert(Group(type_id, group_id).cases()); std::sort(group.begin(), group.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) { pool.submit(test, GroupType(type_id)); } - pool.boot(); - pool.join(); + pool.boot().join(); char buffer[9]; std::string group_info_str; diff --git a/test/group/basic.cc b/test/group/basic.cc index 57cb3a8..2039b6e 100644 --- a/test/group/basic.cc +++ b/test/group/basic.cc @@ -127,12 +127,11 @@ TEST(Group, group_id) { EXPECT_EQ(cases, sort(Group::cases(seed.to_raw_code()))); }; - TinyPool pool; + auto pool = TinyPool(); for (auto &&seed : GROUP_SEEDS) { pool.submit(test, CommonCode(seed)); } - pool.boot(); - pool.join(); + pool.boot().join(); } TEST(Group, operators) { diff --git a/test/group/group_info.cc b/test/group/group_info.cc index c529b6e..c5fda49 100644 --- a/test/group/group_info.cc +++ b/test/group/group_info.cc @@ -12,7 +12,6 @@ using klotski::Group; using klotski::GroupCase; using klotski::GroupType; using klotski::CommonCode; - using klotski::TYPE_ID_LIMIT; TEST(Group, group_info_invalid) { @@ -38,9 +37,7 @@ TEST(Group, group_info_invalid) { TEST(Group, group_info) { auto test = [](GroupType group_type) { for (uint32_t group_id = 0; group_id < group_type.group_num(); ++group_id) { - auto tmp = Group(group_type, group_id).cases(); - std::vector cases(tmp.begin(), tmp.end()); - + auto cases = CommonCode::convert(Group(group_type, group_id).cases()); auto min = *std::min_element(cases.begin(), cases.end()); auto max = *std::max_element(cases.begin(), cases.end());