From 77f9c89d90b8b29ac3f12b56267ed21b2e1f2a0b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 15 Sep 2024 11:48:24 +0800 Subject: [PATCH] test: add core next cases test suite --- src/core_test/core/core.cc | 87 +++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/src/core_test/core/core.cc b/src/core_test/core/core.cc index 3419aa0..3c89a94 100644 --- a/src/core_test/core/core.cc +++ b/src/core_test/core/core.cc @@ -1,21 +1,35 @@ #include -#include "core/core.h" - +#include #include +#include +#include +#include "core/core.h" #include "utils/common.h" - #include "all_cases/all_cases.h" #include "common_code/common_code.h" +#include "utility/hash.h" + +constexpr auto NEXT_CASES_XXH3 = std::to_array({ + 0xcd1920b50bc3bda1, 0xd881004a12384988, 0xbdefaaee9508848d, 0x2d06800538d394c2, + 0xb1c484293104fbfc, 0x0474e965bfd0bf98, 0x76891a6b2906d7d6, 0x2d06800538d394c2, + 0x878de6f355826c4d, 0xe67c680ab0cbfd21, 0x0b987953e6860717, 0x2d06800538d394c2, + 0x4a7599e1bdbffbb3, 0xb3cf1fdea988466a, 0x21226a4f692e1892, 0x2d06800538d394c2, +}); + using klotski::core::Core; using klotski::cases::AllCases; using klotski::codec::CommonCode; using klotski::codec::RawCode; -TEST(core, core) { +// TODO: test input mask with samples + +TEST(Core, core) { + + // TODO: test for each type_id std::vector raw_codes; raw_codes.reserve(klotski::cases::ALL_CASES_NUM_); @@ -54,7 +68,7 @@ TEST(core, core) { // TODO: support multi-thread test -TEST(core, mask) { +TEST(Core, mask) { std::vector raw_codes; raw_codes.reserve(klotski::cases::ALL_CASES_NUM_); @@ -116,13 +130,7 @@ TEST(core, mask) { return; } -// std::cout << RawCode::unsafe_create(full_mask) << std::endl; -// std::cout << RawCode::unsafe_create(ret) << std::endl; -// std::cout << RawCode::unsafe_create(removed) << std::endl; - auto diff = src ^ removed; -// std::cout << RawCode::unsafe_create(diff) << std::endl; -// std::cout << RawCode::unsafe_create(moved) << std::endl; int tmp; switch ((ret >> num) & 0b111) { @@ -147,10 +155,6 @@ TEST(core, mask) { return; } -// std::cout << "----------------" << std::endl; - -// EXPECT_NE(src, ret); - }); for (auto raw_code : raw_codes) { @@ -161,10 +165,53 @@ TEST(core, mask) { } -// auto raw_code = RawCode::from_common_code(0x1A9BF0C00).value(); -// auto raw_code = RawCode::from_common_code(0x4FEA13400).value(); -// src = raw_code.unwrap(); -// -// core.next_cases(raw_code.unwrap(), 0); +} + +TEST(Core, next_cases) { + + std::vector raw_codes; + + for (uint64_t head = 0; head < 16; ++head) { + for (const auto range : AllCases::instance().fetch()[head]) { + auto common_code = CommonCode::unsafe_create(head << 32 | range); + + auto raw_code = common_code.to_raw_code(); + raw_codes.emplace_back(raw_code); + } + break; + } + + std::vector result {}; + + std::vector tmp; + auto core = Core([&tmp](uint64_t ret, uint64_t mask) { + tmp.emplace_back(CommonCode::from_raw_code(ret).value()); + }); + + for (const auto raw_code : raw_codes) { + + result.emplace_back(raw_code.to_common_code()); +// std::cout << raw_code.to_common_code() << "->"; + core.next_cases(raw_code.unwrap(), 0); + + std::stable_sort(tmp.begin(), tmp.end()); + for (uint64_t i = 0; i < tmp.size(); ++i) { + result.emplace_back(tmp[i]); +// std::cout << tmp[i]; +// if (i + 1 != tmp.size()) { +// std::cout << "/"; +// } + } + + tmp.clear(); +// std::cout << std::endl; + + } + +// std::cout << result.size() << std::endl; + +// std::cout << std::hex << hash::xxh3(result) << std::endl; + + EXPECT_EQ(hash::xxh3(result), NEXT_CASES_XXH3[0]); }