| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Rastvorov_K_Number_of_character_alternations/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | |||
| 5 | #include "Rastvorov_K_Number_of_character_alternations/common/include/common.hpp" | ||
| 6 | |||
| 7 | namespace rastvorov_k_number_of_character_alternations { | ||
| 8 | |||
| 9 | namespace { | ||
| 10 | |||
| 11 | inline int Sign(double x) { | ||
| 12 | if (x > 0.0) { | ||
| 13 | return 1; | ||
| 14 | } | ||
| 15 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 128 times.
|
200 | if (x < 0.0) { |
| 16 | return -1; | ||
| 17 | } | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | inline double GetElement(std::size_t i) { | ||
| 22 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 72 times.
|
328 | if (i % 5 == 0) { |
| 23 | return 0.0; | ||
| 24 | } | ||
| 25 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 128 times.
|
256 | if (i % 2 == 0) { |
| 26 | return 1.0; | ||
| 27 | } | ||
| 28 | return -1.0; | ||
| 29 | } | ||
| 30 | |||
| 31 | } // namespace | ||
| 32 | |||
| 33 | 40 | RastvorovKNumberAfCharacterAlternationsSEQ::RastvorovKNumberAfCharacterAlternationsSEQ(const InType &in) { | |
| 34 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 35 | 40 | GetInput() = in; | |
| 36 | GetOutput() = 0; | ||
| 37 | 40 | } | |
| 38 | |||
| 39 | 40 | bool RastvorovKNumberAfCharacterAlternationsSEQ::ValidationImpl() { | |
| 40 | 40 | return GetInput() >= 0; | |
| 41 | } | ||
| 42 | |||
| 43 | 40 | bool RastvorovKNumberAfCharacterAlternationsSEQ::PreProcessingImpl() { | |
| 44 | 40 | GetOutput() = 0; | |
| 45 | 40 | return true; | |
| 46 | } | ||
| 47 | |||
| 48 | 40 | bool RastvorovKNumberAfCharacterAlternationsSEQ::RunImpl() { | |
| 49 | 40 | const InType n = GetInput(); | |
| 50 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 32 times.
|
40 | if (n <= 0) { |
| 51 | 8 | GetOutput() = 0; | |
| 52 | 8 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | int prev = 0; | ||
| 56 | int cnt = 0; | ||
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 328 times.
✓ Branch 1 taken 32 times.
|
360 | for (std::size_t i = 0; i < static_cast<std::size_t>(n); ++i) { |
| 59 | const int s = Sign(GetElement(i)); | ||
| 60 | 72 | if (s == 0) { | |
| 61 | 72 | continue; | |
| 62 | } | ||
| 63 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 64 times.
|
256 | if (prev != 0 && s != prev) { |
| 64 | 192 | ++cnt; | |
| 65 | } | ||
| 66 | prev = s; | ||
| 67 | } | ||
| 68 | |||
| 69 | 32 | GetOutput() = cnt; | |
| 70 | 32 | return true; | |
| 71 | } | ||
| 72 | |||
| 73 | 40 | bool RastvorovKNumberAfCharacterAlternationsSEQ::PostProcessingImpl() { | |
| 74 | 40 | return true; | |
| 75 | } | ||
| 76 | |||
| 77 | } // namespace rastvorov_k_number_of_character_alternations | ||
| 78 |