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
5 changes: 3 additions & 2 deletions homework/insensitive-palindrom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ 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 test.cpp ispalindrom.cpp)
add_executable(${PROJECT_NAME} main.cpp ispalindrom.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)
add_compile_options(${PROJECT_NAME} -Wall -Wextra -Wconversion -pedantic -Werror)

target_link_libraries(${PROJECT_NAME}-ut gtest_main)

Expand Down
29 changes: 29 additions & 0 deletions homework/insensitive-palindrom/ispalindrom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "ispalindrom.hpp"

bool is_palindrome(std::string phraseToTest) {
/*
--->skopjuj znaki do vectora jesli sa z zakresu znakow drukowalnych 32-128
--->zamien na malelitery
---?sprawedz czy jest lustrzanym odbiciem
*/

std::vector<char> PlaceHolder(
std::distance(phraseToTest.begin(), phraseToTest.end()));
std::copy_if(phraseToTest.begin(), phraseToTest.end(), PlaceHolder.begin(),
[](auto spell) {
return (spell > 47 && spell < 58) |
(spell > 64 && spell < 91) |
(spell > 96 && spell < 123)
? true
: false;
});

std::transform(PlaceHolder.begin(), PlaceHolder.end(), PlaceHolder.begin(),
[](unsigned char c) { return std::tolower(c); });

PlaceHolder.resize(distance(PlaceHolder.begin(),
find(PlaceHolder.begin(), PlaceHolder.end(), 0)));

return std::equal(PlaceHolder.cbegin(), PlaceHolder.cend(),
PlaceHolder.crbegin());
};
12 changes: 12 additions & 0 deletions homework/insensitive-palindrom/ispalindrom.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <algorithm>
#include <array>
#include <forward_list>
#include <iostream>
#include <iterator>
#include <string.h>
#include <utility>
#include <vector>
#include"cctype"


bool is_palindrome(std::string phraseToTest);
15 changes: 15 additions & 0 deletions homework/insensitive-palindrom/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "ispalindrom.hpp"
#include <algorithm>

#include <iostream>
#include <iterator>
#include <string.h>
#include <utility>
#include <vector>

int main() {
std::string s{"Eva, can I see bees in a cave?"};

std::cout << std::boolalpha << is_palindrome(s);
return 0;
}
47 changes: 28 additions & 19 deletions homework/insensitive-palindrom/test.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
#include "cctype"
#include "ispalindrom.hpp"
#include "gtest/gtest.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string.h>
#include <utility>
#include <vector>

// TODO: Includes

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

TEST_P(InsensitivePalindromFixture, CheckPalindrome) {
EXPECT_EQ(is_palindrome(GetParam().first), GetParam().second);
EXPECT_EQ(is_palindrome(GetParam().first), GetParam().second);
}

INSTANTIATE_TEST_SUITE_P(
InsensitivePalindromTests,
InsensitivePalindromFixture,
InsensitivePalindromTests, InsensitivePalindromFixture,
::testing::Values(
std::make_pair("a", true),
std::make_pair("aba", true),
std::make_pair("a", true), std::make_pair("aba", true),
std::make_pair("abba", true),
std::make_pair("Eva, can I see bees in a cave?", true),
std::make_pair("No lemon, no melon", true),
std::make_pair("Was it a cat I saw?", true),
std::make_pair("Red rum, sir, is murder", true),
std::make_pair("Are we not pure? “No, sir!” Panama’s moody Noriega brags."
"It is garbage!” Irony dooms a man—a prisoner up to new era.",
true),
std::make_pair("Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol,"
"Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny,"
"Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, "
"Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva,"
"Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, "
"Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.",
true),
std::make_pair("ab", false),
std::make_pair("abab", false),
std::make_pair(
"Are we not pure? “No, sir!” Panama’s moody Noriega brags."
"It is garbage!” Irony dooms a man—a prisoner up to new era.",
true),
std::make_pair(
"Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol,"
"Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny,"
"Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, "
"Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, "
"Eva,"
"Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, "
"Cecil, "
"Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.",
true),
std::make_pair("ab", false), std::make_pair("abab", false),
std::make_pair("abb", false),
std::make_pair("A nut for a jarr of tuna.", false),
std::make_pair("All lets Della call Ed “Stella.”", false),
Expand Down