From b0f3322fe9aea1322f56228bd94c69987e13b942 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 13 Oct 2024 17:53:18 +0800 Subject: [PATCH] test: next group theory test suites --- src/core/group/internal/group_pro.inl | 8 +- src/core_test/cases/group_pro.cc | 106 ++++++++++++++++++++++++++ src/core_test/cases/group_union.cc | 34 +++++++++ 3 files changed, 144 insertions(+), 4 deletions(-) diff --git a/src/core/group/internal/group_pro.inl b/src/core/group/internal/group_pro.inl index 7fe7e00..3a07ad1 100644 --- a/src/core/group/internal/group_pro.inl +++ b/src/core/group/internal/group_pro.inl @@ -102,13 +102,13 @@ constexpr GroupPro GroupPro::to_horizontal_mirror() const { return GroupPro::unsafe_create(type_id_, pattern_id_, 0); case MirrorType::NonMirror: if (mirror_toward_ == 0) { - return GroupPro::unsafe_create(type_id_, pattern_id_, 2); + return GroupPro::unsafe_create(type_id_, pattern_id_, 1); } else if (mirror_toward_ == 1) { - return GroupPro::unsafe_create(type_id_, pattern_id_, 3); - } else if (mirror_toward_ == 2) { return GroupPro::unsafe_create(type_id_, pattern_id_, 0); + } else if (mirror_toward_ == 2) { + return GroupPro::unsafe_create(type_id_, pattern_id_, 3); } - return GroupPro::unsafe_create(type_id_, pattern_id_, 1); + return GroupPro::unsafe_create(type_id_, pattern_id_, 2); } } diff --git a/src/core_test/cases/group_pro.cc b/src/core_test/cases/group_pro.cc index b196da4..22ea40b 100644 --- a/src/core_test/cases/group_pro.cc +++ b/src/core_test/cases/group_pro.cc @@ -1,8 +1,12 @@ #include +#include + #include "helper/group.h" #include "group/group.h" +#include "helper/parallel.h" + using klotski::cases::GroupPro; using klotski::cases::GroupUnion; @@ -29,3 +33,105 @@ TEST(GroupPro, demo) { EXPECT_EQ(group_2.cases().codes(), helper::group_cases(169, 0, group_2.mirror_toward())); } + +TEST(GroupPro, cases) { + GROUP_UNION_PARALLEL({ + for (auto group : group_union.groups_pro()) { + const auto &cases = helper::group_cases(group.type_id(), group.pattern_id(), group.mirror_toward()); + EXPECT_EQ(group.size(), cases.size()); + EXPECT_EQ(group.cases().codes(), cases); + + EXPECT_EQ((int)group.mirror_type(), helper::pattern_mirror_type(group.type_id(), group.pattern_id())); + + auto g1 = GroupPro::from_common_code(cases.front()); + EXPECT_EQ(g1.type_id(), group.type_id()); + EXPECT_EQ(g1.pattern_id(), group.pattern_id()); + EXPECT_EQ(g1.mirror_toward(), group.mirror_toward()); + + auto g2 = GroupPro::from_common_code(cases.back()); + EXPECT_EQ(g2.type_id(), group.type_id()); + EXPECT_EQ(g2.pattern_id(), group.pattern_id()); + EXPECT_EQ(g2.mirror_toward(), group.mirror_toward()); + } + }); +} + +TEST(GroupPro, v_mirror) { + GROUP_UNION_PARALLEL({ + for (auto group : group_union.groups_pro()) { + auto g = group.to_vertical_mirror(); + EXPECT_EQ(group.type_id(), g.type_id()); + EXPECT_EQ(group.pattern_id(), g.pattern_id()); + if (group.mirror_toward() == g.mirror_toward()) { + EXPECT_TRUE(group.is_vertical_mirror()); + + std::unordered_set cases; + for (const auto code : group.cases().codes()) { + cases.emplace(code); + } + for (const auto code : cases) { + auto mirror = CommonCode::unsafe_create(code).to_vertical_mirror(); + EXPECT_TRUE(cases.contains(mirror.unwrap())); + } + } else { + EXPECT_FALSE(group.is_vertical_mirror()); + + std::unordered_set cases_1; + std::unordered_set cases_2; + for (const auto code : group.cases().codes()) { + cases_1.emplace(code); + } + for (const auto code : g.cases().codes()) { + cases_2.emplace(code); + } + EXPECT_EQ(cases_1.size(), cases_2.size()); + + for (const auto code : cases_1) { + auto mirror = CommonCode::unsafe_create(code).to_vertical_mirror(); + EXPECT_FALSE(cases_1.contains(mirror.unwrap())); + EXPECT_TRUE(cases_2.contains(mirror.unwrap())); + } + } + } + }); +} + +TEST(GroupPro, h_mirror) { + GROUP_UNION_PARALLEL({ + for (auto group : group_union.groups_pro()) { + auto g = group.to_horizontal_mirror(); + EXPECT_EQ(group.type_id(), g.type_id()); + EXPECT_EQ(group.pattern_id(), g.pattern_id()); + if (group.mirror_toward() == g.mirror_toward()) { + EXPECT_TRUE(group.is_horizontal_mirror()); + + std::unordered_set cases; + for (const auto code : group.cases().codes()) { + cases.emplace(code); + } + for (const auto code : cases) { + auto mirror = CommonCode::unsafe_create(code).to_horizontal_mirror(); + EXPECT_TRUE(cases.contains(mirror.unwrap())); + } + } else { + EXPECT_FALSE(group.is_horizontal_mirror()); + + std::unordered_set cases_1; + std::unordered_set cases_2; + for (const auto code : group.cases().codes()) { + cases_1.emplace(code); + } + for (const auto code : g.cases().codes()) { + cases_2.emplace(code); + } + EXPECT_EQ(cases_1.size(), cases_2.size()); + + for (const auto code : cases_1) { + auto mirror = CommonCode::unsafe_create(code).to_horizontal_mirror(); + EXPECT_FALSE(cases_1.contains(mirror.unwrap())); + EXPECT_TRUE(cases_2.contains(mirror.unwrap())); + } + } + } + }); +} diff --git a/src/core_test/cases/group_union.cc b/src/core_test/cases/group_union.cc index 77d6d87..785d0b7 100644 --- a/src/core_test/cases/group_union.cc +++ b/src/core_test/cases/group_union.cc @@ -8,12 +8,15 @@ #include "helper/parallel.h" #include "helper/block_num.h" +#include "helper/group.h" + #include "group/group.h" #include "common_code/common_code.h" using klotski::codec::ShortCode; using klotski::cases::Group; +using klotski::cases::GroupPro; using klotski::cases::GroupUnion; using klotski::cases::TYPE_ID_LIMIT; @@ -90,6 +93,37 @@ TEST(GroupUnion, values) { }); } +TEST(GroupUnion, values_pro) { + GROUP_UNION_PARALLEL({ + auto type_id = group_union.unwrap(); + auto &cases = helper::group_union_cases(type_id); + + EXPECT_EQ(group_union.size(), cases.size()); + EXPECT_EQ(group_union.cases().codes(), cases); + EXPECT_EQ(group_union.group_num(), helper::group_union_group_num(type_id)); + EXPECT_EQ(group_union.pattern_num(), helper::group_union_pattern_num(type_id)); + + auto get_group_size = [](auto g) { return g.size(); }; + const auto sizes = group_union.groups() | std::views::transform(get_group_size); + EXPECT_EQ(group_union.max_group_size(), *std::ranges::max_element(sizes)); + + auto groups = group_union.groups_pro(); + for (uint32_t pattern_id = 0; pattern_id < group_union.pattern_num(); ++pattern_id) { + std::vector towards; + for (auto group : groups) { + if (group.pattern_id() == pattern_id) { + towards.emplace_back(group.mirror_toward()); + } + } + auto exp_towards = helper::pattern_toward_list(type_id, pattern_id); + EXPECT_EQ(towards.size(), exp_towards.size()); + for (uint32_t i = 0; i < towards.size(); ++i) { + EXPECT_EQ(towards[i], exp_towards[i]); + } + } + }); +} + TEST(GroupUnion, type_id) { ShortCode::speed_up(true); COMMON_CODE_PARALLEL({