GCC Code Coverage Report


Directory: ./
File: tasks/lifanov_k_sim_hoar_seq/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 55 56 98.2%
Functions: 8 8 100.0%
Branches: 39 62 62.9%

Line Branch Exec Source
1 #include "lifanov_k_sim_hoar_seq/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <utility>
6 #include <vector>
7
8 #include "lifanov_k_sim_hoar_seq/common/include/common.hpp"
9
10 namespace lifanov_k_sim_hoar_seq {
11
12
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 LifanovKSimpleHoarSEQ::LifanovKSimpleHoarSEQ(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
15 GetOutput() = {};
16 24 }
17
18 24 bool LifanovKSimpleHoarSEQ::ValidationImpl() {
19 24 return !GetInput().empty();
20 }
21
22 24 bool LifanovKSimpleHoarSEQ::PreProcessingImpl() {
23 24 data_ = GetInput();
24 24 return true;
25 }
26
27 872 int LifanovKSimpleHoarSEQ::Partition(std::vector<int> &arr, int low, int high) {
28 872 int mid = low + ((high - low) / 2);
29 872 int pivot = arr[mid];
30
31 872 int i = low - 1;
32 872 int j = high + 1;
33
34 while (true) {
35 2003 i++;
36
2/2
✓ Branch 0 taken 1308 times.
✓ Branch 1 taken 2003 times.
3311 while (arr[i] < pivot) {
37 1308 i++;
38 }
39
40 2003 j--;
41
2/2
✓ Branch 0 taken 1801 times.
✓ Branch 1 taken 2003 times.
3804 while (arr[j] > pivot) {
42 1801 j--;
43 }
44
45
2/2
✓ Branch 0 taken 872 times.
✓ Branch 1 taken 1131 times.
2003 if (i >= j) {
46 872 return j;
47 }
48
49 std::swap(arr[i], arr[j]);
50 }
51 }
52
53 48 void LifanovKSimpleHoarSEQ::QuickSortHoare(std::vector<int> &arr, int low, int high) {
54 48 std::vector<std::pair<int, int>> stack;
55
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 stack.emplace_back(low, high);
56
57
2/2
✓ Branch 0 taken 872 times.
✓ Branch 1 taken 48 times.
920 while (!stack.empty()) {
58 auto [l, r] = stack.back();
59 stack.pop_back();
60
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 872 times.
872 if (l >= r) {
62 continue;
63 }
64
65 872 int p = Partition(arr, l, r);
66
67
2/2
✓ Branch 0 taken 422 times.
✓ Branch 1 taken 450 times.
872 if (l < p) {
68
1/2
✓ Branch 1 taken 422 times.
✗ Branch 2 not taken.
422 stack.emplace_back(l, p);
69 }
70
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 470 times.
872 if (p + 1 < r) {
71
1/4
✓ Branch 1 taken 402 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
402 stack.emplace_back(p + 1, r);
72 }
73 }
74 48 }
75
76 24 std::vector<int> LifanovKSimpleHoarSEQ::Merge(const std::vector<int> &left, const std::vector<int> &right) {
77
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<int> res;
78
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 res.reserve(left.size() + right.size());
79
80 size_t i = 0;
81 size_t j = 0;
82
83
4/4
✓ Branch 0 taken 895 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 879 times.
903 while (i < left.size() && j < right.size()) {
84
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 450 times.
879 if (left[i] <= right[j]) {
85 res.push_back(left[i]);
86 429 i++;
87 } else {
88 res.push_back(right[j]);
89 450 j++;
90 }
91 }
92
93
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 24 times.
51 while (i < left.size()) {
94 res.push_back(left[i]);
95 27 i++;
96 }
97
98
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 24 times.
38 while (j < right.size()) {
99 res.push_back(right[j]);
100 14 j++;
101 }
102
103 24 return res;
104 }
105
106
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool LifanovKSimpleHoarSEQ::RunImpl() {
107
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (data_.size() <= 1) {
108 return true;
109 }
110
111 24 size_t mid = data_.size() / 2;
112 auto mid_it = data_.begin() + static_cast<std::ptrdiff_t>(mid);
113
114
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 std::vector<int> left_part(data_.begin(), mid_it);
115
2/6
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
24 std::vector<int> right_part(mid_it, data_.end());
116
117
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 QuickSortHoare(left_part, 0, static_cast<int>(left_part.size() - 1));
118
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 QuickSortHoare(right_part, 0, static_cast<int>(right_part.size() - 1));
119
120
2/6
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
48 data_ = Merge(left_part, right_part);
121
122 return true;
123 }
124
125 24 bool LifanovKSimpleHoarSEQ::PostProcessingImpl() {
126 24 GetOutput() = data_;
127 24 return std::is_sorted(GetOutput().begin(), GetOutput().end());
128 }
129
130 } // namespace lifanov_k_sim_hoar_seq
131