Browse Source

test: perf ostream capture assert

legacy
Dnomd343 3 months ago
parent
commit
e5bbda6a22
  1. 5
      src/core_test/codec/common_code.cc
  2. 12
      src/core_test/codec/helper/codec.h
  3. 7
      src/core_test/codec/raw_code.cc
  4. 5
      src/core_test/codec/short_code.cc

5
src/core_test/codec/common_code.cc

@ -36,9 +36,8 @@ TEST(CommonCode, basic) {
EXPECT_EQ(CommonCode::unsafe_create(TEST_MIRROR_C2).to_horizontal_mirror(), TEST_MIRROR_C2_HM);
#ifndef KLSK_NDEBUG
std::ostringstream out;
out << CommonCode::unsafe_create(TEST_C_CODE); // ostream capture
EXPECT_EQ(out.str(), TEST_C_CODE_STR);
EXPECT_OSTREAM(CommonCode::unsafe_create(0), "000000000");
EXPECT_OSTREAM(CommonCode::unsafe_create(TEST_C_CODE), TEST_C_CODE_STR);
#endif
}

12
src/core_test/codec/helper/codec.h

@ -17,6 +17,18 @@ std::vector<uint64_t> all_common_codes();
// ----------------------------------------------------------------------------------------- //
/// Capture ostream output as string.
template <typename T>
std::string ostream_capture(T obj) {
std::ostringstream out;
out << obj; // ostream capture
return out.str();
}
#define EXPECT_OSTREAM(obj, expect) EXPECT_EQ(ostream_capture(obj), expect)
// ----------------------------------------------------------------------------------------- //
/// Spawn all valid RawCodes in parallel.
void raw_code_parallel(std::function<void(std::span<RawCode>)> &&func);

7
src/core_test/codec/raw_code.cc

@ -31,9 +31,10 @@ TEST(RawCode, basic) {
EXPECT_EQ(RawCode::unsafe_create(TEST_MIRROR_R2).to_horizontal_mirror(), TEST_MIRROR_R2_HM);
#ifndef KLSK_NDEBUG
std::ostringstream out;
out << RawCode::unsafe_create(TEST_R_CODE); // ostream capture
EXPECT_EQ(out.str(), "603EDF5CAFFF5E2\n| @ + |\n+ + + +\n| ~ + |\n+ * * +\n* . . *\n");
EXPECT_OSTREAM(RawCode::unsafe_create(0x3F03C),
"00000000003F03C\n@ + . .\n+ + . .\n. . . .\n. . . .\n. . . .\n");
EXPECT_OSTREAM(RawCode::unsafe_create(TEST_R_CODE),
"603EDF5CAFFF5E2\n| @ + |\n+ + + +\n| ~ + |\n+ * * +\n* . . *\n");
#endif
}

5
src/core_test/codec/short_code.cc

@ -52,9 +52,8 @@ TEST(ShortCode, basic) {
EXPECT_EQ(sum, SHORT_CODE_LIMIT);
#ifndef KLSK_NDEBUG
std::ostringstream out;
out << ShortCode::unsafe_create(TEST_S_CODE); // ostream capture
EXPECT_EQ(out.str(), TEST_S_CODE_STR);
EXPECT_OSTREAM(ShortCode::unsafe_create(0), "11111");
EXPECT_OSTREAM(ShortCode::unsafe_create(TEST_S_CODE), TEST_S_CODE_STR);
#endif
}

Loading…
Cancel
Save