GCC Code Coverage Report


Directory: ./
File: tasks/batushin_i_incr_contrast_with_lhs/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 30 31 96.8%
Functions: 6 6 100.0%
Branches: 15 20 75.0%

Line Branch Exec Source
1 #include "batushin_i_incr_contrast_with_lhs/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <utility>
7 #include <vector>
8
9 #include "batushin_i_incr_contrast_with_lhs/common/include/common.hpp"
10
11 namespace batushin_i_incr_contrast_with_lhs {
12
13
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 BatushinITestTaskSEQ::BatushinITestTaskSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
16
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetOutput().resize(in.size());
17 80 }
18
19 80 bool BatushinITestTaskSEQ::ValidationImpl() {
20 80 return !GetInput().empty();
21 }
22
23 80 bool BatushinITestTaskSEQ::PreProcessingImpl() {
24 80 return true;
25 }
26
27 namespace {
28 unsigned char NormalizePixel(unsigned char pixel, unsigned char min_val, double scale_factor) {
29 216 double normalized = static_cast<double>(pixel - min_val) * scale_factor;
30 216 normalized = std::floor(normalized + 0.5);
31
32 normalized = std::max(normalized, 0.0);
33 normalized = std::min(normalized, 255.0);
34
35 216 return static_cast<unsigned char>(normalized);
36 }
37
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
80 std::pair<unsigned char, unsigned char> FindMinMax(const std::vector<unsigned char> &data) {
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
80 if (data.empty()) {
40 return {0, 0};
41 }
42
43 80 unsigned char minimum = data[0];
44 80 unsigned char maximum = data[0];
45
46
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 80 times.
288 for (size_t idx = 1; idx < data.size(); ++idx) {
47
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 112 times.
208 minimum = std::min(minimum, data[idx]);
48 208 maximum = std::max(maximum, data[idx]);
49 }
50
51 80 return {minimum, maximum};
52 }
53
54 void FillUniformImage(std::vector<unsigned char> &output, size_t size) {
55 32 output.assign(size, 128);
56 }
57
58 } // namespace
59
60
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 48 times.
80 bool BatushinITestTaskSEQ::RunImpl() {
61 const std::vector<unsigned char> &source = GetInput();
62 std::vector<unsigned char> &destination = GetOutput();
63
64 80 auto [min_value, max_value] = FindMinMax(source);
65
66
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 48 times.
80 if (min_value == max_value) {
67 FillUniformImage(destination, source.size());
68 32 return true;
69 }
70
71 48 const double scale_coefficient = 255.0 / static_cast<double>(max_value - min_value);
72
73 48 destination.resize(source.size());
74
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 48 times.
264 for (size_t position = 0; position < source.size(); ++position) {
75 216 destination[position] = NormalizePixel(source[position], min_value, scale_coefficient);
76 }
77
78 return true;
79 }
80
81 80 bool BatushinITestTaskSEQ::PostProcessingImpl() {
82 80 return true;
83 }
84
85 } // namespace batushin_i_incr_contrast_with_lhs
86