Browse Source

test: content and constant test of AllCases

legacy
Dnomd343 6 months ago
parent
commit
9ba27b70ae
  1. 65
      src/core_test/cases/all_cases.cc
  2. 9
      src/core_test/cases/basic_ranges.cc
  3. 4
      src/core_test/cases/cases_helper.h

65
src/core_test/cases/all_cases.cc

@ -1,5 +1,9 @@
#include "hash.h"
#include "helper.h"
#include "cases_helper.h"
#include "common_code/common_code.h"
using klotski::cases::Ranges;
using klotski::codec::CommonCode;
static constexpr auto ALL_CASES_XXH3 = std::to_array<uint64_t>({
0x71c8ff7a71c93da0, 0x2a5247ee8bfed666, 0xf4efc8fc692d58e2, 0x2d06800538d394c2,
@ -30,38 +34,55 @@ protected:
const auto &all_cases = AllCases::instance().fetch();
for (int head = 0; head < 16; ++head) {
EXPECT_EQ(all_cases[head].size(), ALL_CASES_NUM[head]); // verify all cases size
}
for (int head = 0; head < 16; ++head) {
EXPECT_EQ(hash::xxh3(all_cases[head]), ALL_CASES_XXH3[head]); // verify all cases checksum
}
}
};
TEST_FF(AllCases, constant) {
EXPECT_EQ(ALL_CASES_NUM_, 29334498);
TEST_FF(AllCases, content) {
auto verify = [](const uint64_t head) {
auto &cases = AllCases::instance().fetch()[head];
EXPECT_EQ(cases.size(), ALL_CASES_NUM[head]); // size verify
EXPECT_EQ(hash::xxh3(cases), ALL_CASES_XXH3[head]); // checksum verify
EXPECT_EQ(ALL_CASES_NUM[0], 2942906);
EXPECT_EQ(ALL_CASES_NUM[1], 2260392);
EXPECT_EQ(ALL_CASES_NUM[2], 2942906);
EXPECT_TRUE(std::ranges::is_sorted(cases.begin(), cases.end()));
const auto match = std::ranges::adjacent_find(cases.begin(), cases.end());
EXPECT_EQ(match, cases.end()); // no duplicates
EXPECT_EQ(ALL_CASES_NUM[4], 2322050);
EXPECT_EQ(ALL_CASES_NUM[5], 1876945);
EXPECT_EQ(ALL_CASES_NUM[6], 2322050);
auto &all = BasicRanges::instance().fetch(); // subset verify
EXPECT_TRUE(std::ranges::includes(all.begin(), all.end(), cases.begin(), cases.end()));
EXPECT_EQ(ALL_CASES_NUM[8], 2322050);
EXPECT_EQ(ALL_CASES_NUM[9], 1876945);
EXPECT_EQ(ALL_CASES_NUM[10], 2322050);
for (const auto range : cases) {
CommonCode::check(head << 32 | range); // release verify
}
};
EXPECT_EQ(ALL_CASES_NUM[12], 2942906);
EXPECT_EQ(ALL_CASES_NUM[13], 2260392);
EXPECT_EQ(ALL_CASES_NUM[14], 2942906);
for (int head = 0; head < 16; ++head) {
if (head % 4 != 3) {
verify(head);
continue;
}
EXPECT_EQ(AllCases::instance().fetch()[head].size(), 0);
}
}
EXPECT_EQ(ALL_CASES_NUM[3], 0);
EXPECT_EQ(ALL_CASES_NUM[7], 0);
EXPECT_EQ(ALL_CASES_NUM[11], 0);
EXPECT_EQ(ALL_CASES_NUM[15], 0);
TEST_FF(AllCases, constant) {
EXPECT_EQ(ALL_CASES_NUM_, 29334498);
EXPECT_EQ(ALL_CASES_NUM.size(), 16);
EXPECT_EQ(array_sum(ALL_CASES_NUM), ALL_CASES_NUM_);
EXPECT_EQ(klotski::array_sum(ALL_CASES_NUM), ALL_CASES_NUM_);
auto ranges = BasicRanges::instance().fetch();
ranges.reverse();
for (int head = 0; head < 16; ++head) {
if (head % 4 == 3) {
EXPECT_EQ(ALL_CASES_NUM[head], 0);
continue;
}
Ranges release;
ranges.derive(head, release);
EXPECT_EQ(release.size(), ALL_CASES_NUM[head]);
}
}
TEST_FF(AllCases, all_cases) {

9
src/core_test/cases/basic_ranges.cc

@ -1,9 +1,10 @@
#include "hash.h"
#include "helper.h"
#include "group/group.h"
#include "cases_helper.h"
using klotski::cases::Ranges;
using klotski::cases::BLOCK_NUM;
using klotski::cases::TYPE_ID_LIMIT;
static constexpr uint64_t BASIC_RANGES_XXH3 = 0x34fce9da6a052533;
@ -45,12 +46,12 @@ TEST_FF(BasicRanges, content) {
TEST_FF(BasicRanges, constant) {
EXPECT_EQ(BASIC_RANGES_NUM_, 7311885);
EXPECT_EQ(BASIC_RANGES_NUM.size(), TYPE_ID_LIMIT);
EXPECT_EQ(array_sum(BASIC_RANGES_NUM), BASIC_RANGES_NUM_);
Ranges ranges;
for (uint32_t type_id = 0; type_id < klotski::cases::TYPE_ID_LIMIT; ++type_id) {
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
auto [n, n_2x1, n_1x1] = BLOCK_NUM[type_id];
ranges.clear();
Ranges ranges;
ranges.spawn(n, n_2x1, n_1x1);
EXPECT_EQ(ranges.size(), BASIC_RANGES_NUM[type_id]);
}

4
src/core_test/cases/helper.h → src/core_test/cases/cases_helper.h

@ -1,11 +1,11 @@
#pragma once
#include <algorithm>
#include <gtest/gtest.h>
#include "exposer.h"
#include "all_cases.h"
#include "concurrent.h"
#include "gtest/gtest.h"
#include "all_cases/all_cases.h"
using klotski::array_sum;
Loading…
Cancel
Save