Browse Source

test: verify group all cases

legacy
Dnomd343 2 years ago
parent
commit
a9bd6c960e
  1. 3
      src/klotski_core/common_code/common_code.h
  2. 3
      test/codec/common_code.cc
  3. 30
      test/group/group.cc

3
src/klotski_core/common_code/common_code.h

@ -123,6 +123,9 @@ inline bool operator==(uint64_t c1, const CommonCode &c2) noexcept { return c1 =
inline bool operator!=(uint64_t c1, const CommonCode &c2) noexcept { return c1 != c2.unwrap(); }
inline bool operator==(const CommonCode &c1, uint64_t c2) noexcept { return c1.unwrap() == c2; }
inline bool operator!=(const CommonCode &c1, uint64_t c2) noexcept { return c1.unwrap() != c2; }
inline bool operator<(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() < c2.unwrap(); }
inline bool operator>(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() > c2.unwrap(); }
inline bool operator==(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() == c2.unwrap(); }
inline bool operator!=(const CommonCode &c1, const CommonCode &c2) noexcept { return c1.unwrap() != c2.unwrap(); }

3
test/codec/common_code.cc

@ -103,6 +103,9 @@ TEST(CommonCode, operators) {
EXPECT_NE(TEST_CODE + 1, CommonCode(TEST_CODE)); // uint64_t != CommonCode
EXPECT_NE(CommonCode(TEST_CODE), TEST_CODE + 1); // CommonCode != uint64_t
EXPECT_NE(CommonCode(TEST_CODE), CommonCode::unsafe_create(TEST_CODE + 1)); // CommonCode != CommonCode
EXPECT_LT(CommonCode(TEST_CODE), CommonCode::unsafe_create(TEST_CODE + 1)); // CommonCode < CommonCode
EXPECT_GT(CommonCode::unsafe_create(TEST_CODE + 1), CommonCode(TEST_CODE)); // CommonCode > CommonCode
}
TEST(CommonCode, code_convert) {

30
test/group/group.cc

@ -1,14 +1,20 @@
#include <thread>
#include <algorithm>
#include "md5.h"
#include "group.h"
#include "gtest/gtest.h"
#include "group/size.h"
using klotski::Group;
using klotski::AllCases;
using klotski::CommonCode;
using klotski::TYPE_ID_LIMIT;
using klotski::ALL_CASES_SIZE_SUM;
using klotski::GROUP_ALL_CASES_SIZE;
using klotski::TYPE_ID_LIMIT;
const char BLOCK_NUM_MD5[] = "46a7b3af6d039cbe2f7eaebdd196c6a2";
@ -62,10 +68,26 @@ TEST(Group, block_num) {
}
TEST(Group, all_cases) {
std::vector<std::vector<CommonCode>> all_cases;
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
all_cases.emplace_back(Group::all_cases(type_id)); // build test data
}
// TODO: all_cases number
// TODO: combine test
// TODO: data order
// TODO: test every cases (type_id)
std::vector<uint64_t> combine_cases;
combine_cases.reserve(ALL_CASES_SIZE_SUM);
for (uint32_t id = 0; id < TYPE_ID_LIMIT; ++id) {
EXPECT_EQ(all_cases[id].size(), GROUP_ALL_CASES_SIZE[id]); // verify cases number
for (auto &&common_code : all_cases[id]) {
EXPECT_EQ(Group::type_id(common_code), id); // verify type id
combine_cases.emplace_back(common_code.unwrap());
}
std::is_sorted(all_cases[id].begin(), all_cases[id].end()); // verify data order
}
EXPECT_EQ(combine_cases.size(), ALL_CASES_SIZE_SUM); // verify sum
auto all_cases_release = AllCases::release();
std::stable_sort(combine_cases.begin(), combine_cases.end());
for (uint32_t i = 0; i < combine_cases.size(); ++i) {
EXPECT_EQ(combine_cases[i], all_cases_release[i]); // verify after combined
}
}

Loading…
Cancel
Save