Browse Source

test: add ffi all cases export test

legacy
Dnomd343 2 years ago
parent
commit
129516cd83
  1. 2
      test/CMakeLists.txt
  2. 44
      test/ffi/all_cases.cc

2
test/CMakeLists.txt

@ -40,7 +40,7 @@ add_test(NAME codec COMMAND test_codec)
include_directories(../src/klotski_core) include_directories(../src/klotski_core)
include_directories(../src/klotski_core/utils) include_directories(../src/klotski_core/utils)
set(TEST_FFI_SRC metadata.cc) set(TEST_FFI_SRC metadata.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})
target_link_libraries(test_ffi ${TEST_DEPS}) target_link_libraries(test_ffi ${TEST_DEPS})

44
test/ffi/all_cases.cc

@ -0,0 +1,44 @@
#include "klotski.h"
#include "all_cases.h"
#include "gtest/gtest.h"
using klotski::AllCases;
using klotski::BasicRanges;
TEST(FFI, all_cases_build) {
// basic ranges test
EXPECT_EQ(is_basic_ranges_available(), BasicRanges::status() == BasicRanges::AVAILABLE);
basic_ranges_build();
EXPECT_EQ(is_basic_ranges_available(), true);
EXPECT_EQ(is_basic_ranges_available(), BasicRanges::status() == BasicRanges::AVAILABLE);
// all cases test
EXPECT_EQ(is_all_cases_available(), AllCases::status() == AllCases::AVAILABLE);
all_cases_build();
EXPECT_EQ(is_all_cases_available(), true);
EXPECT_EQ(is_all_cases_available(), AllCases::status() == AllCases::AVAILABLE);
}
TEST(FFI, all_cases_size) {
EXPECT_EQ(ALL_CASES_SIZE, klotski::ALL_CASES_SIZE_SUM);
EXPECT_EQ(BASIC_RANGES_SIZE, klotski::BASIC_RANGES_SIZE);
}
TEST(FFI, all_cases_data) {
auto *basic_ranges_buf = new uint32_t[BASIC_RANGES_SIZE];
export_basic_ranges(basic_ranges_buf);
for (uint32_t i = 0; i < BASIC_RANGES_SIZE; ++i) { // basic ranges data verify
EXPECT_EQ(basic_ranges_buf[i], BasicRanges::fetch()[i]);
}
delete []basic_ranges_buf;
auto *all_cases_buf = new uint64_t[ALL_CASES_SIZE];
export_all_cases(all_cases_buf);
uint64_t index = 0;
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : AllCases::fetch()[head]) { // all cases data verify
EXPECT_EQ(all_cases_buf[index++], head << 32 | range);
}
}
delete []all_cases_buf;
}
Loading…
Cancel
Save