-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commons.hpp
48 lines (40 loc) · 1.22 KB
/
test_commons.hpp
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
#pragma once
#include <catch.hpp>
#include <cmath>
#include <string>
#include <iostream>
#include <optional>
#include <image.h>
#include <png_decoder.h>
#include <libpng_wrappers.h>
#ifndef TASK_DIR
#define TASK_DIR "."
#endif
inline std::string ConstructBasePath() {
std::string result(TASK_DIR);
return result;
}
const std::string kBasePath = ConstructBasePath();
void Compare(const Image& actual, const Image& expected) {
REQUIRE(actual.Width() == expected.Width());
REQUIRE(actual.Height() == expected.Height());
for (int y = 0; y < actual.Height(); ++y) {
for (int x = 0; x < actual.Width(); ++x) {
const auto& actual_data = actual(y, x);
const auto& expected_data = expected(y, x);
REQUIRE(actual_data == expected_data);
}
}
}
void CheckImage(
const std::string& filename,
std::optional<std::string> output_filename = std::nullopt)
{
std::cerr << "Running " << filename << "\n";
auto image = ReadPng(kBasePath + "tests/" + filename);
if (output_filename.has_value()) {
libpng::WriteImage(image, output_filename.value());
}
auto ok_image = libpng::ReadImage(kBasePath + "tests/" + filename);
Compare(image, ok_image);
}