Browse Source

test: common code string verify

legacy
Dnomd343 2 years ago
parent
commit
1029bdee83
  1. 2
      klotski/all_cases.h
  2. 1
      klotski/common_code.cc
  3. 32
      klotski/main.cc

2
klotski/all_cases.h

@ -13,6 +13,8 @@ public:
const std::vector<uint32_t>* get_basic_ranges(); const std::vector<uint32_t>* get_basic_ranges();
const std::vector<uint32_t> (*get_all_cases())[16]; const std::vector<uint32_t> (*get_all_cases())[16];
// TODO: add all_cases_list export
private: private:
std::vector<uint32_t> basic_ranges; std::vector<uint32_t> basic_ranges;
std::vector<uint32_t> all_cases[16]; std::vector<uint32_t> all_cases[16];

1
klotski/common_code.cc

@ -2,6 +2,7 @@
#include "common.h" #include "common.h"
#include "common_code.h" #include "common_code.h"
/// WARN: bin should not be zero
inline uint8_t last_zero_num(uint32_t bin) { // get last zero number inline uint8_t last_zero_num(uint32_t bin) { // get last zero number
bin ^= (bin - 1); bin ^= (bin - 1);
return __builtin_popcount(bin >> 1); return __builtin_popcount(bin >> 1);

32
klotski/main.cc

@ -35,8 +35,36 @@ int main() {
// std::cout << CommonCode::code_to_string(0x4FEA13400, true) << std::endl; // std::cout << CommonCode::code_to_string(0x4FEA13400, true) << std::endl;
// std::cout << CommonCode::code_to_string(0x4FEA13400) << std::endl; // std::cout << CommonCode::code_to_string(0x4FEA13400) << std::endl;
printf("%09lX\n", CommonCode::code_from_string("4FEa134")); // printf("%09lX\n", CommonCode::code_from_string("4FEa134"));
printf("%09lX\n", CommonCode::code_from_string("1A9bf0C0")); // printf("%09lX\n", CommonCode::code_from_string("1A9bf0C0"));
// std::cout << (int)last_zero_num(0b1) << std::endl;
// std::cout << (int)last_zero_num(0b1000) << std::endl;
// std::cout << (int)last_zero_num(0) << std::endl;
// std::cout << CommonCode::code_to_string(0, true) << std::endl;
auto a = AllCases();
std::vector<uint64_t> all_cases;
for (int head = 0; head < 16; ++head) {
auto prefix = (uint64_t)head << 32;
for (auto const &range : (*a.get_all_cases())[head]) {
all_cases.emplace_back(prefix | range);
}
}
// std::cout << all_cases.size() << std::endl;
for (auto const &code : all_cases) {
// printf("%s\n", CommonCode::code_to_string(code).c_str());
std::string code_str = CommonCode::code_to_string(code);
if (CommonCode::code_from_string(code_str) != code) {
std::cout << "ERROR: " << code_str << std::endl;
}
code_str = CommonCode::code_to_string(code, true);
if (CommonCode::code_from_string(code_str) != code) {
std::cout << "ERROR: " << code_str << std::endl;
}
}
return 0; return 0;
} }

Loading…
Cancel
Save