Browse Source

test: next group theory test suites

legacy
Dnomd343 2 months ago
parent
commit
b0f3322fe9
  1. 8
      src/core/group/internal/group_pro.inl
  2. 106
      src/core_test/cases/group_pro.cc
  3. 34
      src/core_test/cases/group_union.cc

8
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); return GroupPro::unsafe_create(type_id_, pattern_id_, 0);
case MirrorType::NonMirror: case MirrorType::NonMirror:
if (mirror_toward_ == 0) { 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) { } 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); 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);
} }
} }

106
src/core_test/cases/group_pro.cc

@ -1,8 +1,12 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <unordered_set>
#include "helper/group.h" #include "helper/group.h"
#include "group/group.h" #include "group/group.h"
#include "helper/parallel.h"
using klotski::cases::GroupPro; using klotski::cases::GroupPro;
using klotski::cases::GroupUnion; 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())); 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<uint64_t> 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<uint64_t> cases_1;
std::unordered_set<uint64_t> 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<uint64_t> 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<uint64_t> cases_1;
std::unordered_set<uint64_t> 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()));
}
}
}
});
}

34
src/core_test/cases/group_union.cc

@ -8,12 +8,15 @@
#include "helper/parallel.h" #include "helper/parallel.h"
#include "helper/block_num.h" #include "helper/block_num.h"
#include "helper/group.h"
#include "group/group.h" #include "group/group.h"
#include "common_code/common_code.h" #include "common_code/common_code.h"
using klotski::codec::ShortCode; using klotski::codec::ShortCode;
using klotski::cases::Group; using klotski::cases::Group;
using klotski::cases::GroupPro;
using klotski::cases::GroupUnion; using klotski::cases::GroupUnion;
using klotski::cases::TYPE_ID_LIMIT; 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<uint32_t> 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) { TEST(GroupUnion, type_id) {
ShortCode::speed_up(true); ShortCode::speed_up(true);
COMMON_CODE_PARALLEL({ COMMON_CODE_PARALLEL({

Loading…
Cancel
Save