-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoExVariTest.cpp
More file actions
152 lines (123 loc) · 5.1 KB
/
Copy pathCoExVariTest.cpp
File metadata and controls
152 lines (123 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "CoExVari.hpp"
#include "InCoList.hpp"
#include <type_traits> // static testing
#include <UnitTest++/UnitTest++.h> // dynamic testing
using namespace std;
using namespace vmp;
SUITE(CoExVari) {
// A struct without "static const bool value".
struct no_cast {};
struct bad_cast {
bool value[1] = { true };
constexpr bad_cast() {}
// NOTE: If bool value[1] was declared "static constexpr" then
// value[t_index] would be static, resulting in an error
// even if the conversion was not required.
constexpr operator bool() { return value[1]; }
};
TEST(ConstExprOr) {
// Idempotent
static_assert(!or_all(), "Or with zero arguments is the idempotent, which is false");
// Identity
static_assert(or_all(true), "Or for one argument is identity");
static_assert(!or_all(false), "Or for one argument is identity");
// Logic matrix
static_assert(or_all(true, true), "T || T == T");
static_assert(or_all(false, true), "F || T == T");
static_assert(or_all(true, false), "T || F == T");
static_assert(!or_all(false, false), "F || F == F");
// Implicit casting
//static_assert(or_all(incolist<bool, true>()), "Use implicit cast to bool");
//static_assert(or_all(incolist<bool, true>[0]), "Use implicit cast to bool");
// Short circuit - cast definition is only required if cast will be evaluated
static_assert(or_all(true, no_cast()), "Short circuit hides absence of cast");
static_assert(or_all(true, bad_cast()), "Short circuit prevents invalid indexing");
// Application to incolist
using data = incolist<bool, false, true, false>;
static_assert(data::merged<bool>(&or_all),
"Rebind should yield variadic or of integral constant booleans");
}
TEST(ConstExprAnd) {
// Idempotent
static_assert(and_all(), "And with zero arguments is the idempotent, which is true");
// Identity
static_assert(and_all(true), "And for one argument is identity");
static_assert(!and_all(false), "And for one argument is identity");
// Logic matrix
static_assert(and_all(true, true), "T && T == T");
static_assert(!and_all(false, true), "F && T == F");
static_assert(!and_all(true, false), "T && F == F");
static_assert(!and_all(false, false), "F && F == F");
// Implicit casting
static_assert(and_all(incolist<bool, true>()), "Use implicit cast to bool");
// Short circuit - cast definition is only required if cast will be evaluated
static_assert(!and_all(false, no_cast()), "Short circuit hides absence of cast");
static_assert(!and_all(false, bad_cast()), "Short circuit prevents invalid indexing");
// Application to incolist
using data = incolist<bool, true, false, true>;
static_assert(!data::merged<bool>(&and_all),
"Rebind should yield variadic and of integral constant booleans");
}
TEST(ConstExprPlus) {
// Idempotent
static_assert(0 == plus_all(),
"Sum of zero arguments is idempotnent, which is 0");
// Identity
static_assert(2 == plus_all(2), "Sum of one argument is identity");
// Logic matrix
static_assert(7 == plus_all(3, 4), "Multiple arguments are summed");
static_assert(18 == plus_all(5, 6, 7), "Multiple arguments are summed");
// Application to incolist
using data = incolist<sizetype, 2, 3, 4>;
static_assert(9 == data::merged<sizetype>(&plus_all),
"Rebind should yield variadic sum of integral constant arguments");
// Casting
static_assert(is_same<
decltype(0),
decltype(plus_all())
>::value, "Type is determined by lossless representation");
static_assert(is_same<
short,
decltype(plus_all((short)1))
>::value, "Type is determined by lossless representation");
static_assert(is_same<
long,
decltype(plus_all((short)1, (int)2, (long)3))
>::value, "Type is determined by lossless representation");
static_assert(is_same<
long,
decltype(plus_all((long)1, (int)2, (short)3))
>::value, "Type is determined by lossless representation");
}
TEST(ConstExprTimes) {
// Idempotent
static_assert(1 == times_all(),
"Product of zero arguments is idempotnent, which is 1");
// Identity
static_assert(2 == times_all(2), "Product of one argument is identity");
// Logic matrix
static_assert(12 == times_all(3, 4), "Multiple arguments are multiplied");
static_assert(210 == times_all(5, 6, 7), "Multiple arguments are multiplied");
// Application to incolist
using data = incolist<sizetype, 2, 3, 4>;
static_assert(24 == data::merged<sizetype>(×_all),
"Rebind should yield variadic sum of integral constant arguments");
// Casting
static_assert(is_same<
decltype(0),
decltype(times_all())
>::value, "Type is determined by lossless representation");
static_assert(is_same<
short,
decltype(times_all((short)1))
>::value, "Type is determined by lossless representation");
static_assert(is_same<
long,
decltype(times_all((short)1, (int)2, (long)3))
>::value, "Type is determined by lossless representation");
static_assert(is_same<
long,
decltype(times_all((long)1, (int)2, (short)3))
>::value, "Type is determined by lossless representation");
}
}