GCC Code Coverage Report


Directory: ./
File: tasks/votincev_d_qsort_batcher/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 38 39 97.4%
Functions: 7 7 100.0%
Branches: 22 30 73.3%

Line Branch Exec Source
1 #include "votincev_d_qsort_batcher/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <vector>
5
6 #include "votincev_d_qsort_batcher/common/include/common.hpp"
7
8 namespace votincev_d_qsort_batcher {
9
10
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 VotincevDQsortBatcherSEQ::VotincevDQsortBatcherSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
13 80 }
14
15 // входные данные — просто std::vector<double>, проверяем, что не пустой
16 80 bool VotincevDQsortBatcherSEQ::ValidationImpl() {
17 const auto &vec = GetInput();
18 80 return !vec.empty();
19 }
20
21 80 bool VotincevDQsortBatcherSEQ::PreProcessingImpl() {
22 80 return true;
23 }
24
25 80 bool VotincevDQsortBatcherSEQ::RunImpl() {
26 80 std::vector<double> data = GetInput();
27
28
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (!data.empty()) {
29
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 QuickSort(data.data(), 0, static_cast<int>(data.size()) - 1);
30 }
31
32
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetOutput() = data;
33 80 return true;
34 }
35
36 // partition (для qsort)
37 44720 int VotincevDQsortBatcherSEQ::Partition(double *arr, int l, int h) {
38 int i = l;
39 int j = h;
40 44720 double pivot = arr[(l + h) / 2];
41
42
2/2
✓ Branch 0 taken 171640 times.
✓ Branch 1 taken 44720 times.
261080 while (i <= j) {
43
2/2
✓ Branch 0 taken 101632 times.
✓ Branch 1 taken 171640 times.
273272 while (arr[i] < pivot) {
44 101632 i++;
45 }
46
2/2
✓ Branch 0 taken 100672 times.
✓ Branch 1 taken 171640 times.
272312 while (arr[j] > pivot) {
47 100672 j--;
48 }
49
50
2/2
✓ Branch 0 taken 5144 times.
✓ Branch 1 taken 166496 times.
171640 if (i <= j) {
51 std::swap(arr[i], arr[j]);
52 166496 i++;
53 166496 j--;
54 }
55 }
56 // i — это граница следующего правого подмассива
57 44720 return i;
58 }
59
60 // итеративная qsort
61 80 void VotincevDQsortBatcherSEQ::QuickSort(double *arr, int left, int right) {
62
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 std::vector<int> stack;
63
64 stack.push_back(left);
65 stack.push_back(right);
66
67
2/2
✓ Branch 0 taken 44720 times.
✓ Branch 1 taken 80 times.
44800 while (!stack.empty()) {
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44720 times.
44720 int h = stack.back();
69 stack.pop_back();
70 44720 int l = stack.back();
71 stack.pop_back();
72
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44720 times.
44720 if (l >= h) {
74 continue;
75 }
76
77 // вызываю Partition для разделения массива
78 44720 int p = Partition(arr, l, h);
79 // p - это i после Partition. j находится на p-1 или p-2.
80
81 // p - начало правого подмассива (i)
82 // j - конец левого подмассива (j после Partition)
83
84 // пересчитываю l и h для стека, используя внутренние границы Partition
85 44720 int l_end = p - 1; // конец левого подмассива
86 44720 int r_start = p; // начало правого подмассива
87
88 // если левый подмассив существует
89
2/2
✓ Branch 0 taken 25072 times.
✓ Branch 1 taken 19648 times.
44720 if (l < l_end) {
90 stack.push_back(l);
91 stack.push_back(l_end);
92 }
93
94 // если правый подмассив существует
95
2/2
✓ Branch 0 taken 19568 times.
✓ Branch 1 taken 25152 times.
44720 if (r_start < h) {
96 stack.push_back(r_start);
97 stack.push_back(h);
98 }
99 }
100 80 }
101
102 80 bool VotincevDQsortBatcherSEQ::PostProcessingImpl() {
103 80 return true;
104 }
105
106 } // namespace votincev_d_qsort_batcher
107