GCC Code Coverage Report


Directory: ./
File: tasks/yushkova_p_hoare_sorting_simple_merging/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 53 53 100.0%
Functions: 8 8 100.0%
Branches: 51 74 68.9%

Line Branch Exec Source
1 #include "yushkova_p_hoare_sorting_simple_merging/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <stack>
6 #include <utility>
7 #include <vector>
8
9 #include "yushkova_p_hoare_sorting_simple_merging/common/include/common.hpp"
10
11 namespace yushkova_p_hoare_sorting_simple_merging {
12
13
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 YushkovaPHoareSortingSimpleMergingSEQ::YushkovaPHoareSortingSimpleMergingSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
16 GetOutput().clear();
17 80 }
18
19 352 int YushkovaPHoareSortingSimpleMergingSEQ::HoarePartition(std::vector<int> &values, int left, int right) {
20 352 int pivot = values[left + ((right - left) / 2)];
21 352 int i = left - 1;
22 352 int j = right + 1;
23
24 while (true) {
25 600 ++i;
26
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 600 times.
672 while (values[i] < pivot) {
27 72 ++i;
28 }
29
30 600 --j;
31
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 600 times.
832 while (values[j] > pivot) {
32 232 --j;
33 }
34
35
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 248 times.
600 if (i >= j) {
36 352 return j;
37 }
38
39 std::swap(values[i], values[j]);
40 }
41 }
42
43 128 void YushkovaPHoareSortingSimpleMergingSEQ::HoareQuickSort(std::vector<int> &values, int left, int right) {
44 std::stack<std::pair<int, int>> ranges;
45 ranges.emplace(left, right);
46
47
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 128 times.
960 while (!ranges.empty()) {
48 auto [current_left, current_right] = ranges.top();
49 ranges.pop();
50
51
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 352 times.
832 if (current_left >= current_right) {
52 480 continue;
53 }
54
55 352 int partition_index = HoarePartition(values, current_left, current_right);
56
57
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 264 times.
352 if ((partition_index - current_left) > (current_right - (partition_index + 1))) {
58 ranges.emplace(current_left, partition_index);
59
1/2
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
88 ranges.emplace(partition_index + 1, current_right);
60 } else {
61
2/4
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 264 times.
✗ Branch 5 not taken.
264 ranges.emplace(partition_index + 1, current_right);
62 ranges.emplace(current_left, partition_index);
63 }
64 }
65 128 }
66
67 72 std::vector<int> YushkovaPHoareSortingSimpleMergingSEQ::SimpleMerge(const std::vector<int> &left,
68 const std::vector<int> &right) {
69
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 std::vector<int> merged;
70
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 merged.reserve(left.size() + right.size());
71
72 size_t left_index = 0;
73 size_t right_index = 0;
74
75
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 416 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 360 times.
432 while (left_index < left.size() && right_index < right.size()) {
76
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 232 times.
360 if (left[left_index] <= right[right_index]) {
77
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 merged.push_back(left[left_index++]);
78 } else {
79
1/2
✓ Branch 0 taken 232 times.
✗ Branch 1 not taken.
232 merged.push_back(right[right_index++]);
80 }
81 }
82
83
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 72 times.
176 while (left_index < left.size()) {
84
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 merged.push_back(left[left_index++]);
85 }
86
87
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 72 times.
104 while (right_index < right.size()) {
88
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 merged.push_back(right[right_index++]);
89 }
90
91 72 return merged;
92 }
93
94 80 bool YushkovaPHoareSortingSimpleMergingSEQ::ValidationImpl() {
95 80 return !GetInput().empty();
96 }
97
98 80 bool YushkovaPHoareSortingSimpleMergingSEQ::PreProcessingImpl() {
99 80 GetOutput() = GetInput();
100 80 return true;
101 }
102
103
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 bool YushkovaPHoareSortingSimpleMergingSEQ::RunImpl() {
104 std::vector<int> &values = GetOutput();
105
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 if (values.size() <= 1) {
106 return true;
107 }
108
109 72 size_t middle = values.size() / 2;
110
1/2
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 std::vector<int> left(values.begin(), values.begin() + static_cast<std::ptrdiff_t>(middle));
111
3/6
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
72 std::vector<int> right(values.begin() + static_cast<std::ptrdiff_t>(middle), values.end());
112
113
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
72 if (left.size() > 1) {
114
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 HoareQuickSort(left, 0, static_cast<int>(left.size()) - 1);
115 }
116
117
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
72 if (right.size() > 1) {
118
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 HoareQuickSort(right, 0, static_cast<int>(right.size()) - 1);
119 }
120
121
2/6
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
144 values = SimpleMerge(left, right);
122 return std::ranges::is_sorted(values);
123 }
124
125
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 bool YushkovaPHoareSortingSimpleMergingSEQ::PostProcessingImpl() {
126
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 return !GetOutput().empty() && std::ranges::is_sorted(GetOutput());
127 }
128
129 } // namespace yushkova_p_hoare_sorting_simple_merging
130