| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "baranov_a_sign_alternations/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "baranov_a_sign_alternations/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace baranov_a_sign_alternations { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | BaranovASignAlternationsSEQ::BaranovASignAlternationsSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | GetInput() = in; |
| 13 | 92 | GetOutput() = 0; | |
| 14 | 92 | } | |
| 15 | |||
| 16 | 92 | bool BaranovASignAlternationsSEQ::ValidationImpl() { | |
| 17 | 92 | return GetOutput() >= 0; | |
| 18 | } | ||
| 19 | |||
| 20 | 92 | bool BaranovASignAlternationsSEQ::PreProcessingImpl() { | |
| 21 | 92 | return true; | |
| 22 | } | ||
| 23 | |||
| 24 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 76 times.
|
92 | bool BaranovASignAlternationsSEQ::RunImpl() { |
| 25 | const auto &input = GetInput(); | ||
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 76 times.
|
92 | if (input.size() < 2) { |
| 28 | 16 | GetOutput() = 0; | |
| 29 | 16 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | int alternations_count = 0; | ||
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 260 times.
✓ Branch 1 taken 76 times.
|
336 | for (size_t i = 0; i < input.size() - 1; i++) { |
| 35 | 260 | int current = input[i]; | |
| 36 | 260 | int next = input[i + 1]; | |
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 80 times.
|
260 | if (current != 0 && next != 0) { |
| 39 |
4/4✓ Branch 0 taken 124 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 100 times.
|
180 | if ((current > 0 && next < 0) || (current < 0 && next > 0)) { |
| 40 | 80 | alternations_count++; | |
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | 76 | GetOutput() = alternations_count; | |
| 46 | 76 | return true; | |
| 47 | } | ||
| 48 | |||
| 49 | 92 | bool BaranovASignAlternationsSEQ::PostProcessingImpl() { | |
| 50 | 92 | return true; | |
| 51 | } | ||
| 52 | |||
| 53 | } // namespace baranov_a_sign_alternations | ||
| 54 |