GCC Code Coverage Report


Directory: ./
File: tasks/shkryleva_s_shell_sort_simple_merge/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 39 40 97.5%
Functions: 7 7 100.0%
Branches: 32 46 69.6%

Line Branch Exec Source
1 #include "shkryleva_s_shell_sort_simple_merge/seq/include/ops_seq.hpp"
2
3 #include <cstddef>
4 #include <vector>
5
6 #include "shkryleva_s_shell_sort_simple_merge/common/include/common.hpp"
7
8 namespace shkryleva_s_shell_sort_simple_merge {
9
10
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 ShkrylevaSShellMergeSEQ::ShkrylevaSShellMergeSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 GetInput() = in;
13 GetOutput() = {};
14 64 }
15
16 64 bool ShkrylevaSShellMergeSEQ::ValidationImpl() {
17 64 return true;
18 }
19
20 64 bool ShkrylevaSShellMergeSEQ::PreProcessingImpl() {
21 64 input_data_ = GetInput();
22 output_data_.clear();
23 64 return true;
24 }
25
26
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 void ShkrylevaSShellMergeSEQ::ShellSort(std::vector<int> &data) {
27
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 if (data.empty()) {
28 return;
29 }
30
31
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 120 times.
272 for (size_t gap = data.size() / 2; gap > 0; gap /= 2) {
32
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 152 times.
544 for (size_t i = gap; i < data.size(); ++i) {
33 392 int temp = data[i];
34 size_t j = i;
35
36
4/4
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 80 times.
✓ Branch 2 taken 136 times.
✓ Branch 3 taken 312 times.
528 while (j >= gap && data[j - gap] > temp) {
37 136 data[j] = data[j - gap];
38 j -= gap;
39 }
40
41 392 data[j] = temp;
42 }
43 }
44 }
45
46 64 std::vector<int> ShkrylevaSShellMergeSEQ::MergeSortedVectors(const std::vector<int> &left,
47 const std::vector<int> &right) {
48
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 std::vector<int> merged;
49
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 merged.reserve(left.size() + right.size());
50
51 size_t left_index = 0;
52 size_t right_index = 0;
53
54
4/4
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 248 times.
312 while (left_index < left.size() && right_index < right.size()) {
55
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 128 times.
248 if (left[left_index] <= right[right_index]) {
56 merged.push_back(left[left_index]);
57 120 ++left_index;
58 } else {
59 merged.push_back(right[right_index]);
60 128 ++right_index;
61 }
62 }
63
64
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 64 times.
120 while (left_index < left.size()) {
65 merged.push_back(left[left_index]);
66 56 ++left_index;
67 }
68
69
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 64 times.
136 while (right_index < right.size()) {
70 merged.push_back(right[right_index]);
71 72 ++right_index;
72 }
73
74 64 return merged;
75 }
76
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 bool ShkrylevaSShellMergeSEQ::RunImpl() {
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (input_data_.empty()) {
79 output_data_.clear();
80 return true;
81 }
82
83 64 const size_t middle = input_data_.size() / 2;
84
85
1/2
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
64 std::vector<int> left(input_data_.begin(), input_data_.begin() + static_cast<std::ptrdiff_t>(middle));
86
1/4
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
64 std::vector<int> right(input_data_.begin() + static_cast<std::ptrdiff_t>(middle), input_data_.end());
87
88 // 1. Сортируем каждую половину Шеллом
89 64 ShellSort(left);
90 64 ShellSort(right);
91
92 // 2. Обычное линейное слияние
93
2/6
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
128 output_data_ = MergeSortedVectors(left, right);
94
95 return true;
96 }
97
98 64 bool ShkrylevaSShellMergeSEQ::PostProcessingImpl() {
99 64 GetOutput() = output_data_;
100 64 return true;
101 }
102
103 } // namespace shkryleva_s_shell_sort_simple_merge
104