Browse Source

test: common functions in utils

master
Dnomd343 2 years ago
parent
commit
7842b70167
  1. 8
      test/CMakeLists.txt
  2. 7
      test/all_cases.cc
  3. 36
      test/utils.cc

8
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)

7
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";

36
test/utils.cc

@ -0,0 +1,36 @@
#include <cstdint>
#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);
}
Loading…
Cancel
Save