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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
*.exe
*.out
*.app

# Build dirs
build-*

# .user files
*.user
2 changes: 0 additions & 2 deletions tdd_intro/demo/02_word_count/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ such: 1

#include <gtest/gtest.h>
#include <string>
#include <map>

77 changes: 77 additions & 0 deletions tdd_intro/demo/03_word_wrapp/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Write a function, that is given a string and a length limit, splits provided string into sequence of string,
where length of each string is not more, than provided limit. If there are spaces under provided limit -
last space should be used to wrapp this line. If there are no spaces - wrapp it on provided length limit.

Example:
When pos is specified, the search only includes sequences of characters that begin at or before position pos,
ignoring any possible match beginning after pos

split(hee, 1) -> h, e, e
split(hee, 2) -> he, e
split("ha ha", 2|3|4) -> "ha", "ha"
split("h a", 1) -> "h", "a"

"When pos is specified, the",
"search only includes sequences",
"of characters that begin at or",
"before position pos, ignoring",
"any possible match beginning",
"after pos."
*/

#include <gtest/gtest.h>
#include <string>
#include <vector>

using StringContainer = std::vector<std::string>;
StringContainer SplitString(const std::string& string, size_t length)
{
auto firstSpaceInSubstr = string.rfind(' ', length);
std::string::size_type offset = length;
if (firstSpaceInSubstr != std::string::npos)
{
offset = firstSpaceInSubstr + 1;
}

StringContainer result {{ string.substr(0, offset) }};

if (length < string.size())
{
result.push_back(string.substr(offset));
}
return result;
}

TEST(SplitString, OnePartForOneSymbol)
{
StringContainer parts = {"a"};
EXPECT_EQ(parts, SplitString("a", 1));
}

TEST(SplitString, AbFirstForAbbaAnd2)
{
EXPECT_EQ("Ab", SplitString("Abba", 2).at(0));
}

TEST(SplitString, BaSecondForAbbba)
{
EXPECT_EQ("ba", SplitString("Abba", 2).at(1));
}

TEST(SplitString, AbForAbAnd4)
{
EXPECT_EQ("Ab", SplitString("Ab", 4).at(0));
}

TEST(SplitString, SplitAb_AbBeforeSpaceReturnsAbAndAb)
{
StringContainer parts = {"Ab", "Ab"};
EXPECT_EQ(parts, SplitString("Ab Ab", 2));
}

TEST(SplitString, SplitAb_AbAtSpaceReturnsAbAndAb)
{
StringContainer parts = {"Ab", "Ab"};
EXPECT_EQ(parts, SplitString("Ab Ab", 3));
}
1 change: 1 addition & 0 deletions tdd_intro/demo/demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SUBDIRS += \
01_fizz_buzz \
02_anagram \
02_word_count \
03_word_wrapp \
#03_allergies \
03_roman_numerals \
04_timer
96 changes: 0 additions & 96 deletions tdd_intro/homework/05_word_wrapp/test.cpp

This file was deleted.

175 changes: 171 additions & 4 deletions tdd_intro/homework/06_coffee/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ enum Cup

enum Coffee
{
Americano
Americano,
Cappucino,
Latte,
Marochino
};

class MockSourceOfIngredients : public ISourceOfIngredients
Expand All @@ -56,6 +59,11 @@ class MockSourceOfIngredients : public ISourceOfIngredients
MOCK_METHOD1(AddCream, void(int));
};

int GetCupSize(const Cup cup)
{
return cup == Cup::Big ? 140 : 100;
}

class CoffeeMachine
{
public:
Expand All @@ -65,9 +73,40 @@ class CoffeeMachine
}
void CreateCoffee(const Cup cup, const Coffee coffee)
{
m_source.AddCoffee(0);
m_source.SetCupSize(0);
m_source.AddWater(0, 0);
int cupSize = GetCupSize(cup);
m_source.SetCupSize(cupSize);
switch (coffee)
{
case Coffee::Cappucino:
{
m_source.AddCoffee(cupSize / 6);
m_source.AddWater(cupSize / 2, 80);
m_source.AddMilk(cupSize / 6);
m_source.AddMilkFoam(cupSize / 6);
break;
}
case Coffee::Latte:
{
m_source.AddCoffee(cupSize / 4);
m_source.AddWater(cupSize / 2, 90);
m_source.AddMilk(cupSize / 8);
m_source.AddMilkFoam(cupSize / 8);
break;
}
case Coffee::Americano:
{
m_source.AddCoffee(cupSize / 4 * 3);
m_source.AddWater(cupSize / 4, 60);
break;
}
case Coffee::Marochino:
{
m_source.AddCoffee(cupSize / 4);
m_source.AddChocolate(cupSize / 4);
m_source.AddMilkFoam(cupSize / 4);
break;
}
}
}
private:
ISourceOfIngredients& m_source;
Expand Down Expand Up @@ -117,3 +156,131 @@ TEST(CoffeeMachine, Americano)

cm.CreateCoffee(Cup::Normal, Coffee::Americano);
}
TEST(CoffeeMachine, BigAmericano)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(105)).Times(1);
EXPECT_CALL(si, SetCupSize(140)).Times(1);
EXPECT_CALL(si, AddWater(35, 60)).Times(1);

cm.CreateCoffee(Cup::Big, Coffee::Americano);
}

TEST(CoffeeMachine, CappucinoCallsImportantThings)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(::testing::_)).Times(1);
EXPECT_CALL(si, SetCupSize(::testing::_)).Times(1);
EXPECT_CALL(si, AddMilk(::testing::_)).Times(1);
EXPECT_CALL(si, AddMilkFoam(::testing::_)).Times(1);
EXPECT_CALL(si, AddWater(::testing::_, ::testing::_)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Cappucino);
}
TEST(CoffeeMachine, Cappucino)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(16)).Times(1);
EXPECT_CALL(si, SetCupSize(100)).Times(1);
EXPECT_CALL(si, AddMilk(16)).Times(1);
EXPECT_CALL(si, AddMilkFoam(16)).Times(1);
EXPECT_CALL(si, AddWater(50, 80)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Cappucino);
}
TEST(CoffeeMachine, BigCappucino)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(23)).Times(1);
EXPECT_CALL(si, SetCupSize(140)).Times(1);
EXPECT_CALL(si, AddMilk(23)).Times(1);
EXPECT_CALL(si, AddMilkFoam(23)).Times(1);
EXPECT_CALL(si, AddWater(70, 80)).Times(1);

cm.CreateCoffee(Cup::Big, Coffee::Cappucino);
}

TEST(CoffeeMachine, LatteCallsImportantThings)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(::testing::_)).Times(1);
EXPECT_CALL(si, SetCupSize(::testing::_)).Times(1);
EXPECT_CALL(si, AddMilk(::testing::_)).Times(1);
EXPECT_CALL(si, AddMilkFoam(::testing::_)).Times(1);
EXPECT_CALL(si, AddWater(::testing::_, ::testing::_)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Latte);
}
TEST(CoffeeMachine, Latte)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(25)).Times(1);
EXPECT_CALL(si, SetCupSize(100)).Times(1);
EXPECT_CALL(si, AddMilk(12)).Times(1);
EXPECT_CALL(si, AddMilkFoam(12)).Times(1);
EXPECT_CALL(si, AddWater(50, 90)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Latte);
}
TEST(CoffeeMachine, BigLatte)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(35)).Times(1);
EXPECT_CALL(si, SetCupSize(140)).Times(1);
EXPECT_CALL(si, AddMilk(17)).Times(1);
EXPECT_CALL(si, AddMilkFoam(17)).Times(1);
EXPECT_CALL(si, AddWater(70, 90)).Times(1);

cm.CreateCoffee(Cup::Big, Coffee::Latte);
}

TEST(CoffeeMachine, MarochinoCallsImportantThings)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(::testing::_)).Times(1);
EXPECT_CALL(si, SetCupSize(::testing::_)).Times(1);
EXPECT_CALL(si, AddChocolate(::testing::_)).Times(1);
EXPECT_CALL(si, AddMilkFoam(::testing::_)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Marochino);
}
TEST(CoffeeMachine, Marochino)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(25)).Times(1);
EXPECT_CALL(si, SetCupSize(100)).Times(1);
EXPECT_CALL(si, AddChocolate(25)).Times(1);
EXPECT_CALL(si, AddMilkFoam(25)).Times(1);

cm.CreateCoffee(Cup::Normal, Coffee::Marochino);
}
TEST(CoffeeMachine, BigMarochino)
{
MockSourceOfIngredients si;
CoffeeMachine cm(si);

EXPECT_CALL(si, AddCoffee(35)).Times(1);
EXPECT_CALL(si, SetCupSize(140)).Times(1);
EXPECT_CALL(si, AddChocolate(35)).Times(1);
EXPECT_CALL(si, AddMilkFoam(35)).Times(1);

cm.CreateCoffee(Cup::Big, Coffee::Marochino);
}
Loading