Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
util
IntTypes.ut.cpp
Go to the documentation of this file.
1
// The Reactive C++ Toolbox.
2
// Copyright (C) 2013-2019 Swirly Cloud Limited
3
// Copyright (C) 2021 Reactive Markets Limited
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "
IntTypes.hpp
"
18
19
#include <boost/test/unit_test.hpp>
20
21
#include <boost/lexical_cast.hpp>
22
23
using namespace
boost;
24
using namespace
std
;
25
using namespace
toolbox
;
26
27
namespace
{
28
29
struct
TestTag :
Int32Policy
{};
30
using
Test
=
IntWrapper<TestTag>
;
31
32
constexpr
Test
operator
""
_test
(
unsigned
long
long
val
)
noexcept
33
{
34
return
Test
{
val
};
35
}
36
37
}
// namespace
38
39
BOOST_AUTO_TEST_SUITE
(
IntTypesSuite
)
40
41
BOOST_AUTO_TEST_CASE
(
IntAddAssignCase
)
42
{
43
auto
x
= 5
_test
;
44
BOOST_CHECK_EQUAL
((
x
+= 3
_test
), 8
_test
);
45
BOOST_CHECK_EQUAL
(
x
, 8
_test
);
46
}
47
48
BOOST_AUTO_TEST_CASE
(
IntSubAssignCase
)
49
{
50
auto
x
= 5
_test
;
51
BOOST_CHECK_EQUAL
((
x
-= 3
_test
), 2
_test
);
52
BOOST_CHECK_EQUAL
(
x
, 2
_test
);
53
}
54
55
BOOST_AUTO_TEST_CASE
(
IntMulAssignCase
)
56
{
57
auto
x
= 5
_test
;
58
BOOST_CHECK_EQUAL
((
x
*= 3
_test
), 15
_test
);
59
BOOST_CHECK_EQUAL
(
x
, 15
_test
);
60
}
61
62
BOOST_AUTO_TEST_CASE
(
IntDivAssignCase
)
63
{
64
auto
x
= 15
_test
;
65
BOOST_CHECK_EQUAL
((
x
/= 3
_test
), 5
_test
);
66
BOOST_CHECK_EQUAL
(
x
, 5
_test
);
67
}
68
69
BOOST_AUTO_TEST_CASE
(
IntModAssignCase
)
70
{
71
auto
x
= 5
_test
;
72
BOOST_CHECK_EQUAL
((
x
%= 3
_test
), 2
_test
);
73
BOOST_CHECK_EQUAL
(
x
, 2
_test
);
74
}
75
76
BOOST_AUTO_TEST_CASE
(
IntBitwiseAndAssignCase
)
77
{
78
// 11100
79
// 00111
80
// 00100
81
auto
x
= 28
_test
;
82
BOOST_CHECK_EQUAL
((
x
&= 7
_test
), 4
_test
);
83
BOOST_CHECK_EQUAL
(
x
, 4
_test
);
84
}
85
86
BOOST_AUTO_TEST_CASE
(
IntBitwiseOrAssignCase
)
87
{
88
// 11100
89
// 00111
90
// 11111
91
auto
x
= 28
_test
;
92
BOOST_CHECK_EQUAL
((
x
|= 7
_test
), 31
_test
);
93
BOOST_CHECK_EQUAL
(
x
, 31
_test
);
94
}
95
96
BOOST_AUTO_TEST_CASE
(
IntBitwiseXorAssignCase
)
97
{
98
// 11100
99
// 00111
100
// 11011
101
auto
x
= 28
_test
;
102
BOOST_CHECK_EQUAL
((
x
^= 7
_test
), 27
_test
);
103
BOOST_CHECK_EQUAL
(
x
, 27
_test
);
104
}
105
106
BOOST_AUTO_TEST_CASE
(
IntLeftShiftAssignCase
)
107
{
108
// 00111
109
// 11100
110
auto
x
= 7
_test
;
111
BOOST_CHECK_EQUAL
((
x
<<= 2
_test
), 28
_test
);
112
BOOST_CHECK_EQUAL
(
x
, 28
_test
);
113
}
114
115
BOOST_AUTO_TEST_CASE
(
IntRightShiftAssignCase
)
116
{
117
// 11100
118
// 00111
119
auto
x
= 28
_test
;
120
BOOST_CHECK_EQUAL
((
x
>>= 2
_test
), 7
_test
);
121
BOOST_CHECK_EQUAL
(
x
, 7
_test
);
122
}
123
124
BOOST_AUTO_TEST_CASE
(
IntPreIncCase
)
125
{
126
auto
x
= 5
_test
;
127
BOOST_CHECK_EQUAL
(++
x
, 6
_test
);
128
BOOST_CHECK_EQUAL
(
x
, 6
_test
);
129
}
130
131
BOOST_AUTO_TEST_CASE
(
IntPreDecCase
)
132
{
133
auto
x
= 5
_test
;
134
BOOST_CHECK_EQUAL
(--
x
, 4
_test
);
135
BOOST_CHECK_EQUAL
(
x
, 4
_test
);
136
}
137
138
BOOST_AUTO_TEST_CASE
(
IntPostIncCase
)
139
{
140
auto
x
= 5
_test
;
141
BOOST_CHECK_EQUAL
(
x
++, 5
_test
);
142
BOOST_CHECK_EQUAL
(
x
, 6
_test
);
143
}
144
145
BOOST_AUTO_TEST_CASE
(
IntPostDecCase
)
146
{
147
auto
x
= 5
_test
;
148
BOOST_CHECK_EQUAL
(
x
--, 5
_test
);
149
BOOST_CHECK_EQUAL
(
x
, 4
_test
);
150
}
151
152
BOOST_AUTO_TEST_CASE
(
IntUnaryPlusCase
)
153
{
154
constexpr
auto
x
= 5
_test
;
155
BOOST_CHECK_EQUAL
(+
x
, 5
_test
);
156
}
157
158
BOOST_AUTO_TEST_CASE
(
IntUnaryMinusCase
)
159
{
160
constexpr
auto
x
= 5
_test
;
161
BOOST_CHECK_EQUAL
(-
x
, -5
_test
);
162
}
163
164
BOOST_AUTO_TEST_CASE
(
IntAddCase
)
165
{
166
constexpr
auto
x
= 5
_test
;
167
BOOST_CHECK_EQUAL
((
x
+ 3
_test
), 8
_test
);
168
}
169
170
BOOST_AUTO_TEST_CASE
(
IntSubCase
)
171
{
172
constexpr
auto
x
= 5
_test
;
173
BOOST_CHECK_EQUAL
((
x
- 3
_test
), 2
_test
);
174
}
175
176
BOOST_AUTO_TEST_CASE
(
IntMulCase
)
177
{
178
constexpr
auto
x
= 5
_test
;
179
BOOST_CHECK_EQUAL
((
x
* 3
_test
), 15
_test
);
180
}
181
182
BOOST_AUTO_TEST_CASE
(
IntDivCase
)
183
{
184
constexpr
auto
x
= 15
_test
;
185
BOOST_CHECK_EQUAL
(
x
/ 3
_test
, 5
_test
);
186
}
187
188
BOOST_AUTO_TEST_CASE
(
IntModCase
)
189
{
190
constexpr
auto
x
= 5
_test
;
191
BOOST_CHECK_EQUAL
((
x
% 3
_test
), 2
_test
);
192
}
193
194
BOOST_AUTO_TEST_CASE
(
IntBitwiseNotCase
)
195
{
196
constexpr
auto
x
=
Test
{~1};
197
BOOST_CHECK_EQUAL
(~
x
, 1
_test
);
198
}
199
200
BOOST_AUTO_TEST_CASE
(
IntBitwiseAndCase
)
201
{
202
// 11100
203
// 00111
204
// 00100
205
constexpr
auto
x
= 28
_test
;
206
BOOST_CHECK_EQUAL
((
x
& 7
_test
), 4
_test
);
207
}
208
209
BOOST_AUTO_TEST_CASE
(
IntBitwiseOrCase
)
210
{
211
// 11100
212
// 00111
213
// 11111
214
constexpr
auto
x
= 28
_test
;
215
BOOST_CHECK_EQUAL
((
x
| 7
_test
), 31
_test
);
216
}
217
218
BOOST_AUTO_TEST_CASE
(
IntBitwiseXorCase
)
219
{
220
// 11100
221
// 00111
222
// 11011
223
constexpr
auto
x
= 28
_test
;
224
BOOST_CHECK_EQUAL
((
x
^ 7
_test
), 27
_test
);
225
}
226
227
BOOST_AUTO_TEST_CASE
(
IntLeftShiftCase
)
228
{
229
// 00111
230
// 11100
231
constexpr
auto
x
= 7
_test
;
232
BOOST_CHECK_EQUAL
((
x
<< 2
_test
), 28
_test
);
233
}
234
235
BOOST_AUTO_TEST_CASE
(
IntRightShiftCase
)
236
{
237
// 11100
238
// 00111
239
constexpr
auto
x
= 28
_test
;
240
BOOST_CHECK_EQUAL
((
x
>> 2
_test
), 7
_test
);
241
}
242
243
BOOST_AUTO_TEST_CASE
(
IntEqualToCase
)
244
{
245
BOOST_CHECK_EQUAL
(5
_test
, 5
_test
);
246
}
247
248
BOOST_AUTO_TEST_CASE
(
IntNotEqualToCase
)
249
{
250
BOOST_CHECK_NE
(5
_test
, 7
_test
);
251
}
252
253
BOOST_AUTO_TEST_CASE
(
IntLessThanCase
)
254
{
255
BOOST_CHECK_LT
(5
_test
, 7
_test
);
256
}
257
258
BOOST_AUTO_TEST_CASE
(
IntGreaterThanCase
)
259
{
260
BOOST_CHECK_GT
(5
_test
, 3
_test
);
261
}
262
263
BOOST_AUTO_TEST_CASE
(
IntLessThanOrEqualToCase
)
264
{
265
BOOST_CHECK_LE
(5
_test
, 5
_test
);
266
BOOST_CHECK_LE
(5
_test
, 7
_test
);
267
}
268
269
BOOST_AUTO_TEST_CASE
(
IntGreaterThanOrEqualToCase
)
270
{
271
BOOST_CHECK_GE
(5
_test
, 5
_test
);
272
BOOST_CHECK_GE
(5
_test
, 3
_test
);
273
}
274
275
BOOST_AUTO_TEST_CASE
(
IntInsertionCase
)
276
{
277
BOOST_CHECK_EQUAL
(
lexical_cast<string>
(5
_test
),
"5"
);
278
}
279
280
BOOST_AUTO_TEST_SUITE_END
()
IntTypes.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(IntAddAssignCase)
Definition
IntTypes.ut.cpp:41
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(v.size(), 10U)
std
STL namespace.
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox::util::Test
Test
Definition
Enum.ut.cpp:30
toolbox
Definition
Benchmark.cpp:26
toolbox::util::IntPolicy
Definition
IntTypes.hpp:28
toolbox::IntWrapper
Definition
IntTypes.hpp:38
Generated by
1.9.8