From 5c227b50e7838dd503ff5388d0a55948c429d287 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 19 Feb 2023 15:18:38 +0800 Subject: [PATCH] test: short code tiny convert verify --- test/global/short_code.cc | 49 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/test/global/short_code.cc b/test/global/short_code.cc index d55ad39..89418f5 100644 --- a/test/global/short_code.cc +++ b/test/global/short_code.cc @@ -1,37 +1,56 @@ -#include "gtest/gtest.h" +#include "all_cases.h" #include "short_code.h" +#include "gtest/gtest.h" +#include "global_utils.h" +using klotski::AllCases; using klotski::ShortCode; using klotski::CommonCode; std::vector short_code_check(uint32_t start, uint32_t end) { - - // TODO: give me short_code range -> convert to common_code and archive it - // common_code convert to short_code -> verify normal mode - std::vector archive; - for (uint32_t short_code = start; short_code < end; ++short_code) { - auto common_code = ShortCode::unsafe_create(short_code).to_common_code(); - archive.emplace_back(common_code.unwrap()); - EXPECT_EQ(common_code.to_short_code().unwrap(), short_code); - } - return archive; - } TEST(GLOBAL, short_code) { - + /// create short code check tasks + auto pool = TinyPool(thread_num()); ShortCode::speed_up(ShortCode::NORMAL); + std::vector>> futures; - auto r = short_code_check(0, 100); + for (const auto &range : range_split(0, klotski::ALL_CASES_SIZE_SUM, 10000)) { +// for (const auto &range : range_split(0, 80000, 10000)) { - std::cout << r.size() << std::endl; +// std::cout << "[" << range.first << ", " << range.second << ")" << std::endl; + + futures.emplace_back( + pool.submit(short_code_check, range.first, range.second) + ); + } + /// run short code search + pool.boot(); + std::vector result; + for (auto &f : futures) { + auto ret = f.get(); + result.insert(result.end(), ret.begin(), ret.end()); + } + pool.join(); + +// std::cout << result.size() << std::endl; + + /// verify check result + std::vector 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); }