Browse Source

test: add group cases test suite

legacy
Dnomd343 3 months ago
parent
commit
4090627808
  1. 4
      src/core/group/internal/group.cc
  2. 1
      src/core_test/CMakeLists.txt
  3. 34
      src/core_test/cases/group.cc
  4. 2
      src/core_test/cases/helper/cases.h
  5. 2
      src/core_test/cases/helper/group_impl.cc
  6. 100
      src/core_test/group_tmp/group_extend.cc
  7. 2
      src/core_test/group_tmp/group_union.cc

4
src/core/group/internal/group.cc

@ -59,6 +59,10 @@ RangesUnion Group::cases() const {
// TODO: do sort process // TODO: do sort process
for (int head = 0; head < 16; ++head) {
std::stable_sort(data[head].begin(), data[head].end());
}
return data; return data;
} }

1
src/core_test/CMakeLists.txt

@ -18,6 +18,7 @@ set(KLSK_TEST_CASES_SRC
cases/basic_ranges.cc cases/basic_ranges.cc
cases/all_cases.cc cases/all_cases.cc
cases/group_union.cc cases/group_union.cc
cases/group.cc
cases/helper/block_num.cc cases/helper/block_num.cc
cases/helper/group_impl.cc cases/helper/group_impl.cc
) )

34
src/core_test/cases/group.cc

@ -0,0 +1,34 @@
#include <gtest/gtest.h>
#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

2
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 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. /// Test fixture wrapper with concurrency tools.

2
src/core_test/cases/helper/group_impl.cc

@ -4,7 +4,7 @@
/// Extend ordered Group from the specified CommonCode seed. /// Extend ordered Group from the specified CommonCode seed.
static std::vector<CommonCode> extend_cases(CommonCode seed) { static std::vector<CommonCode> 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()); auto raw_codes = klotski::cases::Group::extend(seed.to_raw_code());
std::vector<CommonCode> common_codes {raw_codes.begin(), raw_codes.end()}; std::vector<CommonCode> common_codes {raw_codes.begin(), raw_codes.end()};
std::ranges::sort(common_codes.begin(), common_codes.end()); std::ranges::sort(common_codes.begin(), common_codes.end());

100
src/core_test/group_tmp/group_extend.cc

@ -1,100 +0,0 @@
#include <hash.h>
#include <group/group.h>
#include <gtest/gtest.h>
#include <ranges/ranges.h>
#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<std::tuple<int, int, int>> target_nums() {
std::vector<std::tuple<int, int, int>> 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<uint32_t> 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);
}

2
src/core_test/group_tmp/group_union.cc

@ -1,4 +1,4 @@
#include <common.h> #include <utils/common.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <thread> #include <thread>

Loading…
Cancel
Save