pfor/tests/expression/algorithm.cpp
2021-05-10 18:11:23 +02:00

78 lines
2.8 KiB
C++

#include <catch.hpp>
#include "../common.h"
#include <pfor/expression/algorithm.h>
TEST_CASE("Operand Utilities") {
constexpr pfor::expr::Access r = pfor::expr::Access::read, w = pfor::expr::Access::write;
SECTION("WorstAccess") {
TEST_IF(REQUIRE, ==, r, pfor::expr::WorstAccess<r, r, r, r>::value);
TEST_IF(REQUIRE, ==, w, pfor::expr::WorstAccess<r, r, w, r>::value);
TEST_IF(REQUIRE, ==, w, pfor::expr::WorstAccess<r, w, w, r>::value);
TEST_IF(REQUIRE, ==, w, pfor::expr::WorstAccess<w, w, w, r>::value);
TEST_IF(REQUIRE, ==, w, pfor::expr::WorstAccess<w, w, w, w>::value);
}
SECTION("Tags") {
using Iterator = void;
using T1R = pfor::expr::OperandTag<class ID1, r, Iterator>;
using T2R = pfor::expr::OperandTag<class ID2, r, Iterator>;
using T3R = pfor::expr::OperandTag<class ID3, r, Iterator>;
using T1W = pfor::expr::OperandTag<class ID1, w, Iterator>;
using T2W = pfor::expr::OperandTag<class ID2, w, Iterator>;
using T3W = pfor::expr::OperandTag<class ID3, w, Iterator>;
using I0 = pfor::Pack<>;
using I1 = pfor::Pack<T1R, T2R, T3R>;
using I2 = pfor::Pack<T1W, T2W, T3W>;
using I3 = pfor::Pack<T1R, T1W, T2R, T2W, T3R, T3W>;
SECTION("CountWrite") {
using R = pfor::expr::OperandTag<class ID0, r, Iterator>;
using W = pfor::expr::OperandTag<class ID0, w, Iterator>;
TEST_IF(REQUIRE, ==, 0, pfor::expr::CountWrite<pfor::Pack<R, R, R, R>>::value);
TEST_IF(REQUIRE, ==, 1, pfor::expr::CountWrite<pfor::Pack<R, R, W, R>>::value);
TEST_IF(REQUIRE, ==, 2, pfor::expr::CountWrite<pfor::Pack<R, W, W, R>>::value);
TEST_IF(REQUIRE, ==, 3, pfor::expr::CountWrite<pfor::Pack<W, W, W, R>>::value);
TEST_IF(REQUIRE, ==, 4, pfor::expr::CountWrite<pfor::Pack<W, W, W, W>>::value);
}
SECTION("IncludeTags") {
using O0 = pfor::expr::IncludeTags<class ID1, I0>;
using O1 = pfor::expr::IncludeTags<class ID2, I1>;
using O2 = pfor::expr::IncludeTags<class ID3, I2>;
using O3 = pfor::expr::IncludeTags<class ID1, I3>;
using E0 = pfor::Pack<>;
using E1 = pfor::Pack<T2R>;
using E2 = pfor::Pack<T3W>;
using E3 = pfor::Pack<T1R, T1W>;
TEST(REQUIRE, is_same_v<O0, E0>);
TEST(REQUIRE, is_same_v<O1, E1>);
TEST(REQUIRE, is_same_v<O2, E2>);
TEST(REQUIRE, is_same_v<O3, E3>);
}
SECTION("ExcludeTags") {
using O0 = pfor::expr::ExcludeTags<class ID1, I0>;
using O1 = pfor::expr::ExcludeTags<class ID2, I1>;
using O2 = pfor::expr::ExcludeTags<class ID3, I2>;
using O3 = pfor::expr::ExcludeTags<class ID1, I3>;
using E0 = pfor::Pack<>;
using E1 = pfor::Pack<T1R, T3R>;
using E2 = pfor::Pack<T1W, T2W>;
using E3 = pfor::Pack<T2R, T2W, T3R, T3W>;
TEST(REQUIRE, is_same_v<O0, E0>);
TEST(REQUIRE, is_same_v<O1, E1>);
TEST(REQUIRE, is_same_v<O2, E2>);
TEST(REQUIRE, is_same_v<O3, E3>);
}
}
}