Browse Source

perf: debug output of RawCode

legacy
Dnomd343 3 months ago
parent
commit
6ae4422fac
  1. 23
      src/core/raw_code/internal/raw_code.cc
  2. 2
      src/core_test/codec/raw_code.cc

23
src/core/raw_code/internal/raw_code.cc

@ -1,3 +1,5 @@
#include <format>
#include "utils/common.h" #include "utils/common.h"
#include "raw_code/raw_code.h" #include "raw_code/raw_code.h"
@ -5,18 +7,17 @@ using klotski::codec::RawCode;
#ifndef KLSK_NDEBUG #ifndef KLSK_NDEBUG
std::ostream& klotski::codec::operator<<(std::ostream &out, const RawCode self) { std::ostream& klotski::codec::operator<<(std::ostream &out, const RawCode self) {
char *code; constexpr auto char_map = std::to_array({
asprintf(&code, "%015llX\n", self.code_); // code length -> 15 '.', // space
out << code; '~', '|', // 1x2 | 2x1
free(code); '*', '@', // 1x1 | 2x2
'?', '?', // unknown
constexpr char map[] = { '+', // fill
// 0x0 1x2 2x1 1x1 2x2 b101 b110 fill });
'.', '~', '|', '*', '@', '?', '?', '+' out << std::format("{:015X}\n", self.code_);
};
for (int addr = 0; addr < 60; addr += 3) { for (int addr = 0; addr < 60; addr += 3) {
out << map[(self.code_ >> addr) & 0b111]; out << char_map[(self.code_ >> addr) & 0b111];
out << " " << &"\n"[(addr & 0b11) != 0b01]; out << &" "[(addr & 0b11) == 0b01] << &"\n"[(addr & 0b11) != 0b01];
} }
return out; return out;
} }

2
src/core_test/codec/raw_code.cc

@ -33,7 +33,7 @@ TEST(RawCode, basic) {
#ifndef KLSK_NDEBUG #ifndef KLSK_NDEBUG
std::ostringstream out; std::ostringstream out;
out << RawCode::unsafe_create(TEST_R_CODE); // ostream capture out << RawCode::unsafe_create(TEST_R_CODE); // ostream capture
EXPECT_EQ(out.str(), "603EDF5CAFFF5E2\n| @ + | \n+ + + + \n| ~ + | \n+ * * + \n* . . * \n"); EXPECT_EQ(out.str(), "603EDF5CAFFF5E2\n| @ + |\n+ + + +\n| ~ + |\n+ * * +\n* . . *\n");
#endif #endif
} }

Loading…
Cancel
Save