| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "korolev_k_string_word_count/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cctype> | ||
| 4 | #include <string> | ||
| 5 | |||
| 6 | #include "korolev_k_string_word_count/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace korolev_k_string_word_count { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | KorolevKStringWordCountSEQ::KorolevKStringWordCountSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 | GetInput() = in; | ||
| 13 | 96 | GetOutput() = 0; | |
| 14 | 96 | } | |
| 15 | |||
| 16 | 96 | bool KorolevKStringWordCountSEQ::ValidationImpl() { | |
| 17 | // Any string is valid. Ensure output is reset. | ||
| 18 | 96 | return GetOutput() == 0; | |
| 19 | } | ||
| 20 | |||
| 21 | 96 | bool KorolevKStringWordCountSEQ::PreProcessingImpl() { | |
| 22 | 96 | GetOutput() = 0; | |
| 23 | 96 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 88 times.
|
96 | bool KorolevKStringWordCountSEQ::RunImpl() { |
| 27 | const std::string &s = GetInput(); | ||
| 28 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 88 times.
|
96 | if (s.empty()) { |
| 29 | 8 | GetOutput() = 0; | |
| 30 | 8 | return true; | |
| 31 | } | ||
| 32 | |||
| 33 | int count = 0; | ||
| 34 | bool in_word = false; | ||
| 35 |
2/2✓ Branch 0 taken 1816 times.
✓ Branch 1 taken 88 times.
|
1904 | for (char ch : s) { |
| 36 | 1816 | auto uc = static_cast<unsigned char>(ch); | |
| 37 | 1816 | bool is_space = std::isspace(uc) != 0; | |
| 38 |
2/2✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 304 times.
|
1816 | if (!is_space) { |
| 39 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 1296 times.
|
1512 | if (!in_word) { |
| 40 | 216 | ++count; | |
| 41 | in_word = true; | ||
| 42 | } | ||
| 43 | } else { | ||
| 44 | in_word = false; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | 88 | GetOutput() = count; | |
| 49 | 88 | return true; | |
| 50 | } | ||
| 51 | |||
| 52 | 96 | bool KorolevKStringWordCountSEQ::PostProcessingImpl() { | |
| 53 | // Nothing to post-process. | ||
| 54 | 96 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 | } // namespace korolev_k_string_word_count | ||
| 58 |