Browse Source

test: add operator test suites for Ranges

master
Dnomd343 5 months ago
parent
commit
fece208b2f
  1. 1
      src/core_test/CMakeLists.txt
  2. 35
      src/core_test/cases/ranges.cc
  3. 24
      src/core_test/cases/ranges_union.cc

1
src/core_test/CMakeLists.txt

@ -21,6 +21,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../core/common_code)
set(KLSK_TEST_CASES_SRC
cases/ranges.cc
cases/ranges_union.cc
cases/basic_ranges.cc
cases/all_cases.cc
cases/group_union.cc

35
src/core_test/cases/ranges.cc

@ -5,16 +5,13 @@
#include "ranges/ranges.h"
static_assert(std::is_base_of_v<std::vector<uint32_t>, Ranges>);
static_assert(std::is_base_of_v<std::array<Ranges, 16>, RangesUnion>);
TEST(Ranges, check) {
RangesUnion all_cases;
const auto ranges = BasicRanges::instance().fetch();
for (const auto head : Heads) {
for (auto range : ranges) {
for (auto range : BasicRanges::instance().fetch()) {
if (Ranges::check(head, range_reverse(range)) == 0) {
all_cases[head].emplace_back(range); // valid cases
all_cases[head].emplace_back(range); // found valid cases
}
}
}
@ -25,13 +22,13 @@ TEST(Ranges, spawn) {
for (auto [n, n_2x1, n_1x1] : BLOCK_NUM) {
Ranges ranges;
ranges.spawn(n, n_2x1, n_1x1);
EXPECT_SORTED_AND_UNIQUE(ranges);
EXPECT_SORTED_AND_UNIQUE(ranges); // sorted and unique
for (const auto range : ranges) {
const auto [val_1x1, val_1x2, val_2x1] = cal_block_num(range);
EXPECT_EQ(val_1x1, n_1x1);
EXPECT_EQ(val_2x1, n_2x1);
EXPECT_EQ(val_1x2 + val_2x1, n);
EXPECT_EQ(val_1x2 + val_2x1, n); // verify block nums
}
}
}
@ -40,18 +37,18 @@ TEST(Ranges, derive) {
for (auto [n, n_2x1, n_1x1] : BLOCK_NUM) {
Ranges ranges;
ranges.spawn(n, n_2x1, n_1x1);
ranges.reverse();
ranges.reverse(); // reverse ranges for derive
RangesUnion cases;
for (const auto head : Heads) {
ranges.derive(head, cases[head]);
EXPECT_SORTED_AND_UNIQUE(cases[head]);
EXPECT_COMMON_CODES(head, cases[head]);
EXPECT_SORTED_AND_UNIQUE(cases[head]); // sorted and unique
EXPECT_COMMON_CODES(head, cases[head]); // verify common codes
}
ranges.reverse();
for (const auto head : Heads) {
EXPECT_SUBSET(ranges, cases[head]); // subset verify
EXPECT_SUBSET(ranges, cases[head]); // derive ranges is subset
}
}
}
@ -82,9 +79,8 @@ TEST(Ranges, combine) {
for (auto [n, n_2x1, n_1x1] : BLOCK_NUM) {
Ranges ranges;
ranges.spawn(n, n_2x1, n_1x1);
// TODO: add += interface
all_ranges.insert(all_ranges.end(), ranges.begin(), ranges.end());
ranges.reverse();
all_ranges += ranges;
ranges.reverse(); // reverse ranges for derive
for (const auto head : Heads) {
ranges.derive(head, all_cases[head]); // derive from sub ranges
}
@ -97,7 +93,7 @@ TEST(Ranges, combine) {
EXPECT_EQ(all_ranges, BasicRanges::instance().fetch()); // verify content
EXPECT_EQ(all_cases, AllCases::instance().fetch()); // verify content
all_ranges.reverse();
all_ranges.reverse(); // reverse ranges for derive
for (const auto head : Heads) {
all_cases[head].clear();
all_ranges.derive(head, all_cases[head]); // derive from all ranges
@ -105,4 +101,11 @@ TEST(Ranges, combine) {
EXPECT_EQ(all_cases, AllCases::instance().fetch()); // verify content
}
// TODO: export CommonCode
TEST(Ranges, operator) {
Ranges r, r1, r2;
r.spawn(5, 3, 4);
r.spawn(5, 4, 4);
r1.spawn(5, 3, 4);
r2.spawn(5, 4, 4);
EXPECT_EQ(r, r1 += r2);
}

24
src/core_test/cases/ranges_union.cc

@ -0,0 +1,24 @@
#include <gtest/gtest.h>
#include "helper/cases.h"
#include "ranges/ranges.h"
static_assert(std::is_base_of_v<std::array<Ranges, 16>, RangesUnion>);
// TODO: test CommonCode export
TEST(RangesUnion, operator) {
Ranges r, r1, r2;
r.spawn(5, 3, 4);
r.spawn(5, 4, 4);
r1.spawn(5, 3, 4);
r2.spawn(5, 4, 4);
RangesUnion r_, r1_, r2_;
for (const auto head : Heads) {
r.derive(head, r_[head]);
r1.derive(head, r1_[head]);
r2.derive(head, r2_[head]);
}
EXPECT_EQ(r_, r1_ += r2_);
}
Loading…
Cancel
Save