From 5642c4f28dd230261fbcd5859c2e49d3ba55b472 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 2 Nov 2024 10:56:02 +0800 Subject: [PATCH] test: split `group` test suites from `cases` --- src/core_test/CMakeLists.txt | 17 ++++++-- src/core_test/cases/all_cases.cc | 1 + src/core_test/cases/basic_ranges.cc | 1 + src/core_test/cases/helper/cases.h | 39 ++----------------- src/core_test/cases/ranges.cc | 1 + src/core_test/cases/ranges_union.cc | 1 + src/core_test/codec/common_code.cc | 8 ++++ .../{cases => group}/group_legacy.cc | 0 src/core_test/{cases => group}/group_pro.cc | 0 src/core_test/{cases => group}/group_union.cc | 0 src/core_test/group/helper/cases.h | 25 ++++++++++++ .../{cases => group}/helper/group_impl.cc | 2 + src/core_test/helper/expect.h | 17 ++++++++ 13 files changed, 72 insertions(+), 40 deletions(-) rename src/core_test/{cases => group}/group_legacy.cc (100%) rename src/core_test/{cases => group}/group_pro.cc (100%) rename src/core_test/{cases => group}/group_union.cc (100%) create mode 100644 src/core_test/group/helper/cases.h rename src/core_test/{cases => group}/helper/group_impl.cc (99%) diff --git a/src/core_test/CMakeLists.txt b/src/core_test/CMakeLists.txt index 5a523f5..e955fdd 100644 --- a/src/core_test/CMakeLists.txt +++ b/src/core_test/CMakeLists.txt @@ -28,10 +28,6 @@ set(KLSK_TEST_CASES_SRC cases/ranges_union.cc cases/basic_ranges.cc cases/all_cases.cc - cases/group_union.cc - cases/group_legacy.cc - cases/helper/group_impl.cc - cases/group_pro.cc ) add_executable(test_klotski_cases ${KLSK_TEST_CASES_SRC}) @@ -40,6 +36,19 @@ add_test(NAME klotski_cases COMMAND test_klotski_cases) # ------------------------------------------------------------------------------------ # +set(KLSK_TEST_GROUP_SRC + group/group_union.cc + group/group_legacy.cc + group/group_pro.cc + group/helper/group_impl.cc +) + +add_executable(test_klotski_group ${KLSK_TEST_GROUP_SRC}) +target_link_libraries(test_klotski_group PRIVATE ${KLSK_TEST_DEPS} test_helper) +add_test(NAME klotski_group COMMAND test_klotski_group) + +# ------------------------------------------------------------------------------------ # + set(KLSK_TEST_FFI_SRC ffi/all_cases.cc ) diff --git a/src/core_test/cases/all_cases.cc b/src/core_test/cases/all_cases.cc index 36c3cb3..42f4aec 100644 --- a/src/core_test/cases/all_cases.cc +++ b/src/core_test/cases/all_cases.cc @@ -2,6 +2,7 @@ #include "helper/hash.h" #include "helper/cases.h" +#include "helper/expect.h" #include "helper/fixture.h" #include "utility/exposer.h" diff --git a/src/core_test/cases/basic_ranges.cc b/src/core_test/cases/basic_ranges.cc index b9718e6..f268de0 100644 --- a/src/core_test/cases/basic_ranges.cc +++ b/src/core_test/cases/basic_ranges.cc @@ -3,6 +3,7 @@ #include "group/group.h" #include "helper/hash.h" #include "helper/cases.h" +#include "helper/expect.h" #include "helper/fixture.h" #include "utility/exposer.h" diff --git a/src/core_test/cases/helper/cases.h b/src/core_test/cases/helper/cases.h index fc87944..1313a8f 100644 --- a/src/core_test/cases/helper/cases.h +++ b/src/core_test/cases/helper/cases.h @@ -1,13 +1,10 @@ #pragma once #include -#include #include "group/group.h" -#include "helper/concurrent.h" - -// ----------------------------------------------------------------------------------------- // +// TODO: move to `.cc` file using klotski::cases::Ranges; using klotski::cases::AllCases; using klotski::codec::CommonCode; @@ -20,41 +17,11 @@ 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} - -// ----------------------------------------------------------------------------------------- // - -/// Assert that Ranges are sorted and unique. -#define EXPECT_SORTED_AND_UNIQUE(R) \ - EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \ - EXPECT_EQ(std::ranges::adjacent_find(R.begin(), R.end()), R.end()) // no duplicates - -/// Assert that two ordered arrays are in a containment relationship. -#define EXPECT_SUBSET(R1, R2) \ - EXPECT_TRUE(std::ranges::includes(R1.begin(), R1.end(), R2.begin(), R2.end())) - -/// Assert that all CommonCodes generated from head and Ranges are valid. -#define EXPECT_COMMON_CODES(head, ranges) \ - for (const auto range : ranges) \ - EXPECT_TRUE(CommonCode::check(static_cast(head) << 32 | range)) - -// ----------------------------------------------------------------------------------------- // - -/// Get the type_id upper limit. -uint32_t group_union_num(); - -/// Get the group_id upper limit. -uint32_t group_num(uint32_t type_id); - -/// Get cases contained in the specified type_id. -const std::vector& group_union_cases(uint32_t type_id); - -/// Get cases contained in the specified type_id and group_id. -const std::vector& group_cases(uint32_t type_id, uint32_t group_id); - -// ----------------------------------------------------------------------------------------- // diff --git a/src/core_test/cases/ranges.cc b/src/core_test/cases/ranges.cc index fb9ef13..5b4e38d 100644 --- a/src/core_test/cases/ranges.cc +++ b/src/core_test/cases/ranges.cc @@ -1,6 +1,7 @@ #include #include "helper/cases.h" +#include "helper/expect.h" #include "helper/block_num.h" #include "group/group.h" diff --git a/src/core_test/cases/ranges_union.cc b/src/core_test/cases/ranges_union.cc index c65af63..4c7ff25 100644 --- a/src/core_test/cases/ranges_union.cc +++ b/src/core_test/cases/ranges_union.cc @@ -2,6 +2,7 @@ #include "helper/hash.h" #include "helper/cases.h" +#include "helper/expect.h" #include "ranges/ranges.h" constexpr std::string_view ALL_CASES_MD5 = "3888e9fab8d3cbb50908b12b147cfb23"; diff --git a/src/core_test/codec/common_code.cc b/src/core_test/codec/common_code.cc index 84c02be..2a86771 100644 --- a/src/core_test/codec/common_code.cc +++ b/src/core_test/codec/common_code.cc @@ -10,6 +10,14 @@ #include "short_code/short_code.h" #include "common_code/common_code.h" +// TODO: add constexpr test + +// TODO: add std::hash test + +// TODO: test `std::is_default_constructible` +// TODO: test `std::is_copy_assignable` and `std::is_copy_constructible` +// TODO: test `std::is_move_assignable` and `std::is_move_constructible` + using klotski::codec::RawCode; using klotski::codec::ShortCode; using klotski::codec::CommonCode; diff --git a/src/core_test/cases/group_legacy.cc b/src/core_test/group/group_legacy.cc similarity index 100% rename from src/core_test/cases/group_legacy.cc rename to src/core_test/group/group_legacy.cc diff --git a/src/core_test/cases/group_pro.cc b/src/core_test/group/group_pro.cc similarity index 100% rename from src/core_test/cases/group_pro.cc rename to src/core_test/group/group_pro.cc diff --git a/src/core_test/cases/group_union.cc b/src/core_test/group/group_union.cc similarity index 100% rename from src/core_test/cases/group_union.cc rename to src/core_test/group/group_union.cc diff --git a/src/core_test/group/helper/cases.h b/src/core_test/group/helper/cases.h new file mode 100644 index 0000000..31306c2 --- /dev/null +++ b/src/core_test/group/helper/cases.h @@ -0,0 +1,25 @@ +#pragma once + +#include "group/group.h" + +// TODO: move to `.cc` file +using klotski::cases::AllCases; +using klotski::codec::CommonCode; + +// ----------------------------------------------------------------------------------------- // + +// TODO: using global test helper + +/// Get the type_id upper limit. +uint32_t group_union_num(); + +/// Get the group_id upper limit. +uint32_t group_num(uint32_t type_id); + +/// Get cases contained in the specified type_id. +const std::vector& group_union_cases(uint32_t type_id); + +/// Get cases contained in the specified type_id and group_id. +const std::vector& group_cases(uint32_t type_id, uint32_t group_id); + +// ----------------------------------------------------------------------------------------- // diff --git a/src/core_test/cases/helper/group_impl.cc b/src/core_test/group/helper/group_impl.cc similarity index 99% rename from src/core_test/cases/helper/group_impl.cc rename to src/core_test/group/helper/group_impl.cc index 8dc5529..475c4ba 100644 --- a/src/core_test/cases/helper/group_impl.cc +++ b/src/core_test/group/helper/group_impl.cc @@ -1,5 +1,7 @@ #include "cases.h" +#include + #include "helper/block_num.h" // TODO: multi-threads builder diff --git a/src/core_test/helper/expect.h b/src/core_test/helper/expect.h index 59f3f25..867a14c 100644 --- a/src/core_test/helper/expect.h +++ b/src/core_test/helper/expect.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include // ----------------------------------------------------------------------------------------- // @@ -16,3 +17,19 @@ std::string ostream_capture(T obj) { #define EXPECT_OSTREAM(obj, expect) EXPECT_EQ(ostream_capture(obj), expect) // ----------------------------------------------------------------------------------------- // + +/// Assert that Ranges are sorted and unique. +#define EXPECT_SORTED_AND_UNIQUE(R) \ + EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \ + EXPECT_EQ(std::ranges::adjacent_find(R.begin(), R.end()), R.end()) // no duplicates + +/// Assert that two ordered arrays are in a containment relationship. +#define EXPECT_SUBSET(R1, R2) \ + EXPECT_TRUE(std::ranges::includes(R1.begin(), R1.end(), R2.begin(), R2.end())) + +/// Assert that all CommonCodes generated from head and Ranges are valid. +#define EXPECT_COMMON_CODES(head, ranges) \ + for (const auto range : ranges) \ + EXPECT_TRUE(CommonCode::check(static_cast(head) << 32 | range)) + +// ----------------------------------------------------------------------------------------- //