From a657f3136c68261212d754a45937829a49dc8609 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Fri, 26 Oct 2018 23:46:05 +0300 Subject: [PATCH 1/4] Fixed build issues. Fixed linking with gtest. Added dependecy on gtest for some homeworks. Fixed build of gmock. Fixed std::abs conflict. --- .../gmock/include/gmock/internal/gmock-internal-utils.h | 7 +++++++ tdd_intro/cleanroom/cleanroom.pro | 4 ++-- tdd_intro/gtest.pri | 4 ++-- tdd_intro/homework/04_weather_client/04_weather_client.pro | 1 + tdd_intro/homework/04_weather_client/test.cpp | 2 ++ tdd_intro/homework/05_coffee/05_coffee.pro | 1 + 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tdd_intro/3rd_party/gmock/include/gmock/internal/gmock-internal-utils.h b/tdd_intro/3rd_party/gmock/include/gmock/internal/gmock-internal-utils.h index e12b7d7d..5507611a 100644 --- a/tdd_intro/3rd_party/gmock/include/gmock/internal/gmock-internal-utils.h +++ b/tdd_intro/3rd_party/gmock/include/gmock/internal/gmock-internal-utils.h @@ -46,6 +46,13 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" +namespace { + +const testing::internal::RelationToSourceCopy kCopy; +const testing::internal::RelationToSourceReference kReference; + +} + namespace testing { namespace internal { diff --git a/tdd_intro/cleanroom/cleanroom.pro b/tdd_intro/cleanroom/cleanroom.pro index b92a4278..31ff6a0b 100644 --- a/tdd_intro/cleanroom/cleanroom.pro +++ b/tdd_intro/cleanroom/cleanroom.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs -SUBDIRS += \ - chatclient +#SUBDIRS += \ +# chatclient diff --git a/tdd_intro/gtest.pri b/tdd_intro/gtest.pri index 586007bb..bc93ca62 100644 --- a/tdd_intro/gtest.pri +++ b/tdd_intro/gtest.pri @@ -1,6 +1,6 @@ win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../3rd_party/gtest/release/ -lgtest else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../3rd_party/gtest/debug/ -lgtest -else:unix:!macx: LIBS += -L$$OUT_PWD/../../3rd_party/gtest/ -lgtest +else:unix: LIBS += -L$$OUT_PWD/../../3rd_party/gtest/ -lgtest INCLUDEPATH += $$PWD/3rd_party/gtest/googletest/include DEPENDPATH += $$PWD/3rd_party/gtest/googletest/include @@ -10,4 +10,4 @@ win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_ else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gtest/debug/libgtest.a else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gtest/release/gtest.lib else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gtest/debug/gtest.lib -else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gtest/libgtest.a +else:unix: PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gtest/libgtest.a diff --git a/tdd_intro/homework/04_weather_client/04_weather_client.pro b/tdd_intro/homework/04_weather_client/04_weather_client.pro index dec9b6a8..e8f86261 100644 --- a/tdd_intro/homework/04_weather_client/04_weather_client.pro +++ b/tdd_intro/homework/04_weather_client/04_weather_client.pro @@ -1,4 +1,5 @@ include(../../gmock.pri) +include(../../gtest.pri) TEMPLATE = app CONFIG += console c++11 diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 346ea809..476405e2 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -47,6 +47,8 @@ Each line means "" : "": #include #include +#include + struct Weather { short temperature = 0; diff --git a/tdd_intro/homework/05_coffee/05_coffee.pro b/tdd_intro/homework/05_coffee/05_coffee.pro index dec9b6a8..05f06c68 100644 --- a/tdd_intro/homework/05_coffee/05_coffee.pro +++ b/tdd_intro/homework/05_coffee/05_coffee.pro @@ -1,3 +1,4 @@ +include(../../gtest.pri) include(../../gmock.pri) TEMPLATE = app From cde857f41493ae03c722a42db5d5d2d162bcd7d7 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Fri, 26 Oct 2018 23:48:10 +0300 Subject: [PATCH 2/4] Added build files to the git ignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 259148fa..32673502 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app +build +.DS_Store +*.pro.user From bd821c5f53a019e8d2c05448c35804d3de2023e4 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Sat, 27 Oct 2018 00:05:10 +0300 Subject: [PATCH 3/4] Implemented is_leap_year function. --- tdd_intro/homework/01_leap_year/test.cpp | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4f186c8b..cfc51e40 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,33 @@ If your language provides a method in the standard library that does this look-u */ #include + +bool is_multiple(int number, int base) +{ + return number % base == 0; +} + +bool is_leap_year(int year) +{ + return (is_multiple(year, 4) && !is_multiple(year, 100)) || is_multiple(year, 400); +} + +TEST(is_leap_year, returns_true_for_4) +{ + EXPECT_TRUE(is_leap_year(4)); +} + +TEST(is_leap_year, returns_false_for_5) +{ + EXPECT_FALSE(is_leap_year(5)); +} + +TEST(is_leap_year, returns_false_for_100) +{ + EXPECT_FALSE(is_leap_year(100)); +} + +TEST(is_leap_year, returns_true_for_400) +{ + EXPECT_TRUE(is_leap_year(400)); +} From ac955d490431f6382d7088deb8a7d74ed06d4ea6 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Wed, 31 Oct 2018 22:12:40 +0200 Subject: [PATCH 4/4] Refactored is_leap_year function. --- tdd_intro/homework/01_leap_year/test.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index cfc51e40..d21da96d 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -21,7 +21,22 @@ bool is_multiple(int number, int base) bool is_leap_year(int year) { - return (is_multiple(year, 4) && !is_multiple(year, 100)) || is_multiple(year, 400); + if (is_multiple(year, 400)) + { + return true; + } + + if (is_multiple(year, 100)) + { + return false; + } + + if (is_multiple(year, 4)) + { + return true; + } + + return false; } TEST(is_leap_year, returns_true_for_4)