Browse Source

test: update core next cases test

master
Dnomd343 1 year ago
parent
commit
7675de8ff5
  1. 2
      test/CMakeLists.txt
  2. 49
      test/core/core.cc

2
test/CMakeLists.txt

@ -57,7 +57,7 @@ add_test(NAME codec COMMAND test_codec)
set(TEST_CORE_SRC core/core.cc)
add_executable(test_core ${TEST_CORE_SRC})
target_link_libraries(test_core ${TEST_DEPS})
target_link_libraries(test_core ${TEST_DEPS} absl::flat_hash_map)
add_test(NAME core COMMAND test_core)
################################################################################

49
test/core/core.cc

@ -1,40 +1,35 @@
#include <unordered_set>
#include "core.h"
#include "group.h"
#include "all_cases.h"
#include "gtest/gtest.h"
using klotski::Group;
using klotski::RawCode;
using klotski::AllCases;
TEST(Core, demo) {
auto raw_codes = std::unordered_set<uint64_t>();
// auto raw_codes_ = std::vector<uint64_t>();
using klotski::TYPE_ID_LIMIT;
raw_codes.reserve(klotski::ALL_CASES_SIZE_SUM);
// raw_codes_.reserve(klotski::ALL_CASES_SIZE_SUM);
for (auto &&common_code : AllCases::release()) { // load all raw codes
// EXPECT_NE(common_code.to_raw_code(), 0);
raw_codes.emplace(common_code.to_raw_code().unwrap());
// raw_codes_.emplace_back(common_code.to_raw_code().unwrap());
}
std::cout << "init ok" << std::endl;
auto core = klotski::Core(
[&raw_codes](auto &&code, auto &&mask) {
EXPECT_NE(raw_codes.find(code), raw_codes.end());
// new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask));
TEST(Core, next_cases) {
auto test = [](uint32_t type_id) {
auto raw_codes = std::unordered_set<uint64_t>();
raw_codes.reserve(klotski::ALL_CASES_SIZE_SUM);
for (auto &&common_code: Group::all_cases(type_id)) { // load all cases in a type
raw_codes.emplace(common_code.to_raw_code().unwrap());
}
);
for (auto &&raw_code : raw_codes) {
core.next_cases(raw_code, 0);
auto core = klotski::Core(
[&raw_codes](auto &&code, auto &&mask) {
EXPECT_NE(raw_codes.find(code), raw_codes.end()); // verify next case
EXPECT_EQ(mask >> __builtin_ctzll(mask), 0b111); // verify mask
}
);
for (auto &&raw_code: raw_codes) {
core.next_cases(raw_code, 0); // search next cases
}
};
// TODO: using multi-threads
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
test(type_id);
}
// EXPECT_EQ(raw_codes.size(), 29334498);
}

Loading…
Cancel
Save