#include #include #include #include #define N 5 TEST_CASE("Expression") { int a[]{1000, 2000, 3000, 4000, 5000}, ca[]{1000, 2000, 3000, 4000, 5000}, b[]{9, 8, 7, 6, 5}, *pa[]{a+0, a+1, a+2, a+3, a+4}; pfor::expr::Expression, pfor::Index> ea{a}; pfor::expr::Expression, pfor::Index> eb{b}; pfor::expr::Expression, pfor::Index> epa{pa}; SECTION("Expression") { for(std::size_t i = 0; i < N; ++i) { REQUIRE(ea[i] == a[i]); REQUIRE(eb[i] == b[i]); } } SECTION("Basic operations") { SECTION("Unary") { SECTION("PostIncr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea++)[i] == (ca[i])); REQUIRE(a[i] == (ca[i]+1)); } } SECTION("PostDecr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea--)[i] == (ca[i])); REQUIRE(a[i] == (ca[i]-1)); } } SECTION("PreIncr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((++ea)[i] == (ca[i]+1)); REQUIRE(a[i] == (ca[i]+1)); } } SECTION("PreDecr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((--ea)[i] == (ca[i]-1)); REQUIRE(a[i] == (ca[i]-1)); } } SECTION("Plus") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((+ea)[i] == (ca[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Minus") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((-ea)[i] == (-ca[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Not") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((!ea)[i] == (!ca[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("BitNot") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((~ea)[i] == (~ca[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Indirection") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((*epa)[i] == (a[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("AddressOf") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((&ea)[i] == (a+i)); REQUIRE(a[i] == (ca[i])); } } } SECTION("Binary") { SECTION("Multiplication") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea*eb)[i] == (a[i]*b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Division") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea/eb)[i] == (a[i]/b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Modulo") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea%eb)[i] == (a[i]%b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Addition") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea+eb)[i] == (a[i]+b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Subtraction") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea-eb)[i] == (a[i]-b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("LeftShift") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea<>eb)[i] == (a[i]>>b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Lower") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((eaeb)[i] == (a[i]>b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("GreaterEqual") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea>=eb)[i] == (a[i]>=b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Equal") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea==eb)[i] == (a[i]==b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("NotEqual") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea!=eb)[i] == (a[i]!=b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("BitAnd") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea&eb)[i] == (a[i]&b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("BitXor") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea^eb)[i] == (a[i]^b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("BitOr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea|eb)[i] == (a[i]|b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("And") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea&&eb)[i] == (a[i]&&b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Or") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea||eb)[i] == (a[i]||b[i])); REQUIRE(a[i] == (ca[i])); } } SECTION("Assignments") { SECTION("Assign") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea=eb)[i] == (a[i]=b[i])); REQUIRE(a[i] == b[i]); } } SECTION("AssignAdd") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea+=eb)[i] == (a[i]+b[i])); REQUIRE(a[i] == (ca[i]+b[i])); } } SECTION("AssignSub") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea-=eb)[i] == (a[i]-b[i])); REQUIRE(a[i] == (ca[i]-b[i])); } } SECTION("AssignMul") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea*=eb)[i] == (a[i]*b[i])); REQUIRE(a[i] == (ca[i]*b[i])); } } SECTION("AssignDiv") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea/=eb)[i] == (a[i]/b[i])); REQUIRE(a[i] == (ca[i]/b[i])); } } SECTION("AssignMod") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea%=eb)[i] == (a[i]%b[i])); REQUIRE(a[i] == (ca[i]%b[i])); } } SECTION("AssignLS") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea<<=eb)[i] == (a[i]<>=eb)[i] == (a[i]>>b[i])); REQUIRE(a[i] == (ca[i]>>b[i])); } } SECTION("AssignAnd") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea&=eb)[i] == (a[i]&b[i])); REQUIRE(a[i] == (ca[i]&b[i])); } } SECTION("AssignXor") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea^=eb)[i] == (a[i]^b[i])); REQUIRE(a[i] == (ca[i]^b[i])); } } SECTION("AssignOr") { for(std::size_t i = 0; i < N; ++i) { REQUIRE((ea|=eb)[i] == (a[i]|b[i])); REQUIRE(a[i] == (ca[i]|b[i])); } } } } } }