GCC Code Coverage Report


Directory: ./
File: tasks/yushkova_p_hoare_sorting_simple_merging/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
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 136 times.
✗ Branch 2 not taken.
136 YushkovaPHoareSortingSimpleMergingSEQ::YushkovaPHoareSortingSimpleMergingSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
136 GetInput() = in;
16 GetOutput().clear();
17 136 }
18
19 5392 int YushkovaPHoareSortingSimpleMergingSEQ::HoarePartition(std::vector<int> &values, int left, int right) {
20 5392 int pivot = values[left + ((right - left) / 2)];
21 5392 int i = left - 1;
22 5392 int j = right + 1;
23
24 while (true) {
25 10384 ++i;
26
2/2
✓ Branch 0 taken 7016 times.
✓ Branch 1 taken 10384 times.
17400 while (values[i] < pivot) {
27 7016 ++i;
28 }
29
30 10384 --j;
31
2/2
✓ Branch 0 taken 9528 times.
✓ Branch 1 taken 10384 times.
19912 while (values[j] > pivot) {
32 9528 --j;
33 }
34
35
2/2
✓ Branch 0 taken 5392 times.
✓ Branch 1 taken 4992 times.
10384 if (i >= j) {
36 5392 return j;
37 }
38
39 std::swap(values[i], values[j]);
40 }
41 }
42
43 240 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 11024 times.
✓ Branch 1 taken 240 times.
11264 while (!ranges.empty()) {
48 auto [current_left, current_right] = ranges.top();
49 ranges.pop();
50
51
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 5392 times.
11024 if (current_left >= current_right) {
52 5632 continue;
53 }
54
55 5392 int partition_index = HoarePartition(values, current_left, current_right);
56
57
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 4792 times.
5392 if ((partition_index - current_left) > (current_right - (partition_index + 1))) {
58 ranges.emplace(current_left, partition_index);
59
1/2
✓ Branch 1 taken 600 times.
✗ Branch 2 not taken.
600 ranges.emplace(partition_index + 1, current_right);
60 } else {
61
2/4
✓ Branch 1 taken 4792 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4792 times.
✗ Branch 5 not taken.
4792 ranges.emplace(partition_index + 1, current_right);
62 ranges.emplace(current_left, partition_index);
63 }
64 }
65 240 }
66
67 128 std::vector<int> YushkovaPHoareSortingSimpleMergingSEQ::SimpleMerge(const std::vector<int> &left,
68 const std::vector<int> &right) {
69
1/2
✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
128 std::vector<int> merged;
70
1/2
✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
128 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 48 times.
✓ Branch 1 taken 3456 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 3376 times.
3504 while (left_index < left.size() && right_index < right.size()) {
76
2/2
✓ Branch 0 taken 1408 times.
✓ Branch 1 taken 1968 times.
3376 if (left[left_index] <= right[right_index]) {
77
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 merged.push_back(left[left_index++]);
78 } else {
79
1/2
✓ Branch 0 taken 1968 times.
✗ Branch 1 not taken.
1968 merged.push_back(right[right_index++]);
80 }
81 }
82
83
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 128 times.
1520 while (left_index < left.size()) {
84
1/2
✓ Branch 0 taken 1392 times.
✗ Branch 1 not taken.
1392 merged.push_back(left[left_index++]);
85 }
86
87
2/2
✓ Branch 0 taken 880 times.
✓ Branch 1 taken 128 times.
1008 while (right_index < right.size()) {
88
1/2
✓ Branch 0 taken 880 times.
✗ Branch 1 not taken.
880 merged.push_back(right[right_index++]);
89 }
90
91 128 return merged;
92 }
93
94 136 bool YushkovaPHoareSortingSimpleMergingSEQ::ValidationImpl() {
95 136 return !GetInput().empty();
96 }
97
98 136 bool YushkovaPHoareSortingSimpleMergingSEQ::PreProcessingImpl() {
99 136 GetOutput() = GetInput();
100 136 return true;
101 }
102
103
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 8 times.
136 bool YushkovaPHoareSortingSimpleMergingSEQ::RunImpl() {
104 std::vector<int> &values = GetOutput();
105
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 8 times.
136 if (values.size() <= 1) {
106 return true;
107 }
108
109 128 size_t middle = values.size() / 2;
110
1/2
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
128 std::vector<int> left(values.begin(), values.begin() + static_cast<std::ptrdiff_t>(middle));
111
3/6
✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
128 std::vector<int> right(values.begin() + static_cast<std::ptrdiff_t>(middle), values.end());
112
113
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 if (left.size() > 1) {
114
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 HoareQuickSort(left, 0, static_cast<int>(left.size()) - 1);
115 }
116
117
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8 times.
128 if (right.size() > 1) {
118
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 HoareQuickSort(right, 0, static_cast<int>(right.size()) - 1);
119 }
120
121
2/6
✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 128 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
256 values = SimpleMerge(left, right);
122 return std::ranges::is_sorted(values);
123 }
124
125
1/2
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
136 bool YushkovaPHoareSortingSimpleMergingSEQ::PostProcessingImpl() {
126
1/2
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
136 return !GetOutput().empty() && std::ranges::is_sorted(GetOutput());
127 }
128
129 } // namespace yushkova_p_hoare_sorting_simple_merging
130