diff --git a/src/core_test/cases/all_cases.cc b/src/core_test/cases/all_cases.cc index 4758b56..e5b7073 100644 --- a/src/core_test/cases/all_cases.cc +++ b/src/core_test/cases/all_cases.cc @@ -1,25 +1,30 @@ #include +#include + +#include "ranges/ranges.h" +#include "all_cases/all_cases.h" +#include "short_code/short_code.h" +#include "common_code/common_code.h" #include "helper/hash.h" -#include "helper/cases.h" #include "helper/expect.h" #include "helper/fixture.h" -#include "utility/exposer.h" - -#include "short_code/short_code.h" -#include "common_code/common_code.h" using klotski::array_sum; using klotski::cases::Ranges; using klotski::cases::AllCases; -using klotski::cases::BasicRanges; - using klotski::codec::ShortCode; using klotski::codec::CommonCode; +using klotski::cases::BasicRanges; +using klotski::cases::RangesUnion; +using klotski::cases::ALL_CASES_NUM; using klotski::cases::ALL_CASES_NUM_; using klotski::codec::SHORT_CODE_LIMIT; +constexpr auto Heads = RangesUnion::Heads; +constexpr auto NonHeads = std::to_array({3, 7, 11, 15}); + /// Forcibly modify private variables to reset state. EXPOSE_VAR(AllCases, bool, available_) @@ -51,14 +56,15 @@ protected: static void Verify() { const auto &all_cases = AllCases::instance().fetch(); for (int head = 0; head < 16; ++head) { - EXPECT_EQ(all_cases.ranges(head).size(), ALL_CASES_NUM[head]); // verify all cases size - EXPECT_EQ(helper::xxh3(all_cases.ranges(head)), ALL_CASES_XXH3[head]); // verify all cases checksum + const auto &ranges = all_cases.ranges(head); + EXPECT_EQ(ranges.size(), ALL_CASES_NUM[head]); // verify all cases size + EXPECT_EQ(helper::xxh3(ranges), ALL_CASES_XXH3[head]); // verify all cases checksum } } }; TEST_FF(AllCases, content) { - for (auto head : Heads) { + for (const auto head : Heads) { auto &cases = AllCases::instance().fetch().ranges(head); EXPECT_SORTED_AND_UNIQUE(cases); EXPECT_EQ(cases.size(), ALL_CASES_NUM[head]); // size verify @@ -73,9 +79,7 @@ TEST_FF(AllCases, content) { for (const auto code : AllCases::instance().fetch().codes()) { short_codes.emplace_back(code.to_short_code().unwrap()); } - EXPECT_EQ(short_codes.front(), 0); - EXPECT_SORTED_AND_UNIQUE(short_codes); - EXPECT_EQ(short_codes.back(), SHORT_CODE_LIMIT - 1); + EXPECT_IOTA(short_codes); } TEST_FF(AllCases, constant) { @@ -83,18 +87,17 @@ TEST_FF(AllCases, constant) { EXPECT_EQ(ALL_CASES_NUM.size(), 16); EXPECT_EQ(array_sum(ALL_CASES_NUM), ALL_CASES_NUM_); - 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); - auto ranges = BasicRanges::instance().fetch(); ranges.reverse(); for (const auto head : Heads) { Ranges release; - ranges.derive(head, release); + ranges.derive(static_cast(head), release); EXPECT_EQ(release.size(), ALL_CASES_NUM[head]); } + + for (const auto head : NonHeads) { + EXPECT_EQ(ALL_CASES_NUM[head], 0); + } } TEST_FF(AllCases, all_cases) { diff --git a/src/core_test/cases/basic_ranges.cc b/src/core_test/cases/basic_ranges.cc index f268de0..597e33b 100644 --- a/src/core_test/cases/basic_ranges.cc +++ b/src/core_test/cases/basic_ranges.cc @@ -1,19 +1,23 @@ #include +#include #include "group/group.h" +#include "ranges/ranges.h" +#include "all_cases/all_cases.h" + #include "helper/hash.h" -#include "helper/cases.h" #include "helper/expect.h" #include "helper/fixture.h" -#include "utility/exposer.h" +#include "helper/parallel.h" using klotski::array_sum; using klotski::cases::Ranges; -using klotski::cases::AllCases; using klotski::cases::BasicRanges; using klotski::group::BLOCK_NUM; using klotski::group::TYPE_ID_LIMIT; +using klotski::cases::BASIC_RANGES_NUM; +using klotski::cases::BASIC_RANGES_NUM_; /// Forcibly modify private variables to reset state. EXPOSE_VAR(BasicRanges, bool, available_) @@ -57,12 +61,12 @@ TEST_FF(BasicRanges, constant) { EXPECT_EQ(BASIC_RANGES_NUM.size(), TYPE_ID_LIMIT); EXPECT_EQ(array_sum(BASIC_RANGES_NUM), BASIC_RANGES_NUM_); - for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { - const auto [n, n_2x1, n_1x1] = BLOCK_NUM[type_id]; + TYPE_ID_PARALLEL({ Ranges ranges; - ranges.spawn(n, n_2x1, n_1x1); + const auto num = BLOCK_NUM[type_id]; + ranges.spawn(std::get<0>(num), std::get<1>(num), std::get<2>(num)); EXPECT_EQ(ranges.size(), BASIC_RANGES_NUM[type_id]); - } + }); } TEST_FF(BasicRanges, basic_ranges) { diff --git a/src/core_test/cases/helper/cases.h b/src/core_test/cases/helper/cases.h deleted file mode 100644 index 1313a8f..0000000 --- a/src/core_test/cases/helper/cases.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include "group/group.h" - -// TODO: move to `.cc` file -using klotski::cases::Ranges; -using klotski::cases::AllCases; -using klotski::codec::CommonCode; -using klotski::cases::BasicRanges; -using klotski::cases::RangesUnion; - -using klotski::group::BLOCK_NUM; -using klotski::cases::ALL_CASES_NUM; -using klotski::cases::ALL_CASES_NUM_; -using klotski::cases::BASIC_RANGES_NUM; -using klotski::cases::BASIC_RANGES_NUM_; - -// TODO: move to global helper - -/// All valid klotski heads. -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} diff --git a/src/core_test/group/group_union.cc b/src/core_test/group/group_union.cc index 37f9836..1f04e37 100644 --- a/src/core_test/group/group_union.cc +++ b/src/core_test/group/group_union.cc @@ -7,6 +7,8 @@ #include "helper/parallel.h" #include "helper/block_num.h" +#include "helper/expect.h" + #include "helper/group.h" #include "group/group.h" @@ -20,12 +22,6 @@ using klotski::group::GroupUnion; using klotski::group::TYPE_ID_LIMIT; using klotski::group::ALL_GROUP_NUM; -#define EXPECT_IOTA(R) \ - EXPECT_FALSE(R.empty()); \ - EXPECT_EQ(R.front(), 0); \ - EXPECT_SORTED_AND_UNIQUE(R); \ - EXPECT_EQ(R.back(), R.size() - 1) - #define EXPECT_REPEAT(R, val) \ EXPECT_FALSE(R.empty()); \ EXPECT_EQ(R.front(), val); \ diff --git a/src/core_test/helper/expect.h b/src/core_test/helper/expect.h index 867a14c..4856ab4 100644 --- a/src/core_test/helper/expect.h +++ b/src/core_test/helper/expect.h @@ -33,3 +33,11 @@ std::string ostream_capture(T obj) { EXPECT_TRUE(CommonCode::check(static_cast(head) << 32 | range)) // ----------------------------------------------------------------------------------------- // + +#define EXPECT_IOTA(R) \ + EXPECT_FALSE(R.empty()); \ + EXPECT_EQ(R.front(), 0); \ + EXPECT_SORTED_AND_UNIQUE(R); \ + EXPECT_EQ(R.back(), R.size() - 1) + +// ----------------------------------------------------------------------------------------- //