diff --git a/src/core_test/CMakeLists.txt b/src/core_test/CMakeLists.txt index dd5ff1a..0ef2efa 100644 --- a/src/core_test/CMakeLists.txt +++ b/src/core_test/CMakeLists.txt @@ -10,9 +10,6 @@ set(KLSK_TEST_DEPS klotski_c klotski_core include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -# TODO: remove it -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utility) - # ------------------------------------------------------------------------------------ # set(KLSK_TEST_CASES_SRC diff --git a/src/core_test/cases/helper/cases.h b/src/core_test/cases/helper/cases.h index 1809282..9d6d4f9 100644 --- a/src/core_test/cases/helper/cases.h +++ b/src/core_test/cases/helper/cases.h @@ -16,7 +16,7 @@ using klotski::cases::RangesUnion; using klotski::cases::BLOCK_NUM; using klotski::cases::ALL_CASES_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_; diff --git a/src/core_test/cases/ranges.cc b/src/core_test/cases/ranges.cc index 95efc0d..75cc82a 100644 --- a/src/core_test/cases/ranges.cc +++ b/src/core_test/cases/ranges.cc @@ -25,7 +25,6 @@ TEST(Ranges, spawn) { Ranges ranges; ranges.spawn(n, n_2x1, n_1x1); EXPECT_SORTED_AND_UNIQUE(ranges); // sorted and unique - for (const auto range : ranges) { const auto [val_1x1, val_1x2, val_2x1] = cal_block_num(range); EXPECT_EQ(val_1x1, n_1x1); @@ -55,16 +54,23 @@ TEST(Ranges, derive) { } } +TEST(Ranges, append) { + Ranges ranges; + for (auto [n, n_2x1, n_1x1] : BLOCK_NUM) { + Ranges r; + r.spawn(n, n_2x1, n_1x1); + auto &tmp = ranges += r; + EXPECT_EQ(tmp, ranges); // reference of ranges + } + std::stable_sort(ranges.begin(), ranges.end()); + EXPECT_EQ(ranges, BasicRanges::instance().fetch()); +} + TEST(Ranges, reverse) { auto ranges = BasicRanges::instance().fetch(); - Ranges reverse {ranges}; - - for (auto &x : reverse) { - x = range_reverse(x); // manual reverse - } + auto reverse = ranges | std::views::transform(range_reverse) | std::ranges::to(); ranges.reverse(); EXPECT_EQ(ranges, reverse); - ranges.reverse(); EXPECT_EQ(ranges, BasicRanges::instance().fetch()); } @@ -72,7 +78,6 @@ TEST(Ranges, reverse) { TEST(Ranges, combine) { Ranges all_ranges; RangesUnion all_cases; - all_ranges.reserve(BASIC_RANGES_NUM_); // pre reserve for (const auto head : Heads) { all_cases[head].reserve(ALL_CASES_NUM[head]); // pre reserve @@ -92,8 +97,8 @@ TEST(Ranges, combine) { for (const auto head : Heads) { std::ranges::stable_sort(all_cases[head].begin(), all_cases[head].end()); } - EXPECT_EQ(all_ranges, BasicRanges::instance().fetch()); // verify content - EXPECT_EQ(all_cases, AllCases::instance().fetch()); // verify content + EXPECT_EQ(all_ranges, BasicRanges::instance().fetch()); // verify all ranges + EXPECT_EQ(all_cases, AllCases::instance().fetch()); // verify all cases all_ranges.reverse(); // reverse ranges for derive for (const auto head : Heads) { @@ -102,12 +107,3 @@ TEST(Ranges, combine) { } EXPECT_EQ(all_cases, AllCases::instance().fetch()); // verify content } - -TEST(Ranges, operator) { - Ranges r, r1, r2; - r.spawn(5, 3, 4); - r.spawn(5, 4, 4); - r1.spawn(5, 3, 4); - r2.spawn(5, 4, 4); - EXPECT_EQ(r, r1 += r2); -} diff --git a/src/core_test/cases/ranges_union.cc b/src/core_test/cases/ranges_union.cc index d6a1d2d..1a4f5b9 100644 --- a/src/core_test/cases/ranges_union.cc +++ b/src/core_test/cases/ranges_union.cc @@ -1,35 +1,39 @@ #include -#include - -#include "hash.h" #include "helper/cases.h" +#include "utility/hash.h" #include "ranges/ranges.h" -static_assert(std::is_base_of_v, RangesUnion>); - constexpr std::string_view ALL_CASES_MD5 = "3888e9fab8d3cbb50908b12b147cfb23"; +static_assert(std::is_base_of_v, RangesUnion>); + TEST(RangesUnion, export) { std::string buffer; + buffer.reserve(ALL_CASES_NUM_ * 10); // [\dA-F]{9} + '\n' for (auto code : AllCases::instance().fetch().codes()) { buffer += std::format("{:09X}\n", code.unwrap()); } EXPECT_EQ(hash::md5(buffer), ALL_CASES_MD5); } -TEST(RangesUnion, operator) { - Ranges r, r1, r2; - r.spawn(5, 3, 4); - r.spawn(5, 4, 4); - r1.spawn(5, 3, 4); - r2.spawn(5, 4, 4); +TEST(RangesUnion, append) { + RangesUnion cases; + for (auto [n, n_2x1, n_1x1] : BLOCK_NUM) { + Ranges r; + r.spawn(n, n_2x1, n_1x1); + r.reverse(); + + RangesUnion ru; + for (const auto head : Heads) { + r.derive(head, ru[head]); + } + auto &tmp = cases += ru; + EXPECT_EQ(tmp, cases); // reference of cases + } - RangesUnion r_, r1_, r2_; for (const auto head : Heads) { - r.derive(head, r_[head]); - r1.derive(head, r1_[head]); - r2.derive(head, r2_[head]); + std::stable_sort(cases[head].begin(), cases[head].end()); } - EXPECT_EQ(r_, r1_ += r2_); + EXPECT_EQ(cases, AllCases::instance().fetch()); }