Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
bits
Commits
c7c2f23c
Commit
c7c2f23c
authored
Jun 19, 2018
by
Gauthier Quesnel
Browse files
test: added tagged-union unit test
parent
ecb4ab20
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/parameter.cpp
0 → 100644
View file @
c7c2f23c
#include <vector>
#include "tagged-union.hpp"
#include "unit-test.hpp"
static
void
check_tagged_union
()
{
bits
::
tagged_union
real
{
3.0
};
Ensures
(
real
.
type
==
bits
::
tagged_union
::
tag
::
real
);
bits
::
tagged_union
integer
{
1000
};
Ensures
(
integer
.
type
==
bits
::
tagged_union
::
tag
::
integer
);
bits
::
tagged_union
str
{
"hello world"
};
Ensures
(
str
.
type
==
bits
::
tagged_union
::
tag
::
string
);
str
=
real
;
Ensures
(
str
.
type
==
bits
::
tagged_union
::
tag
::
real
);
Ensures
(
str
.
d
==
3.0
);
str
=
integer
;
Ensures
(
str
.
type
==
bits
::
tagged_union
::
tag
::
integer
);
Ensures
(
str
.
l
==
1000
);
std
::
vector
<
bits
::
tagged_union
>
x
(
100
);
for
(
auto
&
elem
:
x
)
{
Ensures
(
elem
.
type
==
bits
::
tagged_union
::
tag
::
integer
);
Ensures
(
elem
.
l
==
0
);
}
auto
y
=
bits
::
tagged_union
(
4.0
);
Ensures
(
y
.
type
==
bits
::
tagged_union
::
tag
::
real
);
Ensures
(
y
.
d
==
4.0
);
x
[
0
]
=
bits
::
tagged_union
(
5.0
);
Ensures
(
x
[
0
].
type
==
bits
::
tagged_union
::
tag
::
real
);
Ensures
(
x
[
0
].
d
==
5.0
);
x
[
0
].
swap
(
x
[
1
]);
Ensures
(
x
[
0
].
type
==
bits
::
tagged_union
::
tag
::
integer
);
Ensures
(
x
[
0
].
l
==
0l
);
Ensures
(
x
[
1
].
type
==
bits
::
tagged_union
::
tag
::
real
);
Ensures
(
x
[
1
].
d
==
5.0
);
x
[
2
]
=
std
::
move
(
x
[
1
]);
Ensures
(
x
[
0
].
type
==
bits
::
tagged_union
::
tag
::
integer
);
Ensures
(
x
[
0
].
l
==
0l
);
Ensures
(
x
[
1
].
type
==
bits
::
tagged_union
::
tag
::
integer
);
Ensures
(
x
[
1
].
l
==
0l
);
Ensures
(
x
[
2
].
type
==
bits
::
tagged_union
::
tag
::
real
);
EnsuresEqual
(
x
[
2
].
d
,
5.0
);
EnsuresNotEqual
(
x
[
2
].
d
,
6.0
);
x
[
3
]
=
bits
::
tagged_union
(
std
::
string
(
"hello world!"
));
Ensures
(
x
[
3
].
type
==
bits
::
tagged_union
::
tag
::
string
);
Ensures
(
x
[
3
].
s
==
"hello world!"
);
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
check_tagged_union
();
return
unit_test
::
report_errors
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment