-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_expression.cpp
67 lines (50 loc) · 2.17 KB
/
test_expression.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
#include "catch.hpp"
#include "expression.hpp"
TEST_CASE("Test the Expression constructors", "[expression]") {
Expression expNone = Expression();
Expression expBool = Expression(true);
Expression expNumber = Expression(2.5);
Expression expSymbol = Expression(std::string("Test"));
Expression expPoint = Expression(std::make_tuple(0., 0.));
Expression expLine = Expression(std::make_tuple(0., 0.), std::make_tuple(5., 5.));
Expression expArc = Expression(std::make_tuple(0., 0.), std::make_tuple(5., 5.), 1);
Expression expAtomBool = Expression(Atom(true));
REQUIRE(expNone.getAtom() == Atom());
REQUIRE(expNone.getChildren().empty());
REQUIRE(expBool.getAtom() == Atom(true));
REQUIRE(expBool.getChildren().empty());
REQUIRE(expNumber.getAtom() == Atom(2.5));
REQUIRE(expNumber.getChildren().empty());
REQUIRE(expSymbol.getAtom() == Atom(std::string("Test")));
REQUIRE(expSymbol.getChildren().empty());
REQUIRE(expPoint.getAtom() == Atom(makePoint(0, 0)));
REQUIRE(expPoint.getChildren().empty());
REQUIRE(expLine.getAtom() == Atom(makeLine(makePoint(0, 0), makePoint(5, 5))));
REQUIRE(expLine.getChildren().empty());
REQUIRE(expArc.getAtom() == Atom(makeArc(makePoint(0, 0), makePoint(5, 5), 1)));
REQUIRE(expAtomBool.getAtom() == Atom(true));
REQUIRE(expAtomBool.getChildren().empty());
}
TEST_CASE("Tests adding children to Expressions", "[expression]") {
Expression root = Expression(std::string("Root"));
root.appendChild(Atom(std::string("Child 1")));
REQUIRE(root.getChildren().size() == 1);
REQUIRE(root.lastChild().getAtom() == Atom(std::string("Child 1")));
root.appendChild(Expression(std::string("Child 2")));
REQUIRE(root.getChildren().size() == 2);
REQUIRE(root.lastChild().getAtom() == Atom(std::string("Child 2")));
}
TEST_CASE("Tests equality operator for Expressions", "[expression]") {
Expression a = Expression(std::string("Val"));
Expression b = Expression(std::string("Val"));
Expression c = Expression(std::string("NotVal"));
Expression d = Expression(5.9);
REQUIRE(a == b);
REQUIRE(!(a == c));
REQUIRE(!(a == d));
REQUIRE(!(c == d));
a.appendChild(Atom(std::string("Child")));
REQUIRE(!(a == b));
b.appendChild(Atom(true));
REQUIRE(a == b);
}