-
Notifications
You must be signed in to change notification settings - Fork 0
/
catch_test.cpp
103 lines (76 loc) · 2.62 KB
/
catch_test.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
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_FAST_COMPILE // for fast compilation
#include <catch2/catch_test_macros.hpp>
#include "filter.h"
#include "fileHelper.h"
using namespace std;
// Helper Methods
bool equality_test(const unsigned char *img_1, const unsigned char *img_2, int size){
bool equality = true;
if(img_1 != nullptr && img_2 != nullptr){
for (int i=0; i < size; i++) {
if (abs(*(img_1+i) - *(img_2+i)) > 2) { // Prevention of rounding errors
equality = false;
}
}
}else{
equality = false;
}
return equality;
}
// TESTCASES
TEST_CASE("Read image data from .ppm file") {
char input[] = "../img/test_img.ppm";
int width, height;
auto img = read(input, &width, &height);
REQUIRE(img != nullptr);
}
TEST_CASE("Write image data to .ppm file") {
char input[] = "../img/test_img.ppm";
char output[] = "../img/test_write.ppm";
int width, height;
auto img = read(input, &width, &height);
write(output, img, width, height);
auto img_write = read(output, &width, &height);
remove(output);
bool equality = equality_test(img, img_write, (width*height*3));
delete[] img;
delete[] img_write;
REQUIRE(equality);
}
TEST_CASE("Filter - Gauss") {
char input[] = "../img/test_img.ppm";
char correct[] = "../img/test_gauss.ppm";
int width, height;
auto img_in = read(input, &width, &height);
img_in = gauss(img_in, width, height, 3);
auto img_correct = read(correct, &width, &height);
bool equality = equality_test(img_in, img_correct, (width*height*3));
delete[] img_in;
delete[] img_correct;
REQUIRE(equality);
}
TEST_CASE("Filter - Threshold mean") {
char input[] = "../img/test_img.ppm";
char correct[] = "../img/test_thresholdmean.ppm";
int width, height;
auto img_in = read(input, &width, &height);
img_in = mean_threshold(img_in, width, height, 10, 6 , 0);
auto img_correct = read(correct, &width, &height);
bool equality = equality_test(img_in, img_correct, (width*height*3));
delete[] img_in;
delete[] img_correct;
REQUIRE(equality);
}
TEST_CASE("Filter - Threshold mean - text mode") {
char input[] = "../img/test_img.ppm";
char correct[] = "../img/test_thresholdmean_txtmode.ppm";
int width, height;
auto img_in = read(input, &width, &height);
img_in = mean_threshold(img_in, width, height, 10, 6 , 1);
auto img_correct = read(correct, &width, &height);
bool equality = equality_test(img_in, img_correct, (width*height*3));
delete[] img_in;
delete[] img_correct;
REQUIRE(equality);
}