From 6423a44bb398495dc0c72cf18d16ae9db8a4ab7f Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Fri, 26 Oct 2018 23:46:05 +0300 Subject: [PATCH 01/16] 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/06_coffee/06_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/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 From 4919240d9081202294fc120e4345353a1e7bba81 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Fri, 26 Oct 2018 23:48:10 +0300 Subject: [PATCH 02/16] 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 f8426489945827bb504c25827783edd4fc078b5b Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Wed, 7 Nov 2018 22:10:30 +0200 Subject: [PATCH 03/16] Disabled 6 homework because it is not buildable. --- tdd_intro/homework/homework.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From c2e1c46ef40d5fed14c4fd1d2e2771b1b227572c Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 09:41:16 +0200 Subject: [PATCH 04/16] Fixed build of 06 homework. Cleaned up tests. --- .../include/gtest/internal/gtest-internal.h | 8 ++- tdd_intro/homework/06_coffee/test.cpp | 72 ++----------------- tdd_intro/homework/homework.pro | 4 +- 3 files changed, 15 insertions(+), 69 deletions(-) diff --git a/tdd_intro/3rd_party/gtest/googletest/include/gtest/internal/gtest-internal.h b/tdd_intro/3rd_party/gtest/googletest/include/gtest/internal/gtest-internal.h index 2a6e4dad..ba899d0a 100644 --- a/tdd_intro/3rd_party/gtest/googletest/include/gtest/internal/gtest-internal.h +++ b/tdd_intro/3rd_party/gtest/googletest/include/gtest/internal/gtest-internal.h @@ -1045,8 +1045,12 @@ void CopyArray(const T* from, size_t size, U* to) { // native array it represents. // We use 2 different structs to allow non-copyable types to be used, as long // as RelationToSourceReference() is passed. -struct RelationToSourceReference {}; -struct RelationToSourceCopy {}; +struct RelationToSourceReference { + RelationToSourceReference() {} +}; +struct RelationToSourceCopy { + RelationToSourceCopy() {} +}; // Adapts a native array to a read-only STL-style container. Instead // of the complete STL container concept, this adaptor only implements diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 33b9093e..21b7d6b5 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -31,18 +31,6 @@ class ISourceOfIngredients virtual void AddCream(int gram) = 0; }; - -enum Cup -{ - Normal, - Big -}; - -enum Coffee -{ - Americano -}; - class MockSourceOfIngredients : public ISourceOfIngredients { public: @@ -56,64 +44,18 @@ class MockSourceOfIngredients : public ISourceOfIngredients MOCK_METHOD1(AddCream, void(int)); }; +enum CupSize +{ + Normal, + Big +}; + class CoffeeMachine { public: CoffeeMachine(ISourceOfIngredients& source) : m_source(source) - { + {} - } - void CreateCoffee(const Cup cup, const Coffee coffee) - { - m_source.AddCoffee(0); - m_source.SetCupSize(0); - m_source.AddWater(0, 0); - } private: ISourceOfIngredients& m_source; }; - - -// Architecture -// Class CoffeMachine -// Class-Mock SourceOfIngredients - -// - americano: water & coffee 1:2 or 1:3. Water temp 60C - -// Tests list: -// 1. americano + 100 gram = 1 coffe -// 2. americano + 140 gram = 1 large coffee -// 3. AddCoffee, SetCupSize and AddWater calls once -// 4. Check parameters -// 5. Same for each recipe - -TEST(CoffeeMachine, CoffemachineIsHere) -{ - MockSourceOfIngredients si; - CoffeeMachine cm(si); -} - -TEST(CoffeeMachine, CallsImportantThings) -{ - MockSourceOfIngredients si; - CoffeeMachine cm(si); - - EXPECT_CALL(si, AddCoffee(::testing::_)).Times(1); - EXPECT_CALL(si, SetCupSize(::testing::_)).Times(1); - EXPECT_CALL(si, AddWater(::testing::_, ::testing::_)).Times(1); - - cm.CreateCoffee(Cup::Normal, Coffee::Americano); -} - -//- americano: water & coffee 1:3 Water temp 60C -TEST(CoffeeMachine, Americano) -{ - MockSourceOfIngredients si; - CoffeeMachine cm(si); - - EXPECT_CALL(si, AddCoffee(75)).Times(1); - EXPECT_CALL(si, SetCupSize(100)).Times(1); - EXPECT_CALL(si, AddWater(25, 60)).Times(1); - - cm.CreateCoffee(Cup::Normal, Coffee::Americano); -} diff --git a/tdd_intro/homework/homework.pro b/tdd_intro/homework/homework.pro index 13ac9d31..cf6c01b9 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 From d94cca3d121045f6e1a28a904c8b7a55dc285e76 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 09:54:29 +0200 Subject: [PATCH 05/16] Added linking with gmock for macos --- tdd_intro/gmock.pri | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tdd_intro/gmock.pri b/tdd_intro/gmock.pri index 73de1d85..0e854fac 100644 --- a/tdd_intro/gmock.pri +++ b/tdd_intro/gmock.pri @@ -1,6 +1,6 @@ win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../3rd_party/gmock/release/ -lgmock else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../3rd_party/gmock/debug/ -lgmock -else:unix:!macx: LIBS += -L$$OUT_PWD/../../3rd_party/gmock/ -lgmock +else:unix: LIBS += -L$$OUT_PWD/../../3rd_party/gmock/ -lgmock INCLUDEPATH += $$PWD/3rd_party/gmock/include INCLUDEPATH += $$PWD/3rd_party/gtest/googletest/include @@ -9,4 +9,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/gmock/debug/libgmock.a else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gmock/release/gmock.lib else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gmock/debug/gmock.lib -else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gmock/libgmock.a +else:unix: PRE_TARGETDEPS += $$OUT_PWD/../../3rd_party/gmock/libgmock.a From e4b511d314ade6b9f23c0c443a93dee50aeea408 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 09:55:04 +0200 Subject: [PATCH 06/16] Added red test for cappuchino. --- tdd_intro/homework/06_coffee/test.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 21b7d6b5..9f0d31b6 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -46,7 +46,7 @@ class MockSourceOfIngredients : public ISourceOfIngredients enum CupSize { - Normal, + Little, Big }; @@ -56,6 +56,23 @@ class CoffeeMachine CoffeeMachine(ISourceOfIngredients& source) : m_source(source) {} + void MakeCappuccino(const CupSize cupSize) + {} + private: ISourceOfIngredients& m_source; }; + +TEST(CoffeeMachine, MakeBigCappuccino) +{ + MockSourceOfIngredients ingridientsSource; + + EXPECT_CALL(ingridientsSource, AddWater(140, 80)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilk(140 / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddCoffee(140 / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilkFoam(140 / 3)).Times(1); + + CoffeeMachine coffeeMachine(ingridientsSource); + + coffeeMachine.MakeCappuccino(CupSize::Big); +} From bc818537fb196bfaed77979186540321291e9592 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 09:58:37 +0200 Subject: [PATCH 07/16] Implemented capuchino big. --- tdd_intro/homework/06_coffee/test.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 9f0d31b6..495d2d5a 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -53,14 +53,19 @@ enum CupSize class CoffeeMachine { public: - CoffeeMachine(ISourceOfIngredients& source) : m_source(source) + CoffeeMachine(ISourceOfIngredients& source) : m_ingridientsSource(source) {} void MakeCappuccino(const CupSize cupSize) - {} + { + m_ingridientsSource.AddWater(140, 80); + m_ingridientsSource.AddMilk(140 / 3); + m_ingridientsSource.AddCoffee(140 / 3); + m_ingridientsSource.AddMilkFoam(140 / 3); + } private: - ISourceOfIngredients& m_source; + ISourceOfIngredients& m_ingridientsSource; }; TEST(CoffeeMachine, MakeBigCappuccino) From 98fa4d7efa30e6cbd592a6c42602c96b2bf002b2 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:00:40 +0200 Subject: [PATCH 08/16] Refactoring. --- tdd_intro/homework/06_coffee/test.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 495d2d5a..0314a935 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -58,10 +58,13 @@ class CoffeeMachine void MakeCappuccino(const CupSize cupSize) { - m_ingridientsSource.AddWater(140, 80); - m_ingridientsSource.AddMilk(140 / 3); - m_ingridientsSource.AddCoffee(140 / 3); - m_ingridientsSource.AddMilkFoam(140 / 3); + const int bigCupGrams = 140; + const int temperature = 80; + + m_ingridientsSource.AddWater(bigCupGrams, temperature); + m_ingridientsSource.AddMilk(bigCupGrams / 3); + m_ingridientsSource.AddCoffee(bigCupGrams / 3); + m_ingridientsSource.AddMilkFoam(bigCupGrams / 3); } private: From 7250a4c0a12b0a2098e68d58e54e49f1d371457e Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:02:18 +0200 Subject: [PATCH 09/16] Test refactoring . --- tdd_intro/homework/06_coffee/test.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 0314a935..59e8444c 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -75,10 +75,13 @@ TEST(CoffeeMachine, MakeBigCappuccino) { MockSourceOfIngredients ingridientsSource; - EXPECT_CALL(ingridientsSource, AddWater(140, 80)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilk(140 / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddCoffee(140 / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilkFoam(140 / 3)).Times(1); + const int cappuccinoTemperature = 80; + const int cappuccinoGrams = 140; + + EXPECT_CALL(ingridientsSource, AddWater(cappuccinoGrams, cappuccinoTemperature)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilk(cappuccinoGrams / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddCoffee(cappuccinoGrams / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilkFoam(cappuccinoGrams / 3)).Times(1); CoffeeMachine coffeeMachine(ingridientsSource); From 210a850613a8ec8540beb8518a40d968b2ab11d4 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:05:43 +0200 Subject: [PATCH 10/16] Implemented little capuchino making. --- tdd_intro/homework/06_coffee/test.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 59e8444c..21a08494 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -58,7 +58,7 @@ class CoffeeMachine void MakeCappuccino(const CupSize cupSize) { - const int bigCupGrams = 140; + const int bigCupGrams = (cupSize == CupSize::Little ? 100 : 140); const int temperature = 80; m_ingridientsSource.AddWater(bigCupGrams, temperature); @@ -84,6 +84,21 @@ TEST(CoffeeMachine, MakeBigCappuccino) EXPECT_CALL(ingridientsSource, AddMilkFoam(cappuccinoGrams / 3)).Times(1); CoffeeMachine coffeeMachine(ingridientsSource); - coffeeMachine.MakeCappuccino(CupSize::Big); } + +TEST(CoffeeMachine, MakeLittleCappuccino) +{ + MockSourceOfIngredients ingridientsSource; + + const int cappuchinoTemperature = 80; + const int cappuchinoGrams = 100; + + EXPECT_CALL(ingridientsSource, AddWater(cappuchinoGrams, cappuchinoTemperature)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilk(cappuchinoGrams / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddCoffee(cappuchinoGrams / 3)).Times(1); + EXPECT_CALL(ingridientsSource, AddMilkFoam(cappuchinoGrams / 3)).Times(1); + + CoffeeMachine coffeeMachine(ingridientsSource); + coffeeMachine.MakeCappuccino(CupSize::Little); +} From 1294218b89855de85ef60d63485e4e392ef99a1f Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:10:40 +0200 Subject: [PATCH 11/16] Removed code duplication in tests. --- tdd_intro/homework/06_coffee/test.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 21a08494..037e812f 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -42,6 +42,16 @@ class MockSourceOfIngredients : public ISourceOfIngredients MOCK_METHOD1(AddMilkFoam, void(int)); MOCK_METHOD1(AddChocolate, void(int)); MOCK_METHOD1(AddCream, void(int)); + + void SetupCappuchinoExpectations(int grams) + { + const int cappuccinoTemperature = 80; + + EXPECT_CALL(*this, AddWater(grams, cappuccinoTemperature)).Times(1); + EXPECT_CALL(*this, AddMilk(grams / 3)).Times(1); + EXPECT_CALL(*this, AddCoffee(grams / 3)).Times(1); + EXPECT_CALL(*this, AddMilkFoam(grams / 3)).Times(1); + } }; enum CupSize @@ -75,13 +85,8 @@ TEST(CoffeeMachine, MakeBigCappuccino) { MockSourceOfIngredients ingridientsSource; - const int cappuccinoTemperature = 80; - const int cappuccinoGrams = 140; - - EXPECT_CALL(ingridientsSource, AddWater(cappuccinoGrams, cappuccinoTemperature)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilk(cappuccinoGrams / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddCoffee(cappuccinoGrams / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilkFoam(cappuccinoGrams / 3)).Times(1); + const int cappuchinoGrams = 140; + ingridientsSource.SetupCappuchinoExpectations(cappuchinoGrams); CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeCappuccino(CupSize::Big); @@ -91,13 +96,8 @@ TEST(CoffeeMachine, MakeLittleCappuccino) { MockSourceOfIngredients ingridientsSource; - const int cappuchinoTemperature = 80; const int cappuchinoGrams = 100; - - EXPECT_CALL(ingridientsSource, AddWater(cappuchinoGrams, cappuchinoTemperature)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilk(cappuchinoGrams / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddCoffee(cappuchinoGrams / 3)).Times(1); - EXPECT_CALL(ingridientsSource, AddMilkFoam(cappuchinoGrams / 3)).Times(1); + ingridientsSource.SetupCappuchinoExpectations(cappuchinoGrams); CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeCappuccino(CupSize::Little); From b837162e53eb062243c5ef98557b8b55106e579d Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:15:48 +0200 Subject: [PATCH 12/16] Implemented latte. --- tdd_intro/homework/06_coffee/test.cpp | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 037e812f..b9529a6d 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -52,6 +52,16 @@ class MockSourceOfIngredients : public ISourceOfIngredients EXPECT_CALL(*this, AddCoffee(grams / 3)).Times(1); EXPECT_CALL(*this, AddMilkFoam(grams / 3)).Times(1); } + + void SetupLatteExpectations(int grams) + { + const int temperature = 90; + + EXPECT_CALL(*this, AddWater(grams, temperature)).Times(1); + EXPECT_CALL(*this, AddMilk(grams / 4)).Times(1); + EXPECT_CALL(*this, AddCoffee(grams / 2)).Times(1); + EXPECT_CALL(*this, AddMilkFoam(grams / 4)).Times(1); + } }; enum CupSize @@ -77,6 +87,17 @@ class CoffeeMachine m_ingridientsSource.AddMilkFoam(bigCupGrams / 3); } + void MakeLatte(const CupSize cupSize) + { + const int grams = (cupSize == CupSize::Little ? 100 : 140); + const int temperature = 90; + + m_ingridientsSource.AddWater(grams, temperature); + m_ingridientsSource.AddMilk(grams / 4); + m_ingridientsSource.AddCoffee(grams / 2); + m_ingridientsSource.AddMilkFoam(grams / 4); + } + private: ISourceOfIngredients& m_ingridientsSource; }; @@ -102,3 +123,14 @@ TEST(CoffeeMachine, MakeLittleCappuccino) CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeCappuccino(CupSize::Little); } + +TEST(CoffeeMachine, MakeBigLatte) +{ + MockSourceOfIngredients ingridientsSource; + + const int grams = 140; + ingridientsSource.SetupLatteExpectations(grams); + + CoffeeMachine coffeeMachine(ingridientsSource); + coffeeMachine.MakeLatte(CupSize::Big); +} From d45e9adf6efd7dba3137bcd305ace7d861a50511 Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:19:24 +0200 Subject: [PATCH 13/16] Several renamings. --- tdd_intro/homework/06_coffee/test.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index b9529a6d..b3eb970c 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -78,13 +78,13 @@ class CoffeeMachine void MakeCappuccino(const CupSize cupSize) { - const int bigCupGrams = (cupSize == CupSize::Little ? 100 : 140); + const int grams = (cupSize == CupSize::Little ? 100 : 140); const int temperature = 80; - m_ingridientsSource.AddWater(bigCupGrams, temperature); - m_ingridientsSource.AddMilk(bigCupGrams / 3); - m_ingridientsSource.AddCoffee(bigCupGrams / 3); - m_ingridientsSource.AddMilkFoam(bigCupGrams / 3); + m_ingridientsSource.AddWater(grams, temperature); + m_ingridientsSource.AddMilk(grams / 3); + m_ingridientsSource.AddCoffee(grams / 3); + m_ingridientsSource.AddMilkFoam(grams / 3); } void MakeLatte(const CupSize cupSize) @@ -106,8 +106,8 @@ TEST(CoffeeMachine, MakeBigCappuccino) { MockSourceOfIngredients ingridientsSource; - const int cappuchinoGrams = 140; - ingridientsSource.SetupCappuchinoExpectations(cappuchinoGrams); + const int grams = 140; + ingridientsSource.SetupCappuchinoExpectations(grams); CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeCappuccino(CupSize::Big); @@ -117,8 +117,8 @@ TEST(CoffeeMachine, MakeLittleCappuccino) { MockSourceOfIngredients ingridientsSource; - const int cappuchinoGrams = 100; - ingridientsSource.SetupCappuchinoExpectations(cappuchinoGrams); + const int grams = 100; + ingridientsSource.SetupCappuchinoExpectations(grams); CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeCappuccino(CupSize::Little); From 4d3fdef3279040ff11c6d22a1131974de40b715e Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:23:29 +0200 Subject: [PATCH 14/16] Rmeoved code duplication. --- tdd_intro/homework/06_coffee/test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index b3eb970c..02c2e72c 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -78,7 +78,7 @@ class CoffeeMachine void MakeCappuccino(const CupSize cupSize) { - const int grams = (cupSize == CupSize::Little ? 100 : 140); + const int grams = GramsFromCupSize(cupSize); const int temperature = 80; m_ingridientsSource.AddWater(grams, temperature); @@ -89,7 +89,7 @@ class CoffeeMachine void MakeLatte(const CupSize cupSize) { - const int grams = (cupSize == CupSize::Little ? 100 : 140); + const int grams = GramsFromCupSize(cupSize); const int temperature = 90; m_ingridientsSource.AddWater(grams, temperature); @@ -98,6 +98,17 @@ class CoffeeMachine m_ingridientsSource.AddMilkFoam(grams / 4); } +private: + int GramsFromCupSize(const CupSize cupSize) + { + if (cupSize == CupSize::Little) + { + return 100; + } + + return 140; //for CupSize::Big + } + private: ISourceOfIngredients& m_ingridientsSource; }; From 7921af1a0f63c63e302a35f081e9009dc976ca0a Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:24:14 +0200 Subject: [PATCH 15/16] Green test for little latte. --- tdd_intro/homework/06_coffee/test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 02c2e72c..d252b065 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -145,3 +145,14 @@ TEST(CoffeeMachine, MakeBigLatte) CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeLatte(CupSize::Big); } + +TEST(CoffeeMachine, MakeLittleLatte) +{ + MockSourceOfIngredients ingridientsSource; + + const int grams = 100; + ingridientsSource.SetupLatteExpectations(grams); + + CoffeeMachine coffeeMachine(ingridientsSource); + coffeeMachine.MakeLatte(CupSize::Little); +} From a88f2ef187c591378cc6f49ff16779d77abeac2f Mon Sep 17 00:00:00 2001 From: Roman Mokych Date: Thu, 29 Nov 2018 10:31:31 +0200 Subject: [PATCH 16/16] Implemented marochino. --- tdd_intro/homework/06_coffee/test.cpp | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index d252b065..f4cdaa13 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -62,6 +62,14 @@ class MockSourceOfIngredients : public ISourceOfIngredients EXPECT_CALL(*this, AddCoffee(grams / 2)).Times(1); EXPECT_CALL(*this, AddMilkFoam(grams / 4)).Times(1); } + + void SetupMarochinoExpectations(int grams, const int temperature) + { + EXPECT_CALL(*this, AddWater(grams, temperature)).Times(1); + EXPECT_CALL(*this, AddChocolate(grams / 4)).Times(1); + EXPECT_CALL(*this, AddCoffee(grams / 4)).Times(1); + EXPECT_CALL(*this, AddMilkFoam(grams / 4)).Times(1); + } }; enum CupSize @@ -98,6 +106,16 @@ class CoffeeMachine m_ingridientsSource.AddMilkFoam(grams / 4); } + void MakeMarochino(const CupSize cupSize, const int temperature) + { + const int grams = GramsFromCupSize(cupSize); + + m_ingridientsSource.AddWater(grams, temperature); + m_ingridientsSource.AddChocolate(grams / 4); + m_ingridientsSource.AddCoffee(grams / 4); + m_ingridientsSource.AddMilkFoam(grams / 4); + } + private: int GramsFromCupSize(const CupSize cupSize) { @@ -156,3 +174,15 @@ TEST(CoffeeMachine, MakeLittleLatte) CoffeeMachine coffeeMachine(ingridientsSource); coffeeMachine.MakeLatte(CupSize::Little); } + +TEST(CoffeeMachine, MakeBigMarochino) +{ + MockSourceOfIngredients ingridientsSource; + + const int grams = 140; + const int temperature = 50; + ingridientsSource.SetupMarochinoExpectations(grams, temperature); + + CoffeeMachine coffeeMachine(ingridientsSource); + coffeeMachine.MakeMarochino(CupSize::Big, temperature); +}