diff --git a/tdd_intro/demo/01_bob/test.cpp b/tdd_intro/demo/01_bob/test.cpp index dc9e42f..5840552 100644 --- a/tdd_intro/demo/01_bob/test.cpp +++ b/tdd_intro/demo/01_bob/test.cpp @@ -10,3 +10,45 @@ He answers 'Whatever.' to anything else. #include #include +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")); +} diff --git a/tdd_intro/homework/00_intro/test.cpp b/tdd_intro/homework/00_intro/test.cpp index be6959b..bfbaaab 100644 --- a/tdd_intro/homework/00_intro/test.cpp +++ b/tdd_intro/homework/00_intro/test.cpp @@ -7,3 +7,19 @@ For example: input: "cool" output: "looc" */ #include + +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) +{ + ASSERT_EQ(g_textReversed, ReverseString(g_textToReverse)); +} diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4f186c8..40c8587 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,36 @@ If your language provides a method in the standard library that does this look-u */ #include + +bool IsLeapYear(unsigned int year) +{ + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) + { + return true; + } + + return false; +} + +TEST(LeapYear, DivibleBy4) +{ + ASSERT_TRUE(IsLeapYear(1996)); +} + +TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100) +{ + ASSERT_FALSE(IsLeapYear(1900)); +} + +TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100UnlessDivisibleBy400) +{ + ASSERT_TRUE(IsLeapYear(2000)); +} + +TEST(LeapYear, Acceptence) +{ + ASSERT_TRUE(IsLeapYear(2020)); + ASSERT_TRUE(IsLeapYear(2008)); + ASSERT_FALSE(IsLeapYear(1990)); + ASSERT_FALSE(IsLeapYear(1000)); +} diff --git a/tdd_intro/homework/homework.pro b/tdd_intro/homework/homework.pro index cf6c01b..07506ca 100644 --- a/tdd_intro/homework/homework.pro +++ b/tdd_intro/homework/homework.pro @@ -1,6 +1,7 @@ TEMPLATE = subdirs SUBDIRS += \ + 00_intro \ 01_leap_year \ 02_ternary_numbers \ 03_bank_ocr \