Browse Source

update: group_seeds header file

legacy
Dnomd343 2 years ago
parent
commit
e0ec75f22a
  1. 4
      src/klotski_core/group/group.cc
  2. 3186
      src/klotski_core/group/group_seeds.h
  3. 3191
      src/klotski_core/group/index.h
  4. 48
      test/CMakeLists.txt
  5. 61
      test/group/block_num.cc
  6. 52
      test/group/group.cc

4
src/klotski_core/group/group.cc

@ -7,9 +7,7 @@
#include "size.h" #include "size.h"
#include "seeds.h" #include "group_seeds.h"
#include "index.h"
namespace klotski { namespace klotski {

3186
src/klotski_core/group/seeds.h → src/klotski_core/group/group_seeds.h

File diff suppressed because it is too large

3191
src/klotski_core/group/index.h

File diff suppressed because it is too large

48
test/CMakeLists.txt

@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.0)
################################################################################ ################################################################################
enable_testing() enable_testing()
set(TEST_DEPS gtest gtest_main klotski) set(TEST_DEPS gtest gtest_main klotski)
################################################################################ ################################################################################
@ -18,11 +17,23 @@ unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
include_directories(../third_party/tiny_thread_pool) include_directories(../third_party/tiny_thread_pool)
add_library(tiny_pool STATIC ../third_party/tiny_thread_pool/tiny_pool.c) add_library(tiny_pool STATIC ../third_party/tiny_thread_pool/tiny_pool.c)
# TODO: tiny_pool as cpp module
################################################################################ ################################################################################
include_directories(../src/klotski_core)
include_directories(../src/klotski_core/utils) include_directories(../src/klotski_core/utils)
include_directories(../src/klotski_core/all_cases) include_directories(../src/klotski_core/all_cases)
include_directories(../src/klotski_core/raw_code)
include_directories(../src/klotski_core/short_code)
include_directories(../src/klotski_core/common_code)
include_directories(../src/klotski_core/core)
include_directories(../src/klotski_core/group)
################################################################################
set(TEST_BASIC_SRC utils.cc all_cases.cc) set(TEST_BASIC_SRC utils.cc all_cases.cc)
list(TRANSFORM TEST_BASIC_SRC PREPEND "basic/") list(TRANSFORM TEST_BASIC_SRC PREPEND "basic/")
add_executable(test_basic ${TEST_BASIC_SRC}) add_executable(test_basic ${TEST_BASIC_SRC})
@ -31,23 +42,17 @@ add_test(NAME basic COMMAND test_basic)
################################################################################ ################################################################################
include_directories(../src/klotski_core/raw_code) set(TEST_CODEC_SRC
include_directories(../src/klotski_core/short_code) codec/short_code.cc
include_directories(../src/klotski_core/common_code) codec/raw_code.cc
codec/common_code.cc
set(TEST_CODEC_SRC short_code.cc raw_code.cc common_code.cc) )
list(TRANSFORM TEST_CODEC_SRC PREPEND "codec/")
add_executable(test_codec ${TEST_CODEC_SRC}) add_executable(test_codec ${TEST_CODEC_SRC})
target_link_libraries(test_codec ${TEST_DEPS}) target_link_libraries(test_codec ${TEST_DEPS})
add_test(NAME codec COMMAND test_codec) add_test(NAME codec COMMAND test_codec)
################################################################################ ################################################################################
include_directories(../src/klotski_core/core)
include_directories(../src/klotski_core/raw_code)
include_directories(../src/klotski_core/all_cases)
include_directories(../src/klotski_core/common_code)
set(TEST_CORE_SRC core.cc) set(TEST_CORE_SRC core.cc)
list(TRANSFORM TEST_CORE_SRC PREPEND "core/") list(TRANSFORM TEST_CORE_SRC PREPEND "core/")
add_executable(test_core ${TEST_CORE_SRC}) add_executable(test_core ${TEST_CORE_SRC})
@ -56,23 +61,16 @@ add_test(NAME core COMMAND test_core)
################################################################################ ################################################################################
#include_directories(../src/klotski_core/core) set(TEST_GROUP_SRC
#include_directories(../src/klotski_core/raw_code) group/block_num.cc
#include_directories(../src/klotski_core/all_cases) group/group.cc
#include_directories(../src/klotski_core/common_code) )
include_directories(../src/klotski_core/group)
set(TEST_GROUP_SRC group.cc)
list(TRANSFORM TEST_GROUP_SRC PREPEND "group/")
add_executable(test_group ${TEST_GROUP_SRC}) add_executable(test_group ${TEST_GROUP_SRC})
target_link_libraries(test_group ${TEST_DEPS} md5 absl::flat_hash_map) target_link_libraries(test_group ${TEST_DEPS} md5 absl::flat_hash_map)
add_test(NAME group COMMAND test_group) add_test(NAME group COMMAND test_group)
################################################################################ ################################################################################
include_directories(../src/klotski_core)
include_directories(../src/klotski_core/utils)
set(TEST_FFI_SRC metadata.cc codec.cc all_cases.cc) set(TEST_FFI_SRC metadata.cc codec.cc all_cases.cc)
list(TRANSFORM TEST_FFI_SRC PREPEND "ffi/") list(TRANSFORM TEST_FFI_SRC PREPEND "ffi/")
add_executable(test_ffi ${TEST_FFI_SRC}) add_executable(test_ffi ${TEST_FFI_SRC})
@ -85,10 +83,6 @@ include_directories(../src/klotski_core)
add_library(test_global_utils STATIC global/global_utils.cc) add_library(test_global_utils STATIC global/global_utils.cc)
set(TEST_GLOBAL_DEPS ${TEST_DEPS} test_global_utils tiny_pool) set(TEST_GLOBAL_DEPS ${TEST_DEPS} test_global_utils tiny_pool)
include_directories(../src/klotski_core/raw_code)
include_directories(../src/klotski_core/short_code)
include_directories(../src/klotski_core/common_code)
add_executable(test_codec_global global/short_code.cc global/common_code.cc global/raw_code.cc) add_executable(test_codec_global global/short_code.cc global/common_code.cc global/raw_code.cc)
target_link_libraries(test_codec_global ${TEST_GLOBAL_DEPS}) target_link_libraries(test_codec_global ${TEST_GLOBAL_DEPS})
add_test(NAME codec_global COMMAND test_codec_global) add_test(NAME codec_global COMMAND test_codec_global)

61
test/group/block_num.cc

@ -0,0 +1,61 @@
#include <thread>
#include "md5.h"
#include "group.h"
#include "all_cases.h"
#include "gtest/gtest.h"
using klotski::Group;
using klotski::AllCases;
using klotski::CommonCode;
using klotski::TYPE_ID_LIMIT;
const char BLOCK_NUM_MD5[] = "46a7b3af6d039cbe2f7eaebdd196c6a2";
TEST(Group, type_id) {
std::thread threads[16];
auto test = [](uint64_t head) {
for (const auto &range : AllCases::fetch()[head]) {
auto common_code = CommonCode::unsafe_create(head << 32 | range);
auto type_id = Group::type_id(common_code); // found type id
EXPECT_LT(type_id, TYPE_ID_LIMIT);
EXPECT_EQ(type_id, Group::type_id(common_code.to_raw_code()));
EXPECT_EQ(type_id, Group::type_id(Group::block_num(common_code)));
EXPECT_EQ(Group::block_num(type_id), Group::block_num(common_code));
}
};
for (uint64_t head = 0; head < 16; ++head) { // split into 16 threads
threads[head] = std::thread(test, head);
}
for (auto &t : threads) {
t.join();
}
}
TEST(Group, block_num) {
std::thread threads[16];
std::string block_num_data;
std::string block_num_str[16];
auto test = [&block_num_str](uint64_t head) {
char buffer[13];
for (auto &&range: AllCases::fetch()[head]) {
auto common_code = CommonCode::unsafe_create(head << 32 | range);
auto tmp = Group::block_num(common_code);
EXPECT_EQ(tmp, Group::block_num(common_code.to_raw_code()));
sprintf(buffer, "%d,%d,%d\n", tmp.n_1x2 + tmp.n_2x1, tmp.n_1x1, tmp.n_2x1);
block_num_str[head] += buffer;
}
};
for (uint64_t head = 0; head < 16; ++head) { // split into 16 threads
threads[head] = std::thread(test, head);
}
for (auto &t : threads) {
t.join();
}
for (auto &&tmp : block_num_str) { // combine string
block_num_data += tmp;
}
auto block_num_md5 = md5(block_num_data.c_str(), block_num_data.size());
EXPECT_STREQ(block_num_md5.c_str(), BLOCK_NUM_MD5);
}

52
test/group/group.cc

@ -6,7 +6,7 @@
#include "group/size.h" #include "group/size.h"
#include "group/seeds.h" #include "group_seeds.h"
using klotski::Group; using klotski::Group;
using klotski::AllCases; using klotski::AllCases;
@ -25,58 +25,8 @@ using klotski::SHORT_CODE_LIMIT;
using klotski::GROUP_SEEDS; using klotski::GROUP_SEEDS;
const char BLOCK_NUM_MD5[] = "46a7b3af6d039cbe2f7eaebdd196c6a2";
const char GROUP_INFO_MD5[] = "976bf22530085210e68a6a4e67053506"; const char GROUP_INFO_MD5[] = "976bf22530085210e68a6a4e67053506";
TEST(Group, type_id) {
std::thread threads[16];
auto test = [](uint64_t head) {
for (const auto &range : AllCases::fetch()[head]) {
auto common_code = CommonCode::unsafe_create(head << 32 | range);
auto type_id = Group::type_id(common_code); // found type id
EXPECT_LT(type_id, TYPE_ID_LIMIT);
EXPECT_EQ(type_id, Group::type_id(common_code.to_raw_code()));
EXPECT_EQ(type_id, Group::type_id(Group::block_num(common_code)));
EXPECT_EQ(Group::block_num(type_id), Group::block_num(common_code));
}
};
for (uint64_t head = 0; head < 16; ++head) { // split into 16 threads
threads[head] = std::thread(test, head);
}
for (auto &t : threads) {
t.join();
}
}
TEST(Group, block_num) {
std::thread threads[16];
std::string block_num_data;
std::string block_num_str[16];
auto test = [&block_num_str](uint64_t head) {
char buffer[13];
for (auto &&range: AllCases::fetch()[head]) {
auto common_code = CommonCode::unsafe_create(head << 32 | range);
auto tmp = Group::block_num(common_code);
EXPECT_EQ(tmp, Group::block_num(common_code.to_raw_code()));
sprintf(buffer, "%d,%d,%d\n", tmp.n_1x2 + tmp.n_2x1, tmp.n_1x1, tmp.n_2x1);
block_num_str[head] += buffer;
}
};
for (uint64_t head = 0; head < 16; ++head) { // split into 16 threads
threads[head] = std::thread(test, head);
}
for (auto &t : threads) {
t.join();
}
for (auto &&tmp : block_num_str) { // combine string
block_num_data += tmp;
}
auto block_num_md5 = md5(block_num_data.c_str(), block_num_data.size());
EXPECT_STREQ(block_num_md5.c_str(), BLOCK_NUM_MD5);
}
TEST(Group, all_cases) { TEST(Group, all_cases) {
std::vector<std::vector<CommonCode>> all_cases; std::vector<std::vector<CommonCode>> all_cases;

Loading…
Cancel
Save