Skip to content
Open
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
42 changes: 42 additions & 0 deletions tdd_intro/demo/01_bob/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,45 @@ He answers 'Whatever.' to anything else.
#include <gtest/gtest.h>
#include <string>

const std::string g_tellBobAnswer = "Sure";
const std::string g_yellBobAnswer = "Whoa, chill out!";
const std::string g_emptyBobAnswer = "Fine. Be that way!";
const std::string g_defaultBobAnswer = "Whatever.";

std::string CallBob(const std::string& str)
{
if (str.empty())
{
return g_emptyBobAnswer;
}
if (str.back() == '!')
{
return g_yellBobAnswer;
}
else if (str.back() == '?')
{
return g_tellBobAnswer;
}

return g_defaultBobAnswer;
}

TEST(bob, AnswerSureOnQuestion)
{
ASSERT_EQ(g_tellBobAnswer, CallBob("Are you ok?"));
}

TEST(bob, AnswerChillOnYell)
{
ASSERT_EQ(g_yellBobAnswer, CallBob("Yell!!!!"));
}

TEST(bob, AnswerOnEmptyString)
{
ASSERT_EQ(g_emptyBobAnswer, CallBob(""));
}

TEST(bob, AnswerOnAnythingElse)
{
ASSERT_EQ(g_defaultBobAnswer, CallBob("Anything else"));
}
16 changes: 16 additions & 0 deletions tdd_intro/homework/00_intro/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@ For example: input: "cool" output: "looc"
*/

#include <gtest/gtest.h>

const std::string g_textToReverse = "Reversed";
const std::string g_textReversed = "desreveR";

std::string ReverseString(const std::string& str)
{
std::string reversedStr(str);
std::reverse(reversedStr.begin(), reversedStr.end());

return reversedStr;
}

TEST(intro, StringIsReversed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

после первого простого теста, можно было добавить два теста для четного и нечетного количества букв в строке, а потом уже финальный тест. Нет гарантии, что для нечетного количества будет работать, в задании были примеры.

{
ASSERT_EQ(g_textReversed, ReverseString(g_textToReverse));
}
1 change: 1 addition & 0 deletions tdd_intro/homework/homework.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TEMPLATE = subdirs

SUBDIRS += \
00_intro \
01_leap_year \
02_ternary_numbers \
03_bank_ocr \
Expand Down