From 7675de8ff5cb975aff3ef6ccfab8596f425f72ab Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 12 Apr 2023 11:02:56 +0800 Subject: [PATCH] test: update core next cases test --- test/CMakeLists.txt | 2 +- test/core/core.cc | 49 ++++++++++++++++++++------------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4885750..1c03aa4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -57,7 +57,7 @@ add_test(NAME codec COMMAND test_codec) set(TEST_CORE_SRC core/core.cc) add_executable(test_core ${TEST_CORE_SRC}) -target_link_libraries(test_core ${TEST_DEPS}) +target_link_libraries(test_core ${TEST_DEPS} absl::flat_hash_map) add_test(NAME core COMMAND test_core) ################################################################################ diff --git a/test/core/core.cc b/test/core/core.cc index 054e471..f7c7016 100644 --- a/test/core/core.cc +++ b/test/core/core.cc @@ -1,40 +1,35 @@ #include #include "core.h" +#include "group.h" #include "all_cases.h" #include "gtest/gtest.h" +using klotski::Group; using klotski::RawCode; using klotski::AllCases; -TEST(Core, demo) { - auto raw_codes = std::unordered_set(); -// auto raw_codes_ = std::vector(); +using klotski::TYPE_ID_LIMIT; - raw_codes.reserve(klotski::ALL_CASES_SIZE_SUM); -// raw_codes_.reserve(klotski::ALL_CASES_SIZE_SUM); - - for (auto &&common_code : AllCases::release()) { // load all raw codes - -// EXPECT_NE(common_code.to_raw_code(), 0); - - raw_codes.emplace(common_code.to_raw_code().unwrap()); -// raw_codes_.emplace_back(common_code.to_raw_code().unwrap()); - } - - std::cout << "init ok" << std::endl; - - auto core = klotski::Core( - [&raw_codes](auto &&code, auto &&mask) { - EXPECT_NE(raw_codes.find(code), raw_codes.end()); -// new_case(std::forward(code), std::forward(mask)); +TEST(Core, next_cases) { + auto test = [](uint32_t type_id) { + auto raw_codes = std::unordered_set(); + raw_codes.reserve(klotski::ALL_CASES_SIZE_SUM); + for (auto &&common_code: Group::all_cases(type_id)) { // load all cases in a type + raw_codes.emplace(common_code.to_raw_code().unwrap()); } - ); - - for (auto &&raw_code : raw_codes) { - core.next_cases(raw_code, 0); + auto core = klotski::Core( + [&raw_codes](auto &&code, auto &&mask) { + EXPECT_NE(raw_codes.find(code), raw_codes.end()); // verify next case + EXPECT_EQ(mask >> __builtin_ctzll(mask), 0b111); // verify mask + } + ); + for (auto &&raw_code: raw_codes) { + core.next_cases(raw_code, 0); // search next cases + } + }; + // TODO: using multi-threads + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { + test(type_id); } - - -// EXPECT_EQ(raw_codes.size(), 29334498); }