GCC Code Coverage Report


Directory: ./
File: tasks/litvyakov_d_shell_sort/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 38 38 100.0%
Functions: 8 8 100.0%
Branches: 30 42 71.4%

Line Branch Exec Source
1 #include "litvyakov_d_shell_sort/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstdint>
5 #include <cstdio>
6 #include <utility>
7 #include <vector>
8
9 #include "litvyakov_d_shell_sort/common/include/common.hpp"
10
11 namespace litvyakov_d_shell_sort {
12
13 // wikipedia realization of shell sort
14 48 void LitvyakovDShellSortSEQ::BaseShellSort(std::vector<int> &vec) {
15 auto first = vec.begin();
16 auto last = vec.end();
17
18
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 48 times.
288 for (auto dist = (last - first) / 2; dist != 0; dist /= 2) {
19
2/2
✓ Branch 0 taken 59456 times.
✓ Branch 1 taken 240 times.
59696 for (auto i = first + dist; i != last; ++i) {
20
4/4
✓ Branch 0 taken 105138 times.
✓ Branch 1 taken 4708 times.
✓ Branch 2 taken 50390 times.
✓ Branch 3 taken 54748 times.
109846 for (auto j = i; j - first >= dist && (*j < *(j - dist)); j -= dist) {
21 std::swap(*j, *(j - dist));
22 }
23 }
24 }
25 48 }
26
27
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 void LitvyakovDShellSortSEQ::Merge(std::vector<int> &left, const std::vector<int> &right, std::vector<int> &vec) {
28 vec.clear();
29 std::size_t i = 0;
30 std::size_t j = 0;
31 std::size_t left_size = left.size();
32 std::size_t right_size = right.size();
33
2/2
✓ Branch 0 taken 8837 times.
✓ Branch 1 taken 24 times.
8861 while (i < left_size && j < right_size) {
34
2/2
✓ Branch 0 taken 4419 times.
✓ Branch 1 taken 4418 times.
8837 if (left[i] <= right[j]) {
35
1/2
✓ Branch 0 taken 4419 times.
✗ Branch 1 not taken.
4419 vec.push_back(left[i++]);
36 } else {
37
1/2
✓ Branch 0 taken 4418 times.
✗ Branch 1 not taken.
4418 vec.push_back(right[j++]);
38 }
39 }
40
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 24 times.
45 while (i < left_size) {
41
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 vec.push_back(left[i++]);
42 }
43
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 24 times.
46 while (j < right_size) {
44
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 vec.push_back(right[j++]);
45 }
46 24 }
47
48
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 24 times.
32 void LitvyakovDShellSortSEQ::ShellSortMerge(std::vector<int> &vec) {
49
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 24 times.
32 if (vec.size() <= 1) {
50 8 return;
51 }
52 24 std::size_t mid = vec.size() / 2;
53
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 std::vector<int> left(vec.begin(), vec.begin() + static_cast<int64_t>(mid));
54
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> right(vec.begin() + static_cast<int64_t>(mid), vec.end());
55 24 BaseShellSort(left);
56 24 BaseShellSort(right);
57
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 Merge(left, right, vec);
58 }
59
60
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 LitvyakovDShellSortSEQ::LitvyakovDShellSortSEQ(const InType &in) {
61 SetTypeOfTask(GetStaticTypeOfTask());
62
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 GetInput() = in;
63 32 GetOutput() = std::vector<int>();
64 32 }
65
66 32 bool LitvyakovDShellSortSEQ::ValidationImpl() {
67 const InType &vec = GetInput();
68 32 return !vec.empty();
69 }
70
71 32 bool LitvyakovDShellSortSEQ::PreProcessingImpl() {
72 32 GetOutput() = GetInput();
73 32 return true;
74 }
75
76 32 bool LitvyakovDShellSortSEQ::RunImpl() {
77 std::vector<int> &vec = GetOutput();
78 32 ShellSortMerge(vec);
79 32 return true;
80 }
81
82 32 bool LitvyakovDShellSortSEQ::PostProcessingImpl() {
83 32 return true;
84 }
85
86 } // namespace litvyakov_d_shell_sort
87