Browse Source

test: add group info test

master
Dnomd343 2 years ago
parent
commit
ef30046b84
  1. 22
      src/klotski_core/ffi/tmain.cc
  2. 1
      test/CMakeLists.txt
  3. 2
      test/group/advance.cc
  4. 75
      test/group/group_info.cc

22
src/klotski_core/ffi/tmain.cc

@ -44,17 +44,17 @@ void tmain() {
// std::cout << "group id: " << ret.group_id << std::endl;
// std::cout << "group index: " << ret.group_index << std::endl;
std::cout << GroupCase::parse({
.type_id = 169,
.group_id = 1,
.group_index = 7472,
}) << std::endl;
std::cout << GroupCase::parse({
.type_id = 164,
.group_id = 0,
.group_index = 30833,
}) << std::endl;
// std::cout << GroupCase::parse({
// .type_id = 169,
// .group_id = 1,
// .group_index = 7472,
// }) << std::endl;
//
// std::cout << GroupCase::parse({
// .type_id = 164,
// .group_id = 0,
// .group_index = 30833,
// }) << std::endl;
// std::cerr << (clock() - start) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;

1
test/CMakeLists.txt

@ -63,6 +63,7 @@ add_test(NAME core COMMAND test_core)
set(TEST_GROUP_SRC
group/basic.cc
group/advance.cc
group/group_info.cc
)
add_executable(test_group ${TEST_GROUP_SRC})
target_link_libraries(test_group ${TEST_DEPS} md5 tiny_pool absl::flat_hash_map)

2
test/group/advance.cc

@ -175,5 +175,3 @@ TEST(Group, build_groups) {
auto group_info_md5 = md5(group_info_str.c_str(), group_info_str.size());
EXPECT_STREQ(group_info_md5.c_str(), GROUP_INFO_MD5); // verify all group info
}
// TODO: verify GROUP_SEEDS_INDEX_REV (group_info)

75
test/group/group_info.cc

@ -0,0 +1,75 @@
#include <algorithm>
#include "group.h"
#include "tiny_pool.h"
#include "gtest/gtest.h"
#define SHOULD_PANIC(FUNC) \
try { \
FUNC; EXPECT_STREQ("should panic", "but no panic"); \
} catch (...) {}
using klotski::Group;
using klotski::GroupCase;
using klotski::GroupType;
using klotski::CommonCode;
using klotski::TYPE_ID_LIMIT;
TEST(Group, group_info_invalid) {
SHOULD_PANIC(GroupCase::parse(GroupCase::info_t {
.type_id = TYPE_ID_LIMIT,
.group_id = 0,
.group_index = 0,
}))
SHOULD_PANIC(GroupCase::parse(GroupCase::info_t {
.type_id = 0,
.group_id = static_cast<uint16_t>(GroupType(0).group_num()),
.group_index = 0,
}))
SHOULD_PANIC(GroupCase::parse(GroupCase::info_t {
.type_id = 0,
.group_id = 0,
.group_index = Group(0, 0).size(),
}))
}
TEST(Group, group_info) {
auto test = [](GroupType group_type) {
for (uint32_t group_id = 0; group_id < group_type.group_num(); ++group_id) {
auto tmp = Group(group_type, group_id).cases();
std::vector<CommonCode> cases(tmp.begin(), tmp.end());
auto min = *std::min_element(cases.begin(), cases.end());
auto max = *std::max_element(cases.begin(), cases.end());
auto min_info = GroupCase::info_t{
.type_id = static_cast<uint16_t>(group_type.unwrap()),
.group_id = static_cast<uint16_t>(group_id),
.group_index = 0,
};
auto max_info = GroupCase::info_t{
.type_id = static_cast<uint16_t>(group_type.unwrap()),
.group_id = static_cast<uint16_t>(group_id),
.group_index = static_cast<uint32_t>(cases.size() - 1),
};
EXPECT_EQ(min, GroupCase::parse(min_info));
EXPECT_EQ(max, GroupCase::parse(max_info));
EXPECT_EQ(min_info, GroupCase::encode(min));
EXPECT_EQ(max_info, GroupCase::encode(max));
EXPECT_EQ(min_info, GroupCase::encode(min.to_raw_code()));
EXPECT_EQ(max_info, GroupCase::encode(max.to_raw_code()));
}
};
auto pool = TinyPool();
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
pool.submit(test, GroupType(type_id));
}
pool.boot();
pool.join();
}
// TODO: add group_info FAST mode
Loading…
Cancel
Save