GCC Code Coverage Report


Directory: ./
File: tasks/olesnitskiy_v_hoare_sort_simple_merge/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 7 7 100.0%
Branches: 23 30 76.7%

Line Branch Exec Source
1 #include "olesnitskiy_v_hoare_sort_simple_merge/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <stack>
5 #include <utility>
6 #include <vector>
7
8 #include "olesnitskiy_v_hoare_sort_simple_merge/common/include/common.hpp"
9
10 namespace olesnitskiy_v_hoare_sort_simple_merge {
11
12
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 OlesnitskiyVHoareSortSimpleMergeSEQ::OlesnitskiyVHoareSortSimpleMergeSEQ(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 GetInput() = in;
15 GetOutput().clear();
16 120 }
17
18 1648 int OlesnitskiyVHoareSortSimpleMergeSEQ::HoarePartition(std::vector<int> &values, int left, int right) {
19 1648 const int pivot = values[left + ((right - left) / 2)];
20 1648 int i = left - 1;
21 1648 int j = right + 1;
22
23 while (true) {
24 4040 ++i;
25
2/2
✓ Branch 0 taken 1192 times.
✓ Branch 1 taken 4040 times.
5232 while (values[i] < pivot) {
26 1192 ++i;
27 }
28
29 4040 --j;
30
2/2
✓ Branch 0 taken 1976 times.
✓ Branch 1 taken 4040 times.
6016 while (values[j] > pivot) {
31 1976 --j;
32 }
33
34
2/2
✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 2392 times.
4040 if (i >= j) {
35 1648 return j;
36 }
37
38 std::swap(values[i], values[j]);
39 }
40 }
41
42 112 void OlesnitskiyVHoareSortSimpleMergeSEQ::HoareQuickSort(std::vector<int> &values, int left, int right) {
43 std::stack<std::pair<int, int>> ranges;
44 ranges.emplace(left, right);
45
46
2/2
✓ Branch 0 taken 3408 times.
✓ Branch 1 taken 112 times.
3520 while (!ranges.empty()) {
47 auto [current_left, current_right] = ranges.top();
48 ranges.pop();
49
50
2/2
✓ Branch 0 taken 1760 times.
✓ Branch 1 taken 1648 times.
3408 if (current_left >= current_right) {
51 1760 continue;
52 }
53
54 1648 const int partition_index = HoarePartition(values, current_left, current_right);
55
56
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 1448 times.
1648 if ((partition_index - current_left) > (current_right - (partition_index + 1))) {
57 ranges.emplace(current_left, partition_index);
58
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
200 ranges.emplace(partition_index + 1, current_right);
59 } else {
60
2/4
✓ Branch 1 taken 1448 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1448 times.
✗ Branch 5 not taken.
1448 ranges.emplace(partition_index + 1, current_right);
61 ranges.emplace(current_left, partition_index);
62 }
63 }
64 112 }
65
66 120 bool OlesnitskiyVHoareSortSimpleMergeSEQ::ValidationImpl() {
67 120 return !GetInput().empty();
68 }
69
70 120 bool OlesnitskiyVHoareSortSimpleMergeSEQ::PreProcessingImpl() {
71 120 GetOutput() = GetInput();
72 120 return true;
73 }
74
75
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 112 times.
120 bool OlesnitskiyVHoareSortSimpleMergeSEQ::RunImpl() {
76 std::vector<int> &values = GetOutput();
77 120 const int n = static_cast<int>(values.size());
78
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 112 times.
120 if (n <= 1) {
79 return true;
80 }
81
82 112 HoareQuickSort(values, 0, n - 1);
83 return std::ranges::is_sorted(values);
84 }
85
86
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 bool OlesnitskiyVHoareSortSimpleMergeSEQ::PostProcessingImpl() {
87
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 return !GetOutput().empty() && std::ranges::is_sorted(GetOutput());
88 }
89
90 } // namespace olesnitskiy_v_hoare_sort_simple_merge
91