From 40906278080d4d988cf7702433b0d1d24d99890a Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 22 Sep 2024 10:21:33 +0800 Subject: [PATCH] test: add group cases test suite --- src/core/group/internal/group.cc | 4 + src/core_test/CMakeLists.txt | 1 + src/core_test/cases/group.cc | 34 ++++++++ src/core_test/cases/helper/cases.h | 2 + src/core_test/cases/helper/group_impl.cc | 2 +- src/core_test/group_tmp/group_extend.cc | 100 ----------------------- src/core_test/group_tmp/group_union.cc | 2 +- 7 files changed, 43 insertions(+), 102 deletions(-) create mode 100644 src/core_test/cases/group.cc delete mode 100644 src/core_test/group_tmp/group_extend.cc diff --git a/src/core/group/internal/group.cc b/src/core/group/internal/group.cc index 983de0f..76d21fb 100644 --- a/src/core/group/internal/group.cc +++ b/src/core/group/internal/group.cc @@ -59,6 +59,10 @@ RangesUnion Group::cases() const { // TODO: do sort process + for (int head = 0; head < 16; ++head) { + std::stable_sort(data[head].begin(), data[head].end()); + } + return data; } diff --git a/src/core_test/CMakeLists.txt b/src/core_test/CMakeLists.txt index 0ef2efa..1b8ab47 100644 --- a/src/core_test/CMakeLists.txt +++ b/src/core_test/CMakeLists.txt @@ -18,6 +18,7 @@ set(KLSK_TEST_CASES_SRC cases/basic_ranges.cc cases/all_cases.cc cases/group_union.cc + cases/group.cc cases/helper/block_num.cc cases/helper/group_impl.cc ) diff --git a/src/core_test/cases/group.cc b/src/core_test/cases/group.cc new file mode 100644 index 0000000..6df0567 --- /dev/null +++ b/src/core_test/cases/group.cc @@ -0,0 +1,34 @@ +#include + +#include "group/group.h" +#include "helper/cases.h" + +using klotski::cases::Group; +using klotski::cases::GroupUnion; + +using klotski::cases::TYPE_ID_LIMIT; + +// TODO: basic type_id / group_id verify with create / unsafe_create + +// TODO: hash check for every group + +TEST(Group, cases) { + + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { + auto group_union = GroupUnion::unsafe_create(type_id); + + for (auto group : group_union.groups()) { + + auto &expect = group_cases(type_id, group.group_id()); + auto codes = group.cases().codes(); + + EXPECT_EQ(codes, expect); + + EXPECT_EQ(codes.size(), group.size()); + + } + } + +} + +// TODO: test from_raw_code / from_short_code / from_common_code diff --git a/src/core_test/cases/helper/cases.h b/src/core_test/cases/helper/cases.h index be484d6..685873b 100644 --- a/src/core_test/cases/helper/cases.h +++ b/src/core_test/cases/helper/cases.h @@ -25,6 +25,8 @@ constexpr auto Heads = std::to_array({ 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14 }); +// TODO: add NonHeads -> {3, 7, 11, 15} + // ----------------------------------------------------------------------------------------- // /// Test fixture wrapper with concurrency tools. diff --git a/src/core_test/cases/helper/group_impl.cc b/src/core_test/cases/helper/group_impl.cc index d74cda1..ef08fb0 100644 --- a/src/core_test/cases/helper/group_impl.cc +++ b/src/core_test/cases/helper/group_impl.cc @@ -4,7 +4,7 @@ /// Extend ordered Group from the specified CommonCode seed. static std::vector extend_cases(CommonCode seed) { - // TODO: using inner build process + // TODO: using inner build process -> only allow calling klotski::core auto raw_codes = klotski::cases::Group::extend(seed.to_raw_code()); std::vector common_codes {raw_codes.begin(), raw_codes.end()}; std::ranges::sort(common_codes.begin(), common_codes.end()); diff --git a/src/core_test/group_tmp/group_extend.cc b/src/core_test/group_tmp/group_extend.cc deleted file mode 100644 index 5dafd32..0000000 --- a/src/core_test/group_tmp/group_extend.cc +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include -#include <__format/format_functions.h> - -TEST(Group, group_extend) { - // auto src = klotski::codec::RawCode::from_common_code(0x1A9BF0C00)->unwrap(); - // auto codes = klotski::cases::group_extend_from_seed(src); - // - // for (auto &code: codes) { - // auto raw_code = klotski::codec::RawCode::create(code).value(); - // code = raw_code.to_common_code().unwrap(); - // } - // std::sort(codes.begin(), codes.end()); - // EXPECT_EQ(codes.size(), 25955); - // - // auto index = std::lower_bound(codes.begin(), codes.end(), 0x1A9BF0C00) - codes.begin(); - // EXPECT_EQ(index, 7472); - // - // auto hash_ret = hash::xxh3(codes.data(), codes.size() * sizeof(uint64_t)); - // EXPECT_EQ(hash_ret, 0x91BD28A749312A6D); -} - -static std::vector> target_nums() { - - std::vector> results; - - for (int n = 0; n <= 7; ++n) { - for (int n_2x1 = 0; n_2x1 <= n; ++n_2x1) { - for (int n_1x1 = 0; n_1x1 <= (14 - n * 2); ++n_1x1) { - results.emplace_back(n, n_2x1, n_1x1); - } - } - } - - results.resize(203); - return results; -} - -TEST(Group, ranges) { - // auto ret = klotski::cases::spawn_ranges(2, 1, 4, 4); - // - // EXPECT_EQ(ret.size(), 34650); - // - // auto hash_ret = hash::xxh3(ret.data(), ret.size() * 4); - // EXPECT_EQ(hash_ret, 0xF6F87606E4205EAF); - - klotski::cases::Ranges kk {}; - - // std::vector ranges; - for (auto [n, n_2x1, n_1x1] : target_nums()) { - - kk.spawn(n, n_2x1, n_1x1); - - // kk.spawn_more(n, n_2x1, n_1x1); - - // auto kk = klotski::cases::spawn_ranges(n, n_2x1, n_1x1); - - // ranges.insert(ranges.end(), kk.begin(), kk.end()); - } - - EXPECT_EQ(kk.size(), 7311885); - - klotski::cases::Ranges pp {kk}; - for (auto &x : pp) { - x = klotski::range_reverse(x); - } - - // auto hash_ret = hash::xxh3(kk.ranges_); - // EXPECT_EQ(hash_ret, 0xA1E247B01D5A9545); - - klotski::cases::Ranges result; - // kk.derive(5, result); - klotski::cases::derive_demo(kk, pp, result, 5); - - EXPECT_EQ(result.size(), 1355971); - - // std::cout << result.size() << std::endl; - - EXPECT_EQ(hash::xxh3(result), 0xf00ecc84b6f678a6); - - // std::cout << std::format("{:x}", hash::xxh3(result)) << std::endl; - - -} - -TEST(Group, basic_ranges) { - // auto ret = klotski::cases::basic_ranges(); - // std::cout << ret.size() << std::endl; - - // EXPECT_EQ(ret.size(), 7311921); - - // auto hash_ret = hash::xxh3(ret); - // std::cout << std::format("{:X}", hash_ret) << std::endl; - - // EXPECT_EQ(hash_ret, 0xA1E247B01D5A9545); // no sorted - // EXPECT_EQ(hash_ret, 0x00A926AB1121230D); // no reversed - // EXPECT_EQ(hash_ret, 0x82B040060044E336); -} diff --git a/src/core_test/group_tmp/group_union.cc b/src/core_test/group_tmp/group_union.cc index 72014c2..ac50cbb 100644 --- a/src/core_test/group_tmp/group_union.cc +++ b/src/core_test/group_tmp/group_union.cc @@ -1,4 +1,4 @@ -#include +#include #include #include