| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "vdovin_a_quick_sort_merge/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "vdovin_a_quick_sort_merge/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace vdovin_a_quick_sort_merge { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | VdovinAQuickSortMergeSEQ::VdovinAQuickSortMergeSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GetInput() = in; |
| 14 | GetOutput() = {}; | ||
| 15 | 112 | } | |
| 16 | |||
| 17 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | bool VdovinAQuickSortMergeSEQ::ValidationImpl() { |
| 18 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (!GetOutput().empty()) { |
| 19 | return false; | ||
| 20 | } | ||
| 21 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (GetInput().size() > 1000000) { |
| 22 | return false; | ||
| 23 | } | ||
| 24 |
7/14✗ Branch 0 not taken.
✓ Branch 1 taken 100408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100408 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 100408 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 100408 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 48 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 88 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 96 times.
|
100752 | return std::all_of(GetInput().begin(), GetInput().end(), [](int val) { return val >= -1000000 && val <= 1000000; }); |
| 25 | } | ||
| 26 | |||
| 27 | 112 | bool VdovinAQuickSortMergeSEQ::PreProcessingImpl() { | |
| 28 | 112 | GetOutput() = GetInput(); | |
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
|
112 | if (GetOutput().size() != GetInput().size()) { |
| 30 | return false; | ||
| 31 | } | ||
| 32 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 8 times.
|
112 | if (!GetOutput().empty()) { |
| 33 |
2/2✓ Branch 0 taken 401864 times.
✓ Branch 1 taken 104 times.
|
401968 | for (size_t i = 0; i < GetOutput().size(); i++) { |
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 401864 times.
|
401864 | if (GetOutput()[i] != GetInput()[i]) { |
| 35 | return false; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | return true; | ||
| 40 | } | ||
| 41 | |||
| 42 | namespace { | ||
| 43 | |||
| 44 | // NOLINTNEXTLINE(misc-no-recursion) | ||
| 45 | 355128 | void QuickSort(std::vector<int> &arr, int left, int right) { | |
| 46 |
2/2✓ Branch 0 taken 355128 times.
✓ Branch 1 taken 354936 times.
|
710064 | if (left >= right) { |
| 47 | return; | ||
| 48 | } | ||
| 49 | 354936 | int pivot = arr[(left + right) / 2]; | |
| 50 | int i = left; | ||
| 51 | int j = right; | ||
| 52 |
2/2✓ Branch 0 taken 1581568 times.
✓ Branch 1 taken 354936 times.
|
2291440 | while (i <= j) { |
| 53 |
2/2✓ Branch 0 taken 2181152 times.
✓ Branch 1 taken 1581568 times.
|
3762720 | while (arr[i] < pivot) { |
| 54 | 2181152 | i++; | |
| 55 | } | ||
| 56 |
2/2✓ Branch 0 taken 2563992 times.
✓ Branch 1 taken 1581568 times.
|
4145560 | while (arr[j] > pivot) { |
| 57 | 2563992 | j--; | |
| 58 | } | ||
| 59 |
2/2✓ Branch 0 taken 1472504 times.
✓ Branch 1 taken 109064 times.
|
1581568 | if (i <= j) { |
| 60 | std::swap(arr[i], arr[j]); | ||
| 61 | 1472504 | i++; | |
| 62 | 1472504 | j--; | |
| 63 | } | ||
| 64 | } | ||
| 65 | 354936 | QuickSort(arr, left, j); | |
| 66 | QuickSort(arr, i, right); | ||
| 67 | } | ||
| 68 | |||
| 69 | 96 | std::vector<int> Merge(const std::vector<int> &left, const std::vector<int> &right) { | |
| 70 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | std::vector<int> result; |
| 71 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | result.reserve(left.size() + right.size()); |
| 72 | size_t i = 0; | ||
| 73 | size_t j = 0; | ||
| 74 |
4/4✓ Branch 0 taken 401168 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 401136 times.
|
401232 | while (i < left.size() && j < right.size()) { |
| 75 |
2/2✓ Branch 0 taken 200344 times.
✓ Branch 1 taken 200792 times.
|
401136 | if (left[i] <= right[j]) { |
| 76 | result.push_back(left[i]); | ||
| 77 | 200344 | i++; | |
| 78 | } else { | ||
| 79 | result.push_back(right[j]); | ||
| 80 | 200792 | j++; | |
| 81 | } | ||
| 82 | } | ||
| 83 |
2/2✓ Branch 0 taken 560 times.
✓ Branch 1 taken 96 times.
|
656 | while (i < left.size()) { |
| 84 | result.push_back(left[i]); | ||
| 85 | 560 | i++; | |
| 86 | } | ||
| 87 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 96 times.
|
256 | while (j < right.size()) { |
| 88 | result.push_back(right[j]); | ||
| 89 | 160 | j++; | |
| 90 | } | ||
| 91 | 96 | return result; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace | ||
| 95 | |||
| 96 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 8 times.
|
112 | bool VdovinAQuickSortMergeSEQ::RunImpl() { |
| 97 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 8 times.
|
112 | if (GetOutput().empty()) { |
| 98 | return true; | ||
| 99 | } | ||
| 100 | size_t size = GetOutput().size(); | ||
| 101 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 8 times.
|
104 | if (size == 1) { |
| 102 | return true; | ||
| 103 | } | ||
| 104 | 96 | size_t mid = size / 2; | |
| 105 |
1/2✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
|
96 | std::vector<int> left(GetOutput().begin(), GetOutput().begin() + static_cast<ptrdiff_t>(mid)); |
| 106 |
1/4✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
96 | std::vector<int> right(GetOutput().begin() + static_cast<ptrdiff_t>(mid), GetOutput().end()); |
| 107 | 96 | QuickSort(left, 0, static_cast<int>(left.size()) - 1); | |
| 108 | 96 | QuickSort(right, 0, static_cast<int>(right.size()) - 1); | |
| 109 |
2/6✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
192 | GetOutput() = Merge(left, right); |
| 110 | return true; | ||
| 111 | } | ||
| 112 | |||
| 113 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 104 times.
|
112 | bool VdovinAQuickSortMergeSEQ::PostProcessingImpl() { |
| 114 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 104 times.
|
112 | if (GetOutput().empty()) { |
| 115 | 8 | return GetInput().empty(); | |
| 116 | } | ||
| 117 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (!std::is_sorted(GetOutput().begin(), GetOutput().end())) { |
| 118 | return false; | ||
| 119 | } | ||
| 120 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (GetOutput().size() != GetInput().size()) { |
| 121 | return false; | ||
| 122 | } | ||
| 123 | int sum_input = 0; | ||
| 124 | int sum_output = 0; | ||
| 125 |
2/2✓ Branch 0 taken 401864 times.
✓ Branch 1 taken 104 times.
|
401968 | for (const auto &val : GetInput()) { |
| 126 | 401864 | sum_input += val; | |
| 127 | } | ||
| 128 |
2/2✓ Branch 0 taken 401864 times.
✓ Branch 1 taken 104 times.
|
401968 | for (const auto &val : GetOutput()) { |
| 129 | 401864 | sum_output += val; | |
| 130 | } | ||
| 131 | 104 | return sum_input == sum_output; | |
| 132 | } | ||
| 133 | |||
| 134 | } // namespace vdovin_a_quick_sort_merge | ||
| 135 |