| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "melnik_i_min_neigh_diff_vec/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <ranges> | ||
| 6 | #include <tuple> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "melnik_i_min_neigh_diff_vec/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace melnik_i_min_neigh_diff_vec { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
|
162 | MelnikIMinNeighDiffVecSEQ::MelnikIMinNeighDiffVecSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
|
162 | GetInput() = in; |
| 16 | GetOutput() = std::make_tuple(-1, -1); | ||
| 17 | 162 | } | |
| 18 | |||
| 19 | 162 | bool MelnikIMinNeighDiffVecSEQ::ValidationImpl() { | |
| 20 | 162 | return GetInput().size() >= 2; | |
| 21 | } | ||
| 22 | |||
| 23 | 162 | bool MelnikIMinNeighDiffVecSEQ::PreProcessingImpl() { | |
| 24 | 162 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 162 | bool MelnikIMinNeighDiffVecSEQ::RunImpl() { | |
| 28 | const auto &v = GetInput(); | ||
| 29 | |||
| 30 | 162 | auto iota_range = std::views::iota(size_t{0}, v.size() - 1); | |
| 31 | 50700 | auto comparator = [&](size_t i, size_t j) { | |
| 32 |
2/2✓ Branch 0 taken 50228 times.
✓ Branch 1 taken 472 times.
|
50700 | int diff_i = std::abs(v[i] - v[i + 1]); |
| 33 | 50700 | int diff_j = std::abs(v[j] - v[j + 1]); | |
| 34 |
2/2✓ Branch 0 taken 50228 times.
✓ Branch 1 taken 472 times.
|
50700 | if (diff_i == diff_j) { |
| 35 | 50228 | return i < j; | |
| 36 | } | ||
| 37 | 472 | return diff_i < diff_j; | |
| 38 | 162 | }; | |
| 39 | 162 | auto min_it = std::ranges::min_element(iota_range, comparator); | |
| 40 | 162 | int min_idx = static_cast<int>(*min_it); | |
| 41 | |||
| 42 | 162 | GetOutput() = std::make_tuple(min_idx, min_idx + 1); | |
| 43 | 162 | return true; | |
| 44 | } | ||
| 45 | |||
| 46 | 162 | bool MelnikIMinNeighDiffVecSEQ::PostProcessingImpl() { | |
| 47 | 162 | return true; | |
| 48 | } | ||
| 49 | |||
| 50 | } // namespace melnik_i_min_neigh_diff_vec | ||
| 51 |