-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
157 lines (137 loc) · 4.83 KB
/
Copy pathtest.cpp
File metadata and controls
157 lines (137 loc) · 4.83 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
153
154
155
156
#include "testnum.h"
#include "test_helpers.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_adapters.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <cstdlib>
#include <cstdint>
TEST_CASE("uint32 round trip conversion works", "[constructor]") {
auto a = GENERATE(take(100, random<unsigned int>(0, UINT32_MAX)));
TestNum b{a};
REQUIRE(b.to_uint32() == a);
}
TEST_CASE("Check Addition works", "[addition]") {
auto testVals = GENERATE(take(100, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a + b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 + tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Subtraction works", "[subtraction]") {
auto testVals = GENERATE(take(1000, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a - b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 - tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Multiplication works", "[multiplication]") {
auto testVals = GENERATE(take(100, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a * b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 * tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Division works", "[division]") {
auto testVals = GENERATE(take(100, filter([](std::pair<unsigned int, unsigned int> const& i) {return (i.second != 0);}, pair_random<unsigned int>(0U, UINT32_MAX))));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a / b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 / tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Modulus works", "[modulus]") {
auto testVals = GENERATE(take(100, filter([](std::pair<unsigned int, unsigned int> const& i) {return (i.second != 0);}, pair_random<unsigned int>(0U, UINT32_MAX))));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a % b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 % tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check AND works", "[bitand]") {
auto testVals = GENERATE(take(100, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a & b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 & tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check OR works", "[bitor]") {
auto testVals = GENERATE(take(100, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a | b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 | tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check XOR works", "[bitxor]") {
auto testVals = GENERATE(take(100, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
std::uint32_t res = a ^ b;
TestNum tv1{a};
TestNum tv2{b};
auto result = tv1 ^ tv2;
INFO("a = " << a << " b = " << b);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check NOT works", "[bitnot]") {
std::uint32_t a = GENERATE(take(100, random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t res = ~a;
TestNum tv1{a};
auto result = ~tv1;
INFO("a = " << a );
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Bitshift left works", "[bitshiftleft]") {
auto testVals = GENERATE(take(1000, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t displacement = testVals.second % 32;
auto res = a << displacement;
TestNum tv1{a};
auto result = tv1 << displacement;
INFO("a = " << a << " Offset = " << displacement);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check Bitshift right works", "[bitshiftright]") {
auto testVals = GENERATE(take(1000, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t displacement = testVals.second % 32;
std::uint32_t res = a >> displacement;
TestNum tv1{a};
auto result = tv1 >> displacement;
INFO("a = " << a << " Offset = " << displacement);
CHECK(result.to_uint32() == res);
}
TEST_CASE("Check LT Comparison operator", "[ltcomp]") {
auto testVals = GENERATE(take(1000, pair_random<unsigned int>(0U, UINT32_MAX)));
std::uint32_t a = testVals.first;
std::uint32_t b = testVals.second;
TestNum tv1{a};
TestNum tv2{b};
INFO("a = " << a << " b = " << b << " tv1 = " << tv1.to_uint32() << " tv2 = " << tv2.to_uint32());
CHECK((tv1 < tv2) == (a < b));
}