GCC Code Coverage Report


Directory: ./
File: tasks/shelenkova_m_shell_sort_simple_merge/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 7 7 100.0%
Branches: 31 38 81.6%

Line Branch Exec Source
1 #include "shelenkova_m_shell_sort_simple_merge/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <vector>
6
7 #include "shelenkova_m_shell_sort_simple_merge/common/include/common.hpp"
8
9 namespace shelenkova_m_shell_sort_simple_merge {
10
11 namespace {
12
13
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 16 times.
184 void ShellSort(std::vector<int> &data) {
14 const size_t n = data.size();
15
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 16 times.
184 if (n <= 1) {
16 return;
17 }
18
19
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 168 times.
384 for (size_t gap = n / 2; gap > 0; gap /= 2) {
20
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 216 times.
692 for (size_t i = gap; i < n; ++i) {
21 476 int temp = data[i];
22 size_t j = i;
23
4/4
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 304 times.
✓ Branch 3 taken 284 times.
780 while (j >= gap && data[j - gap] > temp) {
24 304 data[j] = data[j - gap];
25 j -= gap;
26 }
27 476 data[j] = temp;
28 }
29 }
30 }
31
32 92 void SimpleMerge(const std::vector<int> &left, const std::vector<int> &right, std::vector<int> &result) {
33 size_t left_idx = 0;
34 size_t right_idx = 0;
35 size_t res_idx = 0;
36
37
4/4
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 364 times.
456 while (left_idx < left.size() && right_idx < right.size()) {
38
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 222 times.
364 if (left[left_idx] <= right[right_idx]) {
39 142 result[res_idx++] = left[left_idx++];
40 } else {
41 222 result[res_idx++] = right[right_idx++];
42 }
43 }
44
45
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 92 times.
190 while (left_idx < left.size()) {
46 98 result[res_idx++] = left[left_idx++];
47 }
48
49
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 92 times.
170 while (right_idx < right.size()) {
50 78 result[res_idx++] = right[right_idx++];
51 }
52 92 }
53
54 } // namespace
55
56
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 ShelenkovaMShellSortSimpleMergeSEQ::ShelenkovaMShellSortSimpleMergeSEQ(const InType &in) {
57 SetTypeOfTask(GetStaticTypeOfTask());
58
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 GetInput() = in;
59
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 GetOutput() = in;
60 100 }
61
62 100 bool ShelenkovaMShellSortSimpleMergeSEQ::ValidationImpl() {
63 100 return !GetInput().empty();
64 }
65
66 100 bool ShelenkovaMShellSortSimpleMergeSEQ::PreProcessingImpl() {
67 100 GetOutput() = GetInput();
68 100 return true;
69 }
70
71
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 8 times.
100 bool ShelenkovaMShellSortSimpleMergeSEQ::RunImpl() {
72 std::vector<int> &data = GetOutput();
73
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 8 times.
100 if (data.size() <= 1) {
74 return true;
75 }
76
77 92 const size_t mid = data.size() / 2;
78
1/2
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
92 std::vector<int> left(data.begin(), data.begin() + static_cast<std::ptrdiff_t>(mid));
79
1/4
✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
92 std::vector<int> right(data.begin() + static_cast<std::ptrdiff_t>(mid), data.end());
80
81 92 ShellSort(left);
82 92 ShellSort(right);
83 92 SimpleMerge(left, right, data);
84
85 return std::ranges::is_sorted(data);
86 }
87
88 100 bool ShelenkovaMShellSortSimpleMergeSEQ::PostProcessingImpl() {
89 100 return !GetOutput().empty();
90 }
91
92 } // namespace shelenkova_m_shell_sort_simple_merge
93