Browse Source

test: add test suite for `S2Mover`

master
Dnomd343 2 weeks ago
parent
commit
75f88df511
  1. 83
      src/core/main.cc
  2. 1
      src/core_test/CMakeLists.txt
  3. 6
      src/core_test/mover/mover.cc
  4. 51
      src/core_test/mover/s2_mover.cc

83
src/core/main.cc

@ -50,89 +50,6 @@ int main() {
const auto start = std::chrono::system_clock::now(); const auto start = std::chrono::system_clock::now();
// constexpr std::array s2_type_a_up = {"1a9bf0c", "1a99c3", "1abaf0c", "1aaef0c", "1aaac3", "9aaac3"};
// constexpr std::array s2_type_a_down = {"dc3be68", "dc399a", "dc3bae8", "dc3aee8", "dc3aaa", "5c3aaa"};
// constexpr std::array s2_type_a_left = {"1a9bfc", "1a9bd"};
// constexpr std::array s2_type_a_right = {"1a9bc3c", "1a9bc1"};
// const auto code = CommonCode::from_string(s2_type_a_up[5]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_a_down[5]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_a_left[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_a_right[1]).value().to_raw_code();
// constexpr std::array s2_type_b_up = {"5fef84d", "5fea134"};
// constexpr std::array s2_type_b_down = {"9346fbf", "9346afc"};
// constexpr std::array s2_type_b_left = {"6bfaf1c", "6bfae1", "6bfaf34", "6bfa47", "6bfa4d", "dbf993"};
// constexpr std::array s2_type_b_right = {"4fea3cd", "4fea2c4", "4fea3c7", "4fea134", "4fea11c", "dfe660c"};
// const auto code = CommonCode::from_string(s2_type_b_up[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_b_down[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_b_left[5]).value().to_raw_code();
// const auto code = CommonCode::from_string(s2_type_b_right[5]).value().to_raw_code();
// constexpr std::array s1_up = {"5f2f87d", "5f2a1f4"};
// constexpr std::array s1_down = {"9f46fbc", "9f46af"};
// constexpr std::array s1_left = {"1a9bcf", "1a9bc4"};
// constexpr std::array s1_right = {"1a9bcf", "1a9bc4"};
// const auto code = CommonCode::from_string(s1_up[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s1_down[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s1_left[1]).value().to_raw_code();
// const auto code = CommonCode::from_string(s1_right[1]).value().to_raw_code();
// auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code();
// S2Mover mover([](uint64_t code) {
// std::cout << RawCode::unsafe_create(code) << std::endl;
// if (!RawCode::check(code)) {
// std::cout << "error" << std::endl;
// std::abort();
// }
// });
// mover.next_cases(code.unwrap());
auto common_mover = [](RawCode src) {
std::vector<uint64_t> results {};
auto mover = MaskMover([&results](RawCode code, uint64_t) {
results.emplace_back(code.unwrap());
});
mover.next_cases(src, 0);
std::ranges::sort(results.begin(), results.end());
return results;
};
auto s2_mover = [](RawCode src) {
std::vector<uint64_t> results {};
auto mover = S2Mover([&results](uint64_t code) {
// std::cout << RawCode::unsafe_create(code) << std::endl;
if (!RawCode::check(code)) {
std::cout << "error" << std::endl;
std::abort();
}
results.emplace_back(code);
});
mover.next_cases(src.unwrap());
std::ranges::sort(results.begin(), results.end());
return results;
};
// auto code = CommonCode::unsafe_create(0x45C8B9000).to_raw_code();
// std::cout << std::format("{}\n", common_mover(code));
// std::cout << std::format("{}\n", s2_mover(code));
for (auto code : AllCases::instance().fetch().codes()) {
auto type_id = GroupUnion::from_common_code(code).unwrap();
auto [n, n_2x1, n_1x1] = BLOCK_NUM[type_id];
if (n * 2 + n_1x1 != 14) {
continue; // not s2 cases
}
auto raw_code = code.to_raw_code();
auto ret_1 = common_mover(raw_code);
auto ret_2 = s2_mover(raw_code);
if (ret_1 != ret_2) {
std::cout << "!!! get -> " << code << std::endl;
}
}
// TODO: maybe we can support `std::format` // TODO: maybe we can support `std::format`
// const auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code(); // const auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code();

1
src/core_test/CMakeLists.txt

@ -73,6 +73,7 @@ add_test(NAME klotski_codec COMMAND test_klotski_codec)
set(KLSK_TEST_MOVER_SRC set(KLSK_TEST_MOVER_SRC
mover/mover.cc mover/mover.cc
mover/s2_mover.cc
) )
add_executable(test_klotski_mover ${KLSK_TEST_MOVER_SRC}) add_executable(test_klotski_mover ${KLSK_TEST_MOVER_SRC})

6
src/core_test/mover/mover.cc

@ -27,7 +27,7 @@ using klotski::codec::RawCode;
// TODO: test input mask with samples // TODO: test input mask with samples
TEST(Core, core) { TEST(Mover, core) {
// TODO: test for each type_id // TODO: test for each type_id
@ -68,7 +68,7 @@ TEST(Core, core) {
// TODO: support multi-thread test // TODO: support multi-thread test
TEST(Core, mask) { TEST(Mover, mask) {
std::vector<uint64_t> raw_codes; std::vector<uint64_t> raw_codes;
raw_codes.reserve(klotski::cases::ALL_CASES_NUM_); raw_codes.reserve(klotski::cases::ALL_CASES_NUM_);
@ -168,7 +168,7 @@ TEST(Core, mask) {
} }
TEST(Core, next_cases) { TEST(Mover, next_cases) {
std::vector<RawCode> raw_codes; std::vector<RawCode> raw_codes;

51
src/core_test/mover/s2_mover.cc

@ -0,0 +1,51 @@
#include <gtest/gtest.h>
#include "group/group.h"
#include "mover/mover.h"
#include "raw_code/raw_code.h"
#include "all_cases/all_cases.h"
using klotski::codec::RawCode;
using klotski::cases::AllCases;
using klotski::mover::S2Mover;
using klotski::mover::MaskMover;
using klotski::group::BLOCK_NUM;
using klotski::group::GroupUnion;
TEST(S2Mover, demo) {
auto common_mover = [](RawCode src) {
std::vector<uint64_t> results {};
auto mover = MaskMover([&results](RawCode code, uint64_t) {
results.emplace_back(code.unwrap());
});
mover.next_cases(src, 0);
std::ranges::sort(results.begin(), results.end());
return results;
};
auto s2_mover = [](RawCode src) {
std::vector<uint64_t> results {};
auto mover = S2Mover([&results](uint64_t code) {
// std::cout << RawCode::unsafe_create(code) << std::endl;
EXPECT_TRUE(RawCode::check(code));
results.emplace_back(code);
});
mover.next_cases(src.unwrap());
std::ranges::sort(results.begin(), results.end());
return results;
};
for (auto code : AllCases::instance().fetch().codes()) {
// TODO: only check every type_id -> loop GroupUnion
auto type_id = GroupUnion::from_common_code(code).unwrap();
auto [n, n_2x1, n_1x1] = BLOCK_NUM[type_id];
if (n * 2 + n_1x1 != 14) {
continue; // not s2 cases
}
auto raw_code = code.to_raw_code();
EXPECT_EQ(common_mover(raw_code), s2_mover(raw_code));
}
}
Loading…
Cancel
Save