Browse Source

test: group cases support mutli-threads test

master
Dnomd343 1 year ago
parent
commit
d11d6fe551
  1. 11
      test/CMakeLists.txt
  2. 28
      test/group/build_cases.cc

11
test/CMakeLists.txt

@ -65,7 +65,7 @@ set(TEST_GROUP_SRC
group/build_cases.cc
)
add_executable(test_group ${TEST_GROUP_SRC})
target_link_libraries(test_group ${TEST_DEPS} md5 absl::flat_hash_map)
target_link_libraries(test_group ${TEST_DEPS} md5 tiny_pool absl::flat_hash_map)
add_test(NAME group COMMAND test_group)
#######################################################################################
@ -91,13 +91,4 @@ add_executable(test_codec_global ${TEST_CODEC_GLOBAL_SRC})
target_link_libraries(test_codec_global ${TEST_DEPS} tiny_pool)
add_test(NAME codec_global COMMAND test_codec_global)
# TODO: update cmake configure
#add_library(test_global_utils STATIC global/global_utils.cc)
#set(TEST_GLOBAL_DEPS ${TEST_DEPS} test_global_utils tiny_pool)
#add_executable(test_codec_global global/short_code.cc global/common_code.cc global/raw_code.cc)
#target_link_libraries(test_codec_global ${TEST_GLOBAL_DEPS})
#add_test(NAME codec_global COMMAND test_codec_global)
#######################################################################################

28
test/group/build_cases.cc

@ -4,6 +4,8 @@
#include "common_code.h"
#include "gtest/gtest.h"
#include "tiny_pool.h"
#include "group/type_id.h"
#include "group/group_seeds.h"
@ -48,22 +50,32 @@ TEST(Group, all_cases) {
}
TEST(Group, group_cases) {
// TODO: using multi-threads
std::vector<CommonCode> all_cases;
all_cases.reserve(ALL_CASES_SIZE_SUM);
for (auto &&seed : GROUP_SEEDS) {
auto test = [](CommonCode seed) -> std::vector<CommonCode> {
auto group_raw = Group::group_cases(RawCode::from_common_code(seed));
std::vector<CommonCode> group(group_raw.begin(), group_raw.end()); // convert as CommonCodes
EXPECT_EQ(seed, std::min_element(group.begin(), group.end())->unwrap()); // confirm min seed
all_cases.insert(all_cases.end(), group.begin(), group.end()); // archive group cases
uint32_t type_id = Group::type_id(CommonCode(seed)); // current type id
for (auto &&elem : group) {
EXPECT_EQ(Group::type_id(elem), type_id); // verify type id of group cases
}
return group;
};
auto pool = TinyPool();
std::vector<std::future<std::vector<CommonCode>>> futures;
for (auto &&seed : GROUP_SEEDS) {
futures.emplace_back(
pool.submit(test, CommonCode::unsafe_create(seed))
);
}
pool.boot();
std::vector<CommonCode> all_cases;
all_cases.reserve(ALL_CASES_SIZE_SUM);
for (auto &&f : futures) {
auto ret = f.get();
all_cases.insert(all_cases.end(), ret.begin(), ret.end());
}
std::sort(all_cases.begin(), all_cases.end());
EXPECT_EQ(all_cases, AllCases::release()); // verify all released cases

Loading…
Cancel
Save