-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_atom.cpp
203 lines (164 loc) · 6.44 KB
/
test_atom.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "catch.hpp"
#include <string>
#include <tuple>
#include "atom.hpp"
TEST_CASE("Tests the Atom constructors", "[atom]") {
Atom aNone = Atom();
Atom aBool = Atom(true);
Atom aNumber = Atom(2.5);
Atom aSymbol = Atom(std::string("Test"));
Atom aPoint = Atom(makePoint(1, 2));
Atom aLine = Atom(makeLine(makePoint(0, 0), makePoint(5, 5)));
Atom aArc = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1));
REQUIRE(aNone.getType() == Atom::Type::NONE);
REQUIRE(aBool.getType() == Atom::Type::BOOL);
REQUIRE(aNumber.getType() == Atom::Type::NUMBER);
REQUIRE(aSymbol.getType() == Atom::Type::SYMBOL);
REQUIRE(aPoint.getType() == Atom::Type::POINT);
REQUIRE(aLine.getType() == Atom::Type::LINE);
REQUIRE(aArc.getType() == Atom::Type::ARC);
REQUIRE(aBool.getBool());
REQUIRE(aNumber.getNumber() == 2.5);
REQUIRE(aSymbol.getSymbol() == "Test");
REQUIRE(pointX(aPoint.getPoint()) == 1);
REQUIRE(pointY(aPoint.getPoint()) == 2);
REQUIRE(aPoint.getPoint() == makePoint(1, 2));
REQUIRE(aLine.getLine().first == makePoint(0, 0));
REQUIRE(aLine.getLine().second == makePoint(5, 5));
REQUIRE(aArc.getArc().center == makePoint(0, 0));
REQUIRE(aArc.getArc().start == makePoint(5, 5));
REQUIRE(aArc.getArc().span == 1);
}
TEST_CASE("Tests the equality operator for Atoms", "[atom]") {
Atom aNone1 = Atom();
Atom aBool1 = Atom(true);
Atom aNumber1 = Atom(2.5);
Atom aSymbol1 = Atom(std::string("Test"));
Atom aPoint1 = Atom(makePoint(1, 2));
Atom aLine1 = Atom(makeLine(makePoint(0, 0), makePoint(5, 5)));
Atom aArc1 = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1));
Atom aNone2 = Atom();
Atom aBool2 = Atom(true);
Atom aNumber2 = Atom(2.5);
Atom aSymbol2 = Atom(std::string("Test"));
Atom aPoint2 = Atom(makePoint(1, 2));
Atom aLine2 = Atom(makeLine(makePoint(0, 0), makePoint(5, 5)));
Atom aArc2 = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1));
Atom aNone3 = Atom();
Atom aBool3 = Atom(false);
Atom aNumber3 = Atom(5.3);
Atom aSymbol3 = Atom(std::string("Not Test"));
Atom aPoint3 = Atom(makePoint(2, 1));
Atom aLine3 = Atom(makeLine(makePoint(1, 1), makePoint(5, 5)));
Atom aArc3 = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 2));
REQUIRE(aNone1 == aNone2);
REQUIRE(aNone1 == aNone3);
REQUIRE(aBool1 == aBool2);
REQUIRE(aBool1 != aBool3);
REQUIRE(aNumber1 == aNumber2);
REQUIRE(aNumber1 != aNumber3);
REQUIRE(aSymbol1 == aSymbol2);
REQUIRE(aSymbol1 != aSymbol3);
REQUIRE(aPoint1 == aPoint2);
REQUIRE(aPoint1 != aPoint3);
REQUIRE(aLine1 == aLine2);
REQUIRE(aLine1 != aLine3);
REQUIRE(aArc1 == aArc2);
REQUIRE(aArc1 != aArc3);
}
TEST_CASE("Tests Atom equality across types", "[atom]") {
Atom aNone1 = Atom();
Atom aBool1 = Atom(true);
Atom aNumber1 = Atom(2.5);
Atom aSymbol1 = Atom(std::string("Test"));
Atom aPoint1 = Atom(makePoint(1, 2));
Atom aLine1 = Atom(makeLine(makePoint(0, 0), makePoint(5, 5)));
Atom aArc1 = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1));
REQUIRE(aNone1 != aBool1);
REQUIRE(aNone1 != aNumber1);
REQUIRE(aNone1 != aSymbol1);
REQUIRE(aNone1 != aPoint1);
REQUIRE(aNone1 != aLine1);
REQUIRE(aNone1 != aArc1);
REQUIRE(aBool1 != aNone1);
REQUIRE(aBool1 != aNumber1);
REQUIRE(aBool1 != aSymbol1);
REQUIRE(aBool1 != aPoint1);
REQUIRE(aBool1 != aLine1);
REQUIRE(aBool1 != aArc1);
REQUIRE(aNumber1 != aNone1);
REQUIRE(aNumber1 != aBool1);
REQUIRE(aNumber1 != aSymbol1);
REQUIRE(aNumber1 != aPoint1);
REQUIRE(aNumber1 != aLine1);
REQUIRE(aNumber1 != aArc1);
REQUIRE(aSymbol1 != aNone1);
REQUIRE(aSymbol1 != aBool1);
REQUIRE(aSymbol1 != aNumber1);
REQUIRE(aSymbol1 != aPoint1);
REQUIRE(aSymbol1 != aLine1);
REQUIRE(aSymbol1 != aArc1);
REQUIRE(aPoint1 != aNone1);
REQUIRE(aPoint1 != aBool1);
REQUIRE(aPoint1 != aNumber1);
REQUIRE(aPoint1 != aSymbol1);
REQUIRE(aPoint1 != aLine1);
REQUIRE(aPoint1 != aArc1);
REQUIRE(aLine1 != aNone1);
REQUIRE(aLine1 != aBool1);
REQUIRE(aLine1 != aNumber1);
REQUIRE(aLine1 != aSymbol1);
REQUIRE(aLine1 != aPoint1);
REQUIRE(aLine1 != aArc1);
REQUIRE(aArc1 != aNone1);
REQUIRE(aArc1 != aBool1);
REQUIRE(aArc1 != aNumber1);
REQUIRE(aArc1 != aSymbol1);
REQUIRE(aArc1 != aPoint1);
REQUIRE(aArc1 != aLine1);
}
TEST_CASE("Tests exception throwing for invalid access on Atoms", "[atom]") {
Atom aNone = Atom();
Atom aBool = Atom(true);
Atom aNumber = Atom(2.5);
Atom aSymbol = Atom(std::string("Test"));
Atom aPoint = Atom(makePoint(1, 2));
Atom aLine = Atom(makeLine(makePoint(0, 0), makePoint(5, 5)));
Atom aArc = Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1));
REQUIRE_THROWS_AS(aNone.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aNone.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aNone.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aNone.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aNone.getLine(), std::logic_error);
REQUIRE_THROWS_AS(aNone.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aBool.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aBool.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aBool.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aBool.getLine(), std::logic_error);
REQUIRE_THROWS_AS(aBool.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aNumber.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aNumber.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aNumber.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aNumber.getLine(), std::logic_error);
REQUIRE_THROWS_AS(aNumber.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aSymbol.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aSymbol.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aSymbol.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aSymbol.getLine(), std::logic_error);
REQUIRE_THROWS_AS(aSymbol.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aPoint.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aPoint.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aPoint.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aPoint.getLine(), std::logic_error);
REQUIRE_THROWS_AS(aPoint.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aLine.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aLine.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aLine.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aLine.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aLine.getArc(), std::logic_error);
REQUIRE_THROWS_AS(aArc.getBool(), std::logic_error);
REQUIRE_THROWS_AS(aArc.getNumber(), std::logic_error);
REQUIRE_THROWS_AS(aArc.getSymbol(), std::logic_error);
REQUIRE_THROWS_AS(aArc.getPoint(), std::logic_error);
REQUIRE_THROWS_AS(aArc.getLine(), std::logic_error);
}