| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "krykov_e_word_count/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cctype> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <ranges> | ||
| 7 | #include <string> | ||
| 8 | |||
| 9 | #include "krykov_e_word_count/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace krykov_e_word_count { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 176 times.
✗ Branch 2 not taken.
|
176 | KrykovEWordCountSEQ::KrykovEWordCountSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 176 | GetOutput() = 0; | |
| 17 | 176 | } | |
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
|
176 | bool KrykovEWordCountSEQ::ValidationImpl() { |
| 20 |
2/4✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 176 times.
|
176 | return (!GetInput().empty()) && (GetOutput() == 0); |
| 21 | } | ||
| 22 | |||
| 23 | 176 | bool KrykovEWordCountSEQ::PreProcessingImpl() { | |
| 24 | auto &input = GetInput(); | ||
| 25 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 176 times.
|
232 | input.erase(input.begin(), std::ranges::find_if(input, [](unsigned char ch) { return !std::isspace(ch); })); |
| 26 | 176 | input.erase( | |
| 27 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 176 times.
|
232 | std::ranges::find_if(std::ranges::reverse_view(input), [](unsigned char ch) { return !std::isspace(ch); }).base(), |
| 28 | input.end()); | ||
| 29 | 176 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | 176 | bool KrykovEWordCountSEQ::RunImpl() { | |
| 33 | const std::string &text = GetInput(); | ||
| 34 | |||
| 35 | bool in_word = false; | ||
| 36 | size_t word_count = 0; | ||
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 2192 times.
✓ Branch 1 taken 176 times.
|
2368 | for (char c : text) { |
| 39 |
2/2✓ Branch 0 taken 1904 times.
✓ Branch 1 taken 288 times.
|
2192 | if (std::isspace(static_cast<unsigned char>(c)) != 0) { |
| 40 | if (in_word) { | ||
| 41 | in_word = false; | ||
| 42 | } | ||
| 43 | } else { | ||
| 44 |
2/2✓ Branch 0 taken 368 times.
✓ Branch 1 taken 1536 times.
|
1904 | if (!in_word) { |
| 45 | in_word = true; | ||
| 46 | 368 | word_count++; | |
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | 176 | GetOutput() = static_cast<int>(word_count); | |
| 52 | 176 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 176 | bool KrykovEWordCountSEQ::PostProcessingImpl() { | |
| 56 | 176 | return GetOutput() >= 0; | |
| 57 | } | ||
| 58 | |||
| 59 | } // namespace krykov_e_word_count | ||
| 60 |