GCC Code Coverage Report


Directory: ./
File: tasks/kondakov_v_shell_sort/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 7 7 100.0%
Branches: 27 34 79.4%

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