-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_readable.cpp
105 lines (94 loc) · 4 KB
/
test_readable.cpp
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
#include "humanreadable.h"
#include "test_helpers.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_adapters.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <sstream>
#include <string>
#include <cstdint>
TEST_CASE("Test constructor works as expected", "[constructor]") {
auto a = GENERATE(take(100, random<int>(INT32_MIN, INT32_MAX)));
HumanReadableNum b{a};
std::stringstream ss;
ss << a;
std::string expected = ss.str();
ss = {};
ss << b;
std::string result = ss.str();
INFO("Expected = " << expected << " Result = " << result);
CHECK(expected == result);
}
TEST_CASE("Verify subtraction works as expected", "[subtraction]") {
// Testing the interval [-2,500,000 2,500,000] prevents rollover
auto testVals = GENERATE(take(100, pair_random<int>(-2500000,2500000)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
int expected = testVals.first - testVals.second;
HumanReadableNum result = tv1 - tv2;
INFO("Testing: " << testVals.first << " - " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(result == expected);
}
TEST_CASE("Verify AddEquals operation works as expected", "[hr_addeq]") {
// Testing the interval [-2,500,000 2,500,000] prevents rollover
auto testVals = GENERATE(take(100, pair_random<int>(-2500000,2500000)));
HumanReadableNum result{testVals.first};
HumanReadableNum tv2{testVals.second};
int expected = testVals.first + testVals.second;
result += tv2;
INFO("Testing: " << testVals.first << " += " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(result == expected);
}
TEST_CASE("Verify addition works as expected", "[addition]") {
// Testing the interval [-2,500,000 2,500,000] prevents rollover
auto testVals = GENERATE(take(100, pair_random<int>(-2500000,2500000)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
int expected = testVals.first + testVals.second;
HumanReadableNum result = tv1 + tv2;
INFO("Testing: " << testVals.first << " + " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(result == expected);
}
TEST_CASE("Verify spaceship operator works", "[spaceship_operator]") {
auto testVals = GENERATE(take(100, pair_random<int>(INT32_MIN,INT32_MAX)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
auto expected = testVals.first <=> testVals.second;
auto result = tv1 <=> tv2;
INFO(testVals.first << " <=> " << testVals.second);
INFO("Expected = " << comparisonString(expected) << " Result = " << comparisonString(result));
CHECK(result == expected);
}
TEST_CASE("Verify Multiplication works", "[multi_operator]") {
auto testVals = GENERATE(take(100, pair_random<int>(INT16_MIN, INT16_MAX)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
auto expected = testVals.first * testVals.second;
auto result = tv1 * tv2;
INFO("Testing: " << testVals.first << " * " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(expected == result);
}
TEST_CASE("Verify Division works", "[divide_operator]") {
auto testVals = GENERATE(take(100, pair_random<int>(INT16_MIN, INT16_MAX)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
auto expected = testVals.first / testVals.second;
auto result = tv1 / tv2;
INFO("Testing: " << testVals.first << " / " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(expected == result);
}
TEST_CASE("Verify Modulo works", "[modulo_operator]") {
auto testVals = GENERATE(take(100, pair_random<int>(INT32_MIN, INT32_MAX)));
HumanReadableNum tv1{testVals.first};
HumanReadableNum tv2{testVals.second};
auto expected = testVals.first % testVals.second;
auto result = tv1 % tv2;
INFO("Testing: " << testVals.first << " % " << testVals.second);
INFO("Expected = " << expected << " Result = " << result);
CHECK(expected == result);
}