From 7a282aa62849b56742c04d12f4bdb048e8957b66 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 26 Feb 2023 16:24:59 +0800 Subject: [PATCH] test: add vertical mirror global test --- test/codec/raw_code.cc | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/codec/raw_code.cc b/test/codec/raw_code.cc index 058be4b..40c639d 100644 --- a/test/codec/raw_code.cc +++ b/test/codec/raw_code.cc @@ -77,6 +77,26 @@ TEST(RawCode, initializate) { EXPECT_EQ(RawCode::from_common_code(common_code.to_string()).unwrap(), TEST_CODE); // r-value } +TEST(RawCode, vertical_mirror) { + auto raw_code_1 = RawCode::unsafe_create(0x0'FC0'480'6DB'FC0'480); // invalid layout only for test + auto raw_code_2 = RawCode::from_common_code(0x4FEA13400); + auto raw_code_2_ = RawCode::from_common_code(0x8346AFC00); + + EXPECT_EQ(raw_code_1.is_vertical_mirror(), true); + EXPECT_EQ(raw_code_1.to_vertical_mirror(), raw_code_1); + EXPECT_EQ(raw_code_1.is_vertical_mirror(raw_code_1), true); // l-value + EXPECT_EQ(raw_code_1.is_vertical_mirror(raw_code_2), false); // l-value + EXPECT_EQ(raw_code_1.is_vertical_mirror(static_cast(raw_code_1)), true); // r-value + EXPECT_EQ(raw_code_1.is_vertical_mirror(static_cast(raw_code_2)), false); // r-value + + EXPECT_EQ(raw_code_2.is_vertical_mirror(), false); + EXPECT_EQ(raw_code_2.to_vertical_mirror(), raw_code_2_); + EXPECT_EQ(raw_code_2.is_vertical_mirror(raw_code_1), false); // l-value + EXPECT_EQ(raw_code_2.is_vertical_mirror(raw_code_2_), true); // l-value + EXPECT_EQ(raw_code_2.is_vertical_mirror(static_cast(raw_code_1)), false); // r-value + EXPECT_EQ(raw_code_2.is_vertical_mirror(static_cast(raw_code_2_)), true); // r-value +} + TEST(RawCode, horizontal_mirror) { auto raw_code_1 = RawCode::from_common_code(0x1A9BF0C00); auto raw_code_2 = RawCode::from_common_code(0x4FEA13400); @@ -97,6 +117,31 @@ TEST(RawCode, horizontal_mirror) { EXPECT_EQ(raw_code_2.is_horizontal_mirror(static_cast(raw_code_2_)), true); // r-value } +TEST(RawCode, vertical_mirror_global) { + std::thread threads[16]; + auto test = [](uint64_t head) { + for (const auto &range : AllCases::fetch()[head]) { + /// generate code and mirror layout + auto common_code = CommonCode::unsafe_create(head << 32 | range); + auto raw_code = common_code.to_raw_code(); + auto raw_code_mirror = raw_code.to_vertical_mirror(); + + /// verify vertical mirror + EXPECT_EQ(raw_code_mirror.valid(), true); + EXPECT_EQ(raw_code_mirror.to_common_code().to_raw_code(), raw_code_mirror); + EXPECT_EQ(raw_code.is_vertical_mirror(), false); + EXPECT_NE(raw_code, raw_code_mirror); + EXPECT_EQ(raw_code_mirror.to_vertical_mirror(), raw_code); + } + }; + for (uint64_t head = 0; head < 16; ++head) { // split into 16 threads + threads[head] = std::thread(test, head); + } + for (auto &t : threads) { + t.join(); + } +} + TEST(RawCode, horizontal_mirror_global) { std::thread threads[16]; auto test = [](uint64_t head) {