-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestComp.cpp
More file actions
205 lines (162 loc) · 4.79 KB
/
testComp.cpp
File metadata and controls
205 lines (162 loc) · 4.79 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
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
204
205
#define CATCH_CONFIG_MAIN
#include "cs221util/catch.hpp"
#include <vector>
#include <sys/stat.h>
#include <iostream>
#include "cs221util/PNG.h"
#include "cs221util/RGBAPixel.h"
#include "stats.h"
#include "twoDtree.h"
using namespace std;
using namespace cs221util;
TEST_CASE("stats::basic rectArea","[weight=1][part=stats]"){
PNG data; data.resize(2,3);
stats s(data);
pair<int,int> ul(0,0);
pair<int,int> lr(1,2);
long result = s.rectArea(ul,lr);
REQUIRE(result == 6);
}
TEST_CASE("stats::basic getAvg","[weight=1][part=stats]"){
PNG data; data.resize(2,2);
for (int i = 0; i < 2; i ++){
for (int j = 0; j < 2; j++){
RGBAPixel * p = data.getPixel(i,j);
p->r = 20 * i + 3 * j;
p->g = 3 * i + 20 * j;
p->b = 23 * i + 23 * j;
p->a = 1.0;
}
}
stats s(data);
pair<int,int> ul(0,0);
pair<int,int> lr(1,1);
RGBAPixel result = s.getAvg(ul,lr);
RGBAPixel expected(11,11,23);
REQUIRE(result == expected);
}
TEST_CASE("stats::basic 1x2 getAvg (0,0)(1,0)","[weight=1][part=stats]"){
PNG data; data.resize(2,1);
for (int i = 0; i < 2; i ++){
for (int j = 0; j < 1; j++){
RGBAPixel * p = data.getPixel(i,j);
p->r = 12;
p->g = 12;
p->b = 12;
p->a = 1.0;
}
}
stats s(data);
pair<int,int> ul(0,0);
pair<int,int> lr(1,0);
cout << "area" << s.rectArea(ul, lr);
RGBAPixel result = s.getAvg(ul,lr);
cout << result.r << " " << result.g << " " << result.b;
RGBAPixel expected(13,13,13);
REQUIRE(result == expected);
}
TEST_CASE("stats::size 1x2,(1,0)(1,0) avg","[weight=1][part=stats]"){
PNG data; data.resize(2,1);
for (int i = 0; i < 2; i ++){
for (int j = 0; j < 1; j++){
RGBAPixel * p = data.getPixel(i,j);
p->r = 12;
p->g = 12;
p->b = 12;
p->a = 1.0;
}
}
stats s(data);
pair<int,int> ul(1,0);
pair<int,int> lr(1,0);
cout << "area" << s.rectArea(ul, lr);
RGBAPixel result = s.getAvg(ul,lr);
cout << result.r << " " << result.g << " " << result.b;
RGBAPixel expected(13,13,13);
REQUIRE(result == expected);
}
TEST_CASE("stats::basic variance","[weight=1][part=stats]"){
PNG data; data.resize(2,2);
for (int i = 0; i < 2; i ++){
for (int j = 0; j < 2; j++){
RGBAPixel * p = data.getPixel(i,j);
p->r = 20 * i + 3 * j;
p->g = 3 * i + 20 * j;
p->b = 23 * i + 23 * j;
p->a = 1.0;
}
}
stats s(data);
pair<int,int> ul(0,0);
pair<int,int> lr(1,1);
long result = s.getScore(ul,lr);
REQUIRE(result == 1876);
}
TEST_CASE("stats::2x2 score","[weight=1][part=stats]"){
PNG data; data.resize(2,2);
for (int i = 0; i < 2; i ++){
for (int j = 0; j < 2; j++){
RGBAPixel * p = data.getPixel(i,j);
p->r = 64;
p->g = 64;
p->b = 64;
p->a = 1.0;
}
}
stats s(data);
pair<int,int> ul(0,0);
pair<int,int> lr(1,1);
long result = s.getScore(ul,lr);
REQUIRE(result == 0);
}
TEST_CASE("twoDtree::basic ctor render","[weight=1][part=twoDtree]"){
PNG img;
img.readFromFile("images/geo.png");
twoDtree t1(img);
PNG out = t1.render();
out.writeToFile("images/rendertest_geo.png");
REQUIRE(out==img);
}
TEST_CASE("twoDtree::basic copy","[weight=1][part=twoDtree]"){
PNG img;
img.readFromFile("images/geo.png");
twoDtree t1(img);
twoDtree t1copy(t1);
PNG out = t1copy.render();
REQUIRE(out==img);
}
// TEST_CASE("twoDtree::basic prune canada","[weight=1][part=twoDtree]"){
// PNG img;
// img.readFromFile("images/canadaPlace.png");
// twoDtree t1(img);
// t1.prune(4000);
// PNG result = t1.render();
// result.writeToFile("images/out_canadaPlacePrune.png");
// }
// TEST_CASE("twoDtree::basic prune","[weight=1][part=twoDtree]"){
// PNG img;
// img.readFromFile("images/ada.png");
// twoDtree t1(img);
// t1.prune(3000);
// PNG result = t1.render();
// result.writeToFile("images/out_adaPrune.png");
// PNG expected;
// expected.readFromFile("images/given-adaPrune.png");
// REQUIRE(expected==result);
// }
TEST_CASE("twoDtree::basic pruneSize","[weight=1][part=twoDtree]"){
PNG img;
img.readFromFile("images/ada.png");
twoDtree t1(img);
int result = t1.pruneSize(3000);
int expected = 13904;
REQUIRE(expected==result);
}
TEST_CASE("twoDtree::basic idealPrune","[weight=1][part=twoDtree]"){
PNG img;
img.readFromFile("images/ada.png");
twoDtree t1(img);
int result = t1.idealPrune(13904);
int expected = 2998;
REQUIRE(expected==result);
}