-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExplicitConvertOpTest.h
More file actions
108 lines (84 loc) · 2.03 KB
/
ExplicitConvertOpTest.h
File metadata and controls
108 lines (84 loc) · 2.03 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
#define BOOST_TEST_MODULE ExplicitConvertOpTest
#include "../IntX.h"
#include "../Utils/Constants.h"
#include <vector>
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(ExplicitConvertOpTest)
BOOST_AUTO_TEST_CASE(ConvertToInt)
{
int n = 1234567890;
IntX intX = n;
BOOST_CHECK(n == (int)intX);
n = -n;
intX = n;
BOOST_CHECK(n == (int)intX);
n = 0;
intX = n;
BOOST_CHECK(n == (int)intX);
n = 1234567890;
UInt32 un = (UInt32)n;
intX = IntX(vector<UInt32>({ un, un, un }), false);
BOOST_CHECK(n == (int)intX);
intX = IntX(vector<UInt32>({ un, un, un }), true);
BOOST_CHECK(-n == (int)intX);
}
BOOST_AUTO_TEST_CASE(ConvertToUInt)
{
UInt32 n = 1234567890;
IntX intX = n;
BOOST_CHECK(n == (UInt32)intX);
n = 0;
intX = n;
BOOST_CHECK(n == (UInt32)intX);
n = 1234567890;
intX = IntX(vector<UInt32>({ n, n, n }), false);
BOOST_CHECK(n == (UInt32)intX);
}
BOOST_AUTO_TEST_CASE(ConvertToInt64)
{
long long n = 1234567890123456789;
IntX intX = n;
BOOST_CHECK(n == (long long)intX);
n = -n;
intX = n;
BOOST_CHECK(n == (long long)intX);
n = 0;
intX = n;
BOOST_CHECK(n == (long long)intX);
UInt32 un = 1234567890;
n = (long long)(un | (UInt64)un << 32);
intX = IntX(vector<UInt32>({ un, un, un, un, un }), false);
BOOST_CHECK(n == (long long)intX);
intX = IntX(vector<UInt32>({ un, un, un, un, un }), true);
BOOST_CHECK(-n == (long long)intX);
int ni = 1234567890;
n = ni;
intX = ni;
BOOST_CHECK(n == (long long)intX);
}
BOOST_AUTO_TEST_CASE(ConvertToUInt64)
{
UInt64 n = 1234567890123456789;
IntX intX = n;
BOOST_CHECK(n == (UInt64)intX);
n = 0;
intX = n;
BOOST_CHECK(n == (UInt64)intX);
UInt32 un = 1234567890;
n = un | (UInt64)un << 32;
intX = IntX(vector<UInt32>({ un, un, un, un, un }), false);
BOOST_CHECK(n == (UInt64)intX);
n = un;
intX = un;
BOOST_CHECK(n == (UInt64)intX);
}
BOOST_AUTO_TEST_CASE(ConvertToUshort)
{
unsigned short n = 12345;
IntX intX = n;
BOOST_CHECK(n == (unsigned short)intX);
n = 0;
intX = n;
BOOST_CHECK(n == (unsigned short)intX);
}
BOOST_AUTO_TEST_SUITE_END()