From 601982dc88a09bf9a4bc94f854a6762efec90823 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 30 Apr 2023 01:30:46 +0800 Subject: [PATCH] remove: legacy global test --- test/CMakeLists.txt | 16 ++------ test/global/common_code.cc | 46 ----------------------- test/global/global_utils.h | 18 --------- test/global/raw_code.cc | 75 -------------------------------------- test/global/short_code.cc | 55 ---------------------------- 5 files changed, 3 insertions(+), 207 deletions(-) delete mode 100644 test/global/common_code.cc delete mode 100644 test/global/global_utils.h delete mode 100644 test/global/raw_code.cc delete mode 100644 test/global/short_code.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f7f541..ed4b970 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,9 @@ add_test(NAME codec COMMAND test_codec) ####################################################################################### -set(TEST_CORE_SRC core/core.cc) +set(TEST_CORE_SRC + core/core.cc +) add_executable(test_core ${TEST_CORE_SRC}) target_link_libraries(test_core ${TEST_DEPS}) add_test(NAME core COMMAND test_core) @@ -89,15 +91,3 @@ target_link_libraries(test_ffi ${TEST_DEPS}) add_test(NAME ffi COMMAND test_ffi) ####################################################################################### - -set(TEST_CODEC_GLOBAL_SRC - global/short_code.cc - global/common_code.cc - global/raw_code.cc -) - -add_executable(test_codec_global ${TEST_CODEC_GLOBAL_SRC}) -target_link_libraries(test_codec_global ${TEST_DEPS} tiny_pool) -add_test(NAME codec_global COMMAND test_codec_global) - -####################################################################################### diff --git a/test/global/common_code.cc b/test/global/common_code.cc deleted file mode 100644 index 78d09ec..0000000 --- a/test/global/common_code.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "all_cases.h" -#include "common_code.h" -#include "gtest/gtest.h" -#include "global_utils.h" - -using klotski::AllCases; -using klotski::CommonCode; - -std::vector common_code_search(uint64_t start, uint64_t end) { - std::vector ret; - for (uint64_t common_code = start; common_code < end; ++common_code) { - if (CommonCode::check(common_code)) { - ret.emplace_back(common_code); // valid common code - } - } - return ret; -} - -TEST(GLOBAL, common_code) { - /// create common code check tasks - auto pool = TinyPool(); - std::vector>> futures; - for (const auto &range : range_split(0, 0x10'0000'0000, 0x10'0000)) { - futures.emplace_back( - pool.submit(common_code_search, range.first, range.second) - ); - } - - /// run common code search - pool.boot(); - std::vector result; - for (auto &f : futures) { - auto ret = f.get(); - result.insert(result.end(), ret.begin(), ret.end()); - } - pool.join(); - - /// verify check result - std::vector all_cases; - for (uint64_t head = 0; head < 16; ++head) { - for (const auto &range : AllCases::fetch()[head]) { - all_cases.emplace_back(head << 32 | range); - } - } - EXPECT_EQ(result, all_cases); -} diff --git a/test/global/global_utils.h b/test/global/global_utils.h deleted file mode 100644 index e549fd8..0000000 --- a/test/global/global_utils.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include "tiny_pool.h" - -typedef std::vector> range_split_t; - -inline range_split_t range_split(uint64_t start, uint64_t end, uint64_t size) { - uint64_t rear = end - (end - start) % size; // (rear - start) % size == 0 - range_split_t ranges; - for (uint64_t i = start; i < rear; i += size) { - ranges.emplace_back(i, i + size); - } - if (rear != end) { - ranges.emplace_back(rear, end); - } - return ranges; -} diff --git a/test/global/raw_code.cc b/test/global/raw_code.cc deleted file mode 100644 index bf23aa1..0000000 --- a/test/global/raw_code.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include "common.h" -#include "raw_code.h" -#include "gtest/gtest.h" -#include "global_utils.h" - -using klotski::RawCode; -using klotski::AllCases; -using klotski::CommonCode; -using klotski::Common::range_reverse; - -uint64_t convert(uint64_t common_code) { // try to convert as raw code - auto code = C_2x2 << (common_code >> 32) * 3; - auto range = range_reverse((uint32_t)common_code); - for (int addr = 0; range; range >>= 2) { - while ((code >> addr) & 0b111 && addr < 60) { - addr += 3; - } - if (addr >= 60) { - return 0; - } - switch (range & 0b11) { // match low 2-bits - case 0b01: // 1x2 block - code |= C_1x2 << addr; - break; - case 0b10: // 2x1 block - code |= C_2x1 << addr; - break; - case 0b11: // 1x1 block - code |= C_1x1 << addr; - break; - case 0b00: // space - addr += 3; - } - } - return code; -} - -std::vector raw_code_search(uint64_t start, uint64_t end) { - std::vector ret; - for (uint64_t common_code = start; common_code < end; ++common_code) { - if (RawCode::check(convert(common_code))) { - ret.emplace_back(common_code); // valid layout - } - } - return ret; -} - -TEST(GLOBAL, raw_code) { - /// create raw code check tasks - auto pool = TinyPool(); - std::vector>> futures; - for (const auto &range : range_split(0, 0x10'0000'0000, 0x10'0000)) { - futures.emplace_back( - pool.submit(raw_code_search, range.first, range.second) - ); - } - - /// run raw code search - pool.boot(); - std::vector result; - for (auto &f : futures) { - auto ret = f.get(); - result.insert(result.end(), ret.begin(), ret.end()); - } - pool.join(); - - /// verify check result - std::vector all_cases; - for (uint64_t head = 0; head < 16; ++head) { - for (const auto &range : AllCases::fetch()[head]) { - all_cases.emplace_back(head << 32 | range); - } - } - EXPECT_EQ(result, all_cases); -} diff --git a/test/global/short_code.cc b/test/global/short_code.cc deleted file mode 100644 index 127ebef..0000000 --- a/test/global/short_code.cc +++ /dev/null @@ -1,55 +0,0 @@ -#include "all_cases.h" -#include "short_code.h" -#include "gtest/gtest.h" -#include "global_utils.h" - -using klotski::AllCases; -using klotski::ShortCode; -using klotski::CommonCode; - -std::vector short_code_check(uint32_t start, uint32_t end) { - std::vector archive; - for (uint32_t short_code = start; short_code < end; ++short_code) { - auto common_code = ShortCode::unsafe_create(short_code).to_common_code(); - archive.emplace_back(common_code.unwrap()); - EXPECT_EQ(common_code.to_short_code().unwrap(), short_code); - } - return archive; -} - -void short_code_verify() { - /// create short code check tasks - auto pool = TinyPool(); - std::vector>> futures; - for (const auto &range : range_split(0, klotski::ALL_CASES_SIZE_SUM, 10000)) { - futures.emplace_back( - pool.submit(short_code_check, range.first, range.second) - ); - } - - /// run short code search - pool.boot(); - std::vector result; - for (auto &f : futures) { - auto ret = f.get(); - result.insert(result.end(), ret.begin(), ret.end()); - } - pool.join(); - - /// verify check result - std::vector all_cases; - for (uint64_t head = 0; head < 16; ++head) { - for (const auto &range : AllCases::fetch()[head]) { - all_cases.emplace_back(head << 32 | range); - } - } - EXPECT_EQ(result, all_cases); -} - -TEST(GLOBAL, short_code) { - ShortCode::speed_up(ShortCode::NORMAL); // normal mode - short_code_verify(); - - ShortCode::speed_up(ShortCode::FAST); // fast mode - short_code_verify(); -}