Skip to content

Commit

Permalink
fix: missing assertions in parallel-letter-frequency test (#830)
Browse files Browse the repository at this point in the history
* fix: missing assertions in parallel-letter-frequency test

* fix example implementation

* include namespace in .cpp
  • Loading branch information
ahans authored Mar 5, 2024
1 parent 0f24bf1 commit f547e22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
There are several ways how to achieve parallelism in C++.
Exercism's online runner supports C++17, so you can use execution policies from the [algorithms library][algorithm].
Another option is manually managing [threads][thread].
However, note that spawning a thread is quite expensive (using a thread [pool][pool] would help).
However, note that spawning a thread is quite expensive (using a [thread pool][pool] would help).

When working locally, you can of course use whatever you want.
However, a solution using non-standard libraries will most probably not work with the Exercism online runner.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ namespace {
[[nodiscard]] std::unordered_map<char, size_t> frequency(
std::string_view const text) {
std::unordered_map<char, size_t> freq;
for (unsigned char c : text) freq[std::tolower(c)] += 1;
for (unsigned char c : text) {
if (std::isalpha(c)) {
freq[std::tolower(c)] += 1;
}
}
return freq;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#include "parallel_letter_frequency.h"

namespace parallel_letter_frequency {

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TEST_CASE("ignore whitespace",
"\n",
};
auto freqs = parallel_letter_frequency::frequency(texts);
CHECK(freqs.empty());
}

TEST_CASE("ignore punctuation",
Expand All @@ -88,6 +89,7 @@ TEST_CASE("ignore punctuation",
"!", "?", ";", ",", ".",
};
auto freqs = parallel_letter_frequency::frequency(texts);
CHECK(freqs.empty());
}

TEST_CASE("ignore numbers",
Expand All @@ -96,6 +98,7 @@ TEST_CASE("ignore numbers",
"1", "2", "3", "4", "5", "6", "7", "8", "9",
};
auto freqs = parallel_letter_frequency::frequency(texts);
CHECK(freqs.empty());
}

TEST_CASE(
Expand Down

0 comments on commit f547e22

Please sign in to comment.