-
Notifications
You must be signed in to change notification settings - Fork 0
/
testchain.cpp
207 lines (159 loc) · 4.41 KB
/
testchain.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
204
205
206
207
#define CATCH_CONFIG_MAIN
#include "cs221util/catch.hpp"
// headers from PA's main.cpp
#include "chain.h"
#include "block.h"
#include "cs221util/PNG.h"
#include <iostream>
using namespace cs221util;
using namespace std;
// chain copy constructor
TEST_CASE("chain::basic copy constructor", "[weight=1][part=chain]")
{
PNG pngin;
pngin.readFromFile("img-input/jingle-dresssmall.png");
cout << "test - build chain from other PNG" << endl;
Chain c(pngin, 32, 15);
cout << "test - call copy chain method" << endl;
Chain d(c);
PNG orig = c.render(32,15);
PNG result = d.render(32,15);
cout << "test - start to compare test case" << endl;
REQUIRE(result == orig);
}
TEST_CASE("chain::basic odd reverse", "[weight=1][part=chain]")
{
PNG img;
img.readFromFile("img-input/jingle-dresssmall.png");
int cols = 3;
int rows = 5;
Chain c(img, cols,rows);
c.reverse();
PNG res = c.render(cols,rows);
//res.writeToFile("img-soln/jdsoddreverse.png");
PNG expected;
expected.readFromFile("img-soln/jdsoddreverse.png");
REQUIRE(res == expected);
}
TEST_CASE("chain::basic even reverse", "[weight=1][part=chain]")
{
PNG img;
img.readFromFile("img-input/jingle-dresssmall.png");
int cols = 3;
int rows = 10;
Chain c(img, cols,rows);
c.reverse();
PNG res = c.render(cols,rows);
//res.writeToFile("img-soln/jdsevenreverse.png");
PNG expected; expected.readFromFile("img-soln/jdsevenreverse.png");
REQUIRE(res == expected);
}
TEST_CASE("chain::basic rotate k = 1", "[weight=1][part=chain]")
{
PNG img;
img.readFromFile("img-input/jingle-dresssmall.png");
int cols = 2;
int rows = 10;
Chain c(img, cols,rows);
c.rotate(1);
PNG res = c.render(cols,rows);
REQUIRE(res == img);
}
TEST_CASE("chain::basic rotate k = 2", "[weight=1][part=chain]")
{
PNG img;
img.readFromFile("img-input/jingle-dresssmall.png");
int cols = 2;
int rows = 4;
Chain c(img, cols,rows);
c.rotate(2);
PNG res = c.render(cols,rows);
//res.writeToFile("img-soln/jdsrotate2.png");
PNG expected; expected.readFromFile("img-soln/jdsrotate2.png");
REQUIRE(res == expected);
}
TEST_CASE("chain::long rotate k = 12", "[weight=1][part=chain]")
{
PNG img;
img.readFromFile("img-input/jingle-dresssmall.png");
int cols = 12;
int rows = 5;
Chain c(img, cols,rows);
c.rotate(12);
PNG res = c.render(cols,rows);
//res.writeToFile("img-soln/jdsrotate12.png");
PNG expected; expected.readFromFile("img-soln/jdsrotate12.png");
REQUIRE(res == expected);
}
TEST_CASE("chain::basic odd rotate k = 2", "[weight=1][part=chain]")
{
int cols = 5;
PNG img(cols, 1);
img.getPixel(0, 0)->r = 0;
img.getPixel(1, 0)->r = 10;
img.getPixel(2, 0)->r = 20;
img.getPixel(3, 0)->r = 30;
img.getPixel(4, 0)->r = 40;
Chain c(img, cols,1);
c.rotate(2);
PNG res = c.render(cols,1);
RGBAPixel *p0 = res.getPixel(0, 0);
RGBAPixel *p1 = res.getPixel(1, 0);
RGBAPixel *p2 = res.getPixel(2, 0);
RGBAPixel *p3 = res.getPixel(3, 0);
RGBAPixel *p4 = res.getPixel(4, 0);
REQUIRE(p0->r == 10);
REQUIRE(p1->r == 0);
REQUIRE(p2->r == 30);
REQUIRE(p3->r == 20);
REQUIRE(p4->r == 40);
}
//* Composite Tests
TEST_CASE("chain::mirror large even", "[weight=1][part=chain]")
{
int cols = 10;
PNG img(cols, cols);
for (int x = 0; x < cols; x++)
{
for (int y = 0; y < cols; y++)
{
img.getPixel(x, y)->r = x;
}
}
Chain c(img, cols,cols);
c.reverse();
PNG res = c.render(cols,cols);
for (int x = 0; x < cols; x++)
{
for (int y = 0; y < cols; y++)
{
int hVal = cols - 1 - x;
RGBAPixel *pr = res.getPixel(x, y);
REQUIRE(pr->r == hVal);
}
}
}
TEST_CASE("chain::mirror large odd", "[weight=1][part=chain]")
{
int cols = 15;
PNG img(cols, cols);
for (int x = 0; x < cols; x++)
{
for (int y = 0; y < cols; y++)
{
img.getPixel(x, y)->r = x;
}
}
Chain c(img, cols,cols);
c.reverse();
PNG res = c.render(cols,cols);
for (int x = 0; x < cols; x++)
{
for (int y = 0; y < cols; y++)
{
int hVal = cols - 1 - x;
RGBAPixel *pr = res.getPixel(x, y);
REQUIRE(pr->r == hVal);
}
}
}