From 7842b701672a193c032359b50ff38bbf412c3543 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 27 Jan 2023 08:47:52 +0800 Subject: [PATCH] test: common functions in utils --- test/CMakeLists.txt | 8 ++++++++ test/all_cases.cc | 7 ------- test/utils.cc | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 test/utils.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7891023..a73f3a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,6 +11,14 @@ add_library(md5 STATIC ../third_party/md5/md5.cpp) ################################################################ +include_directories(../src/klotski/utils) +add_executable(test_utils utils.cc) +target_link_libraries(test_utils PUBLIC gtest gtest_main) +target_link_libraries(test_utils PUBLIC utils) +add_test(NAME utils COMMAND test_utils) + +################################################################ + include_directories(../src/klotski/all_cases) add_executable(test_all_cases all_cases.cc) target_link_libraries(test_all_cases PUBLIC gtest gtest_main) diff --git a/test/all_cases.cc b/test/all_cases.cc index 980822f..6802901 100644 --- a/test/all_cases.cc +++ b/test/all_cases.cc @@ -6,16 +6,9 @@ using namespace klotski; /// basic ranges constants -//const uint32_t BASIC_RANGES_SIZE = 7311921; const char BASIC_RANGES_MD5[] = "6f385dc171e201089ff96bb010b47212"; /// all cases constants -//const uint32_t ALL_CASES_SIZE[16] = { -// 2942906, 2260392, 2942906, 0, -// 2322050, 1876945, 2322050, 0, -// 2322050, 1876945, 2322050, 0, -// 2942906, 2260392, 2942906, 0, -//}; const uint32_t ALL_CASES_SIZE_SUM = 29334498; const char ALL_CASES_MD5[] = "3888e9fab8d3cbb50908b12b147cfb23"; diff --git a/test/utils.cc b/test/utils.cc new file mode 100644 index 0000000..c3edf57 --- /dev/null +++ b/test/utils.cc @@ -0,0 +1,36 @@ +#include +#include "common.h" +#include "gtest/gtest.h" + +using namespace klotski; + +TEST(Utils, range_reverse) { + EXPECT_EQ(Common::range_reverse((uint32_t)0x00000003), (uint32_t)0xC0000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x0000000C), (uint32_t)0x30000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x00000030), (uint32_t)0x0C000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x000000C0), (uint32_t)0x03000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x00000300), (uint32_t)0x00C00000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x00000C00), (uint32_t)0x00300000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x00003000), (uint32_t)0x000C0000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x0000C000), (uint32_t)0x00030000); + + EXPECT_EQ(Common::range_reverse((uint32_t)0x0000000F), (uint32_t)0xF0000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x000000FF), (uint32_t)0xFF000000); + EXPECT_EQ(Common::range_reverse((uint32_t)0x0000FFFF), (uint32_t)0xFFFF0000); + + EXPECT_EQ(Common::range_reverse((uint32_t)0x55555555), (uint32_t)0x55555555); + EXPECT_EQ(Common::range_reverse((uint32_t)0xAAAAAAAA), (uint32_t)0xAAAAAAAA); +} + +TEST(Utils, check_range) { + EXPECT_NE(Common::check_range(1, 0xA9BF0C00), 0); + EXPECT_EQ(Common::check_range(1, 0x0030FE6A), 0); + + EXPECT_NE(Common::check_range(4, 0xFEA13400), 0); + EXPECT_EQ(Common::check_range(4, 0x001C4ABF), 0); + + EXPECT_EQ(Common::check_range(5, 0x004845D3), 5); + EXPECT_EQ(Common::check_range(10, 0x003B7521), 8); + EXPECT_EQ(Common::check_range(13, 0x000EC9D3), 9); + EXPECT_EQ(Common::check_range(15, 0x00A3B724), 6); +}