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 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/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 17503028..88992794 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -16,3 +16,72 @@ The last place in a ternary number is the 1's place. The second to last is the 3 If your language provides a method in the standard library to perform the conversion, pretend it doesn't exist and implement it yourself. */ + +#include +#include + + +int IntFromTernaryNumberString(const std::string& ternaryNumberString) +{ + int result = 0; + for (size_t i = 0; i < ternaryNumberString.size(); ++i) + { + if (ternaryNumberString[i] < '0' || ternaryNumberString[i] > '2') + { + return 0; + } + + size_t power = ternaryNumberString.size() - i - 1; + result += (ternaryNumberString[i] - '0') * std::pow(3, power); + } + + return result; +} + +TEST(IntFromTernaryNumberString, one) +{ + EXPECT_EQ(1, IntFromTernaryNumberString("1")); +} + +TEST(IntFromTernaryNumberString, two) +{ + EXPECT_EQ(2, IntFromTernaryNumberString("2")); +} + +TEST(IntFromTernaryNumberString, decimal3ForTernary10) +{ + EXPECT_EQ(3, IntFromTernaryNumberString("10")); +} + +TEST(IntFromTernaryNumberString, decimal6ForTernary20) +{ + EXPECT_EQ(6, IntFromTernaryNumberString("20")); +} + +TEST(IntFromTernaryNumberString, decimal9ForTernary100) +{ + EXPECT_EQ(9, IntFromTernaryNumberString("100")); +} + +TEST(IntFromTernaryNumberString, decimal4ForTernary11) +{ + EXPECT_EQ(4, IntFromTernaryNumberString("11")); +} + +TEST(IntFromTernaryNumberString, decimal13ForTernary111) +{ + EXPECT_EQ(13, IntFromTernaryNumberString("111")); +} + +TEST(IntFromTernaryNumberString, zeroForInvalidTernary) +{ + EXPECT_EQ(0, IntFromTernaryNumberString("3")); + EXPECT_EQ(0, IntFromTernaryNumberString("13")); + EXPECT_EQ(0, IntFromTernaryNumberString(".")); +} + +TEST(IntFromTernaryNumberString, acceptance) +{ + EXPECT_EQ(302, IntFromTernaryNumberString("102012")); +} + 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/06_coffee/06_coffee.pro b/tdd_intro/homework/06_coffee/06_coffee.pro index dec9b6a8..05f06c68 100644 --- a/tdd_intro/homework/06_coffee/06_coffee.pro +++ b/tdd_intro/homework/06_coffee/06_coffee.pro @@ -1,3 +1,4 @@ +include(../../gtest.pri) include(../../gmock.pri) TEMPLATE = app diff --git a/tdd_intro/homework/homework.pro b/tdd_intro/homework/homework.pro index cf6c01b9..13ac9d31 100644 --- a/tdd_intro/homework/homework.pro +++ b/tdd_intro/homework/homework.pro @@ -5,5 +5,5 @@ SUBDIRS += \ 02_ternary_numbers \ 03_bank_ocr \ 04_weather_client \ - 05_word_wrapp \ - 06_coffee + 05_word_wrapp +# 06_coffee