Final product, sent for evaluation
All checks were successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
dDogge 2025-01-04 14:05:14 +01:00
parent 7cdf807337
commit e45e0674f3
3 changed files with 20 additions and 8 deletions

View file

@ -3,6 +3,8 @@ CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor \
-Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wconversion \
-Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -std=c++17
CXXFLAGS += -Wno-conversion
CXXFLAGS += -I.
ifeq ($(RELEASE),)

View file

@ -30,29 +30,38 @@ std::vector<std::string> read_candidates(std::istream &input) {
}
bool wrong_fn::operator()(const std::string &word) const {
return contains_any_of(word, letter_set);
std::string lowercase_word = word;
std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower);
std::string lowercase_set = letter_set;
std::transform(lowercase_set.begin(), lowercase_set.end(), lowercase_set.begin(), ::tolower);
return contains_any_of(lowercase_word, lowercase_set);
}
bool correct_fn::operator()(const std::string &word) const {
return std::all_of(map.begin(), map.end(), [&word](const auto &pair) {
return contains_at(word, pair.second, pair.first);
std::string lowercase_word = word;
std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower);
return std::all_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) {
return contains_at(lowercase_word, std::tolower(pair.second), pair.first);
});
}
bool misplaced_fn::operator()(const std::string &word) const {
std::string lowercase_word = word;
std::transform(lowercase_word.begin(), lowercase_word.end(), lowercase_word.begin(), ::tolower);
if (map.empty()) {
return true;
}
if (std::all_of(map.begin(), map.end(), [&word](const auto &pair) {
return pair.first < word.size() && word[pair.first] == pair.second;
if (std::all_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) {
return pair.first < lowercase_word.size() && lowercase_word[pair.first] == std::tolower(pair.second);
})) {
return false;
}
if (std::any_of(map.begin(), map.end(), [&word](const auto &pair) {
return std::find(word.begin(), word.end(), pair.second) !=
word.end();
if (std::any_of(map.begin(), map.end(), [&lowercase_word](const auto &pair) {
return std::find(lowercase_word.begin(), lowercase_word.end(), std::tolower(pair.second)) !=
lowercase_word.end();
})) {
return true;
}

View file

@ -114,6 +114,7 @@ void test_build_list() {
}
}
//Added to check a bug mainly
void test_misplaced_fn_empty() {
std::vector<std::string> candidates = {"apple", "ample", "angle"};
std::string wrong = "x";