-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_environment.cpp
158 lines (118 loc) · 4.27 KB
/
test_environment.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
// File: test_environment.cpp
// Author: Samuel McFalls
#include "catch.hpp"
#include "environment.hpp"
TEST_CASE("Tests the Environment constructor pt1", "[environment]") {
Environment env;
EnvEntry result;
EnvEntry::fptrBool notFptr = notProc;
EnvEntry::fptrBool andFptr = andProc;
EnvEntry::fptrBool orFptr = orProc;
EnvEntry::fptrBool ltFptr = ltProc;
EnvEntry::fptrBool lteFptr = lteProc;
EnvEntry::fptrBool gtFptr = gtProc;
EnvEntry::fptrBool gteFptr = gteProc;
REQUIRE(env.exists("pi"));
result = env.fetch("pi");
REQUIRE(result.getType() == EnvEntry::Type::NUMBER);
REQUIRE(result.getNumber() == atan2(0, -1));
REQUIRE(env.exists("not"));
result = env.fetch("not");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == notFptr);
REQUIRE(env.exists("and"));
result = env.fetch("and");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == andFptr);
REQUIRE(env.exists("or"));
result = env.fetch("or");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == orFptr);
REQUIRE(env.exists("<"));
result = env.fetch("<");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == ltFptr);
REQUIRE(env.exists("<="));
result = env.fetch("<=");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == lteFptr);
REQUIRE(env.exists(">"));
result = env.fetch(">");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == gtFptr);
REQUIRE(env.exists(">="));
result = env.fetch(">=");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == gteFptr);
}
TEST_CASE("Tests the Environment constructor pt2", "[environment]") {
Environment env;
EnvEntry result;
EnvEntry::fptrBool equalFptr = equalProc;
EnvEntry::fptrNumber sumFptr = sumProc;
EnvEntry::fptrNumber subFptr = subProc;
EnvEntry::fptrNumber multFptr = multProc;
EnvEntry::fptrNumber divFptr = divProc;
REQUIRE(env.exists("="));
result = env.fetch("=");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
REQUIRE(result.getFptrBool() == equalFptr);
REQUIRE(env.exists("+"));
result = env.fetch("+");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_NUMBER);
REQUIRE(result.getFptrNumber() == sumFptr);
REQUIRE(env.exists("-"));
result = env.fetch("-");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_NUMBER);
REQUIRE(result.getFptrNumber() == subFptr);
REQUIRE(env.exists("*"));
result = env.fetch("*");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_NUMBER);
REQUIRE(result.getFptrNumber() == multFptr);
REQUIRE(env.exists("/"));
result = env.fetch("/");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_NUMBER);
REQUIRE(result.getFptrNumber() == divFptr);
}
TEST_CASE("Test valid defining and fetching in the Environment", "[environment]") {
Environment env;
EnvEntry entry;
EnvEntry result;
entry = EnvEntry(true);
REQUIRE_NOTHROW(env.define("Bool", entry));
entry = EnvEntry(117.6);
REQUIRE_NOTHROW(env.define("Number", entry));
EnvEntry::fptrBool fBool = notProc;
entry = EnvEntry(fBool);
REQUIRE_NOTHROW(env.define("FBool", entry));
EnvEntry::fptrNumber fNumber = sumProc;
entry = EnvEntry(fNumber);
REQUIRE_NOTHROW(env.define("FNumber", entry));
REQUIRE_NOTHROW(env.fetch("Bool"));
result = env.fetch("Bool");
REQUIRE(result.getType() == EnvEntry::Type::BOOL);
REQUIRE(result.getBool());
REQUIRE_NOTHROW(env.fetch("Number"));
result = env.fetch("Number");
REQUIRE(result.getType() == EnvEntry::Type::NUMBER);
REQUIRE(result.getNumber() == 117.6);
REQUIRE_NOTHROW(env.fetch("FBool"));
result = env.fetch("FBool");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_BOOL);
//REQUIRE(result.getFptrBool() == fBool);
REQUIRE_NOTHROW(env.fetch("FNumber"));
result = env.fetch("FNumber");
REQUIRE(result.getType() == EnvEntry::Type::FPTR_NUMBER);
//REQUIRE(result.getFptrNumber() == fNumber);
}
TEST_CASE("Test invalid defining and fetching in the Environment", "[environment]") {
Environment env;
EnvEntry entry;
EnvEntry result;
entry = EnvEntry(true);
REQUIRE_NOTHROW(env.define("Bool", entry));
REQUIRE_THROWS(env.define("Bool", entry));
REQUIRE_NOTHROW(env.fetch("Bool"));
REQUIRE(!env.exists("DNE"));
REQUIRE_THROWS(env.fetch("DNE"));
}