GCC Code Coverage Report


Directory: ./
File: tasks/gaivoronskiy_m_marking_binary_components/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 6 6 100.0%
Branches: 30 36 83.3%

Line Branch Exec Source
1 #include "gaivoronskiy_m_marking_binary_components/seq/include/ops_seq.hpp"
2
3 #include <array>
4 #include <cstddef>
5 #include <queue>
6 #include <utility>
7 #include <vector>
8
9 #include "gaivoronskiy_m_marking_binary_components/common/include/common.hpp"
10
11 namespace gaivoronskiy_m_marking_binary_components {
12
13
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
44 GaivoronskiyMMarkingBinaryComponentsSEQ::GaivoronskiyMMarkingBinaryComponentsSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
44 GetInput() = in;
16 GetOutput() = {};
17 44 }
18
19
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 bool GaivoronskiyMMarkingBinaryComponentsSEQ::ValidationImpl() {
20 const auto &input = GetInput();
21
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if (input.size() < 2) {
22 return false;
23 }
24 44 int rows = input[0];
25 44 int cols = input[1];
26
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if (rows <= 0 || cols <= 0) {
27 return false;
28 }
29 44 return static_cast<int>(input.size()) == (rows * cols) + 2;
30 }
31
32 44 bool GaivoronskiyMMarkingBinaryComponentsSEQ::PreProcessingImpl() {
33 const auto &input = GetInput();
34 44 int rows = input[0];
35 44 int cols = input[1];
36 44 GetOutput().assign((static_cast<std::size_t>(rows) * static_cast<std::size_t>(cols)) + 2, 0);
37 44 GetOutput()[0] = rows;
38 44 GetOutput()[1] = cols;
39 44 return true;
40 }
41
42 namespace {
43
44 66 void BfsLabel(const InType &input, OutType &output, int rows, int cols, int start_row, int start_col, int label) {
45 static constexpr std::array<int, 4> kDx = {-1, 1, 0, 0};
46 static constexpr std::array<int, 4> kDy = {0, 0, -1, 1};
47
48 std::queue<std::pair<int, int>> queue;
49 queue.emplace(start_row, start_col);
50 66 output[(start_row * cols) + start_col + 2] = label;
51
52
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 66 times.
234 while (!queue.empty()) {
53 auto [cx, cy] = queue.front();
54 queue.pop();
55
56
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 168 times.
840 for (std::size_t dir = 0; dir < 4; dir++) {
57 672 int nx = cx + kDx.at(dir);
58 672 int ny = cy + kDy.at(dir);
59
8/8
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 512 times.
✓ Branch 3 taken 76 times.
✓ Branch 4 taken 436 times.
✓ Branch 5 taken 76 times.
✓ Branch 6 taken 384 times.
✓ Branch 7 taken 52 times.
672 if (nx >= 0 && nx < rows && ny >= 0 && ny < cols) {
60 384 int nidx = (nx * cols) + ny + 2;
61
4/4
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 102 times.
✓ Branch 3 taken 122 times.
384 if (input[nidx] == 0 && output[nidx] == 0) {
62
1/2
✓ Branch 1 taken 102 times.
✗ Branch 2 not taken.
102 output[nidx] = label;
63 queue.emplace(nx, ny);
64 }
65 }
66 }
67 }
68 66 }
69
70 } // namespace
71
72 44 bool GaivoronskiyMMarkingBinaryComponentsSEQ::RunImpl() {
73 const auto &input = GetInput();
74 auto &output = GetOutput();
75 44 int rows = input[0];
76 44 int cols = input[1];
77
78 int label = 0;
79
80
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 44 times.
156 for (int i = 0; i < rows; i++) {
81
2/2
✓ Branch 0 taken 340 times.
✓ Branch 1 taken 112 times.
452 for (int j = 0; j < cols; j++) {
82 340 int idx = (i * cols) + j + 2;
83
4/4
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 172 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 102 times.
340 if (input[idx] == 0 && output[idx] == 0) {
84 66 label++;
85 66 BfsLabel(input, output, rows, cols, i, j, label);
86 }
87 }
88 }
89
90 44 return true;
91 }
92
93 44 bool GaivoronskiyMMarkingBinaryComponentsSEQ::PostProcessingImpl() {
94 44 return true;
95 }
96
97 } // namespace gaivoronskiy_m_marking_binary_components
98