From a9bd6c960e6179b38d28c96fa81c1c958747f910 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 10 Apr 2023 16:44:31 +0800 Subject: [PATCH] test: verify group all cases --- src/klotski_core/common_code/common_code.h | 3 +++ test/codec/common_code.cc | 3 +++ test/group/group.cc | 30 +++++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/klotski_core/common_code/common_code.h b/src/klotski_core/common_code/common_code.h index fbb45ea..4f7ad87 100644 --- a/src/klotski_core/common_code/common_code.h +++ b/src/klotski_core/common_code/common_code.h @@ -123,6 +123,9 @@ inline bool operator==(uint64_t c1, const CommonCode &c2) noexcept { return c1 = inline bool operator!=(uint64_t c1, const CommonCode &c2) noexcept { return c1 != c2.unwrap(); } inline bool operator==(const CommonCode &c1, uint64_t c2) noexcept { return c1.unwrap() == c2; } inline bool operator!=(const CommonCode &c1, uint64_t c2) noexcept { return c1.unwrap() != c2; } + +inline bool operator<(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() < c2.unwrap(); } +inline bool operator>(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() > c2.unwrap(); } inline bool operator==(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() == c2.unwrap(); } inline bool operator!=(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() != c2.unwrap(); } diff --git a/test/codec/common_code.cc b/test/codec/common_code.cc index acfdf53..169dec3 100644 --- a/test/codec/common_code.cc +++ b/test/codec/common_code.cc @@ -103,6 +103,9 @@ TEST(CommonCode, operators) { EXPECT_NE(TEST_CODE + 1, CommonCode(TEST_CODE)); // uint64_t != CommonCode EXPECT_NE(CommonCode(TEST_CODE), TEST_CODE + 1); // CommonCode != uint64_t EXPECT_NE(CommonCode(TEST_CODE), CommonCode::unsafe_create(TEST_CODE + 1)); // CommonCode != CommonCode + + EXPECT_LT(CommonCode(TEST_CODE), CommonCode::unsafe_create(TEST_CODE + 1)); // CommonCode < CommonCode + EXPECT_GT(CommonCode::unsafe_create(TEST_CODE + 1), CommonCode(TEST_CODE)); // CommonCode > CommonCode } TEST(CommonCode, code_convert) { diff --git a/test/group/group.cc b/test/group/group.cc index e82bed7..d04ff9b 100644 --- a/test/group/group.cc +++ b/test/group/group.cc @@ -1,14 +1,20 @@ #include +#include #include "md5.h" #include "group.h" #include "gtest/gtest.h" +#include "group/size.h" + using klotski::Group; using klotski::AllCases; using klotski::CommonCode; using klotski::TYPE_ID_LIMIT; using klotski::ALL_CASES_SIZE_SUM; +using klotski::GROUP_ALL_CASES_SIZE; + +using klotski::TYPE_ID_LIMIT; const char BLOCK_NUM_MD5[] = "46a7b3af6d039cbe2f7eaebdd196c6a2"; @@ -62,10 +68,26 @@ TEST(Group, block_num) { } TEST(Group, all_cases) { + std::vector> all_cases; + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { + all_cases.emplace_back(Group::all_cases(type_id)); // build test data + } - // TODO: all_cases number - // TODO: combine test - // TODO: data order - // TODO: test every cases (type_id) + std::vector combine_cases; + combine_cases.reserve(ALL_CASES_SIZE_SUM); + for (uint32_t id = 0; id < TYPE_ID_LIMIT; ++id) { + EXPECT_EQ(all_cases[id].size(), GROUP_ALL_CASES_SIZE[id]); // verify cases number + for (auto &&common_code : all_cases[id]) { + EXPECT_EQ(Group::type_id(common_code), id); // verify type id + combine_cases.emplace_back(common_code.unwrap()); + } + std::is_sorted(all_cases[id].begin(), all_cases[id].end()); // verify data order + } + EXPECT_EQ(combine_cases.size(), ALL_CASES_SIZE_SUM); // verify sum + auto all_cases_release = AllCases::release(); + std::stable_sort(combine_cases.begin(), combine_cases.end()); + for (uint32_t i = 0; i < combine_cases.size(); ++i) { + EXPECT_EQ(combine_cases[i], all_cases_release[i]); // verify after combined + } }