Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homework/insensitive-palindrom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FetchContent_MakeAvailable(googletest)
project(insensitivePalindrom)
enable_testing()

add_executable(${PROJECT_NAME}-ut test.cpp) # add your cpp file here after test.cpp
add_executable(${PROJECT_NAME}-ut detector.cpp test.cpp) # add your cpp file here after test.cpp
# if this is problematic take a look into CMakeLists.txt files in other exercises

add_compile_options(${PROJECT_NAME}-ut -Wall -Wextra -Wconversion -pedantic -Werror)
Expand Down
9 changes: 9 additions & 0 deletions homework/insensitive-palindrom/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RMDIR build /S /Q
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
MinGW32-make

insensitivePalindrom-ut.exe

cd ..
25 changes: 25 additions & 0 deletions homework/insensitive-palindrom/detector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "detector.hpp"
#include <algorithm>
#include <iostream>

std::string toLowerAndRemoveSpecial(const std::string& input) {
std::string result;
result.reserve(input.size());

std::for_each(input.begin(), input.end(), [&result](char c) {
if (std::isalnum(static_cast<unsigned char>(c))) {
result += std::tolower(static_cast<unsigned char>(c));
}
});

return result;
}

bool is_palindrome(std::string word) {
std::string word_raw = toLowerAndRemoveSpecial(word);
std::string word_raw_reverse = word_raw;

std::reverse_copy(word_raw.begin(), word_raw.end(), word_raw_reverse.begin());

return std::equal(word_raw.begin(), word_raw.end(), word_raw_reverse.begin(), word_raw_reverse.end());
}
4 changes: 4 additions & 0 deletions homework/insensitive-palindrom/detector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include <string>

bool is_palindrome(std::string word);
3 changes: 1 addition & 2 deletions homework/insensitive-palindrom/test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "detector.hpp"
#include "gtest/gtest.h"

// TODO: Includes

class InsensitivePalindromFixture : public ::testing::TestWithParam<std::pair<std::string, bool>> {
};

Expand Down