1 #include <gtest/gtest.h>
3 #include "../src/rescale.hpp"
15 std::vector<uint16_t> in(1ul << 16);
16 std::iota(std::begin(in), std::end(in),
17 std::numeric_limits<uint16_t>::min());
18 std::vector<uint8_t> expected(in.size());
19 std::vector<uint8_t> result(in.size());
21 for (
size_t i = 0; i < in.size(); i += 8) {
23 for (
size_t j = 0; j < 8; ++j) {
24 expected[i + j] = in[i + j] / 256;
27 EXPECT_EQ(result, expected);
31 std::vector<uint16_t> in(1ul << 16);
32 std::iota(std::begin(in), std::end(in),
33 std::numeric_limits<uint16_t>::min());
34 std::vector<uint8_t> expected(in.size());
35 std::vector<uint8_t> result(in.size());
37 for (
size_t i = 0; i < in.size(); i += 8) {
39 for (
size_t j = 0; j < 8; ++j) {
40 expected[i + j] = std::round(in[i + j] / 256.);
43 EXPECT_EQ(result, expected);
47 std::vector<uint16_t> in(1ul << 16);
48 std::iota(std::begin(in), std::end(in),
49 std::numeric_limits<uint16_t>::min());
50 std::vector<uint8_t> expected(in.size());
51 std::vector<uint8_t> result(in.size());
53 for (
size_t i = 0; i < in.size(); i += 8) {
55 for (
size_t j = 0; j < 8; ++j) {
56 expected[i + j] = in[i + j] / 255;
59 EXPECT_EQ(result, expected);
63 std::vector<uint16_t> in((1ul << 16) - 128);
64 std::iota(std::begin(in), std::end(in),
65 std::numeric_limits<uint16_t>::min());
66 std::vector<uint8_t> expected(in.size());
67 std::vector<uint8_t> result(in.size());
69 for (
size_t i = 0; i < in.size(); i += 8) {
71 for (
size_t j = 0; j < 8; ++j) {
72 expected[i + j] = std::round(in[i + j] / 255.);
75 EXPECT_EQ(result, expected);
79 std::vector<uint16_t> in(1ul << 16);
80 std::iota(std::begin(in), std::end(in),
81 std::numeric_limits<uint16_t>::min());
82 std::vector<uint8_t> expected(in.size());
83 std::vector<uint8_t> result(in.size());
85 for (
size_t i = 0; i < in.size(); i += 8) {
87 for (
size_t j = 0; j < 8; ++j) {
88 expected[i + j] = std::round(in[i + j] / 255.);
91 std::vector<int8_t> differences(in.size());
92 std::transform(std::begin(expected), std::end(expected), std::begin(result),
93 differences.begin(), std::minus<>());
94 auto errors = std::count_if(differences.begin(), differences.end(),
95 [](int8_t d) { return d != 0; });
96 EXPECT_LE(errors, 127);
97 EXPECT_LE(*std::max_element(differences.begin(), differences.end()), 0);
98 EXPECT_GE(*std::min_element(differences.begin(), differences.end()), -1);
104 std::vector<uint16_t> in(1ul << 16);
105 std::iota(std::begin(in), std::end(in),
106 std::numeric_limits<uint16_t>::min());
107 std::vector<uint8_t> expected(in.size());
108 std::vector<uint8_t> result(in.size());
110 for (
size_t i = 0; i < in.size(); i += 1) {
112 expected[i] = in[i] / 256;
114 EXPECT_EQ(result, expected);
118 std::vector<uint16_t> in((1ul << 16) - 128);
119 std::iota(std::begin(in), std::end(in),
120 std::numeric_limits<uint16_t>::min());
121 std::vector<uint8_t> expected(in.size());
122 std::vector<uint8_t> result(in.size());
124 for (
size_t i = 0; i < in.size(); i += 1) {
126 expected[i] = std::round(in[i] / 256.);
128 EXPECT_EQ(result, expected);
132 std::vector<uint16_t> in(1ul << 16);
133 std::iota(std::begin(in), std::end(in),
134 std::numeric_limits<uint16_t>::min());
135 std::vector<uint8_t> expected(in.size());
136 std::vector<uint8_t> result(in.size());
138 for (
size_t i = 0; i < in.size(); i += 1) {
140 expected[i] = in[i] / 255;
142 EXPECT_EQ(result, expected);
146 std::vector<uint16_t> in((1ul << 16) - 128);
147 std::iota(std::begin(in), std::end(in),
148 std::numeric_limits<uint16_t>::min());
149 std::vector<uint8_t> expected(in.size());
150 std::vector<uint8_t> result(in.size());
152 for (
size_t i = 0; i < in.size(); i += 1) {
154 expected[i] = std::round(in[i] / 255.);
156 EXPECT_EQ(result, expected);
160 std::vector<uint16_t> in((1ul << 16) - 128);
161 std::iota(std::begin(in), std::end(in),
162 std::numeric_limits<uint16_t>::min());
163 std::vector<uint8_t> expected(in.size());
164 std::vector<uint8_t> result(in.size());
166 for (
size_t i = 0; i < in.size(); i += 1) {
168 expected[i] = std::round(in[i] / 255.);
170 std::vector<int8_t> differences(in.size());
171 std::transform(std::begin(expected), std::end(expected), std::begin(result),
172 differences.begin(), std::minus<>());
173 auto errors = std::count_if(differences.begin(), differences.end(),
174 [](int8_t d) { return d != 0; });
175 EXPECT_LE(errors, 127);
176 EXPECT_LE(*std::max_element(differences.begin(), differences.end()), 0);
177 EXPECT_GE(*std::min_element(differences.begin(), differences.end()), -1);