华容道高性能计算引擎
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

#include "all_cases.h"
#include "gtest/gtest.h"
#include "common_code.h"
#include "global_utils.h"
using klotski::AllCases;
using klotski::CommonCode;
std::vector<uint64_t> common_code_search(uint64_t start, uint64_t end) {
std::vector<uint64_t> ret;
for (uint64_t common_code = start; common_code < end; ++common_code) {
if (CommonCode::check(common_code)) {
ret.emplace_back(common_code); // valid common code
}
}
return ret;
}
TEST(GLOBAL, common_code) {
/// create common code check tasks
auto pool = TinyPool(thread_num());
std::vector<std::future<std::vector<uint64_t>>> futures;
for (const auto &range : range_split(0, 0x10'0000'0000, 0x10'0000)) {
futures.emplace_back(
pool.submit(common_code_search, range.first, range.second)
);
}
/// run common code search
pool.boot();
std::vector<uint64_t> result;
for (auto &f : futures) {
auto ret = f.get();
result.insert(result.end(), ret.begin(), ret.end());
}
pool.join();
/// verify check result
std::vector<uint64_t> all_cases;
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : AllCases::fetch()[head]) {
all_cases.emplace_back(head << 32 | range);
}
}
EXPECT_EQ(result, all_cases);
}