Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b995d37
Red. Empty line
Krestol Sep 14, 2018
57187da
Green. Empty line
Krestol Sep 14, 2018
c1df72a
Red. single word
Krestol Sep 14, 2018
af36297
Green single word and red empty line
Krestol Sep 14, 2018
3302c38
Test refactoring
Krestol Sep 14, 2018
4164773
Code refactoring
Krestol Sep 14, 2018
707a060
Red two different words
Krestol Sep 14, 2018
c958502
Green two different words
Krestol Sep 14, 2018
0571b47
Code refactoring
Krestol Sep 14, 2018
7e28108
Red two same words
Krestol Sep 14, 2018
1e9928b
Green two same words
Krestol Sep 14, 2018
6234fb4
Code refactoring
Krestol Sep 14, 2018
6bd527e
Red two different words with double space
Krestol Sep 14, 2018
fc77cbb
Green two different words with double space
Krestol Sep 14, 2018
4fc4129
Code refactoring
Krestol Sep 14, 2018
ad30f79
acceptance
Krestol Sep 14, 2018
1c47d5c
red. one_return_false
Krestol Sep 18, 2018
6aa614f
red. one_return_false
Krestol Sep 18, 2018
823f562
green. one_return_false
Krestol Sep 18, 2018
7fed5d4
refactoring. one_return_false
Krestol Sep 18, 2018
352734d
red. hundred_return_false
Krestol Sep 18, 2018
eb4708f
green. hundred_return_false
Krestol Sep 18, 2018
195057a
refactoring. hundred_return_false
Krestol Sep 18, 2018
f7b8dbf
red. four_hundred_return_true
Krestol Sep 18, 2018
87e1307
green. four_hundred_return_true
Krestol Sep 18, 2018
d357df4
refactoring. four_hundred_return_true
Krestol Sep 18, 2018
aab847a
acceptance
Krestol Sep 18, 2018
24aad50
red. CharToTernaryDigit input_zero
Krestol Sep 18, 2018
e13dd8b
red. CharToTernaryDigit input_zero
Krestol Sep 18, 2018
db95249
green. CharToTernaryDigit input_zero
Krestol Sep 18, 2018
43c0727
refactoring. CharToTernaryDigit input_zero
Krestol Sep 18, 2018
cc7cbd1
red. CharToTernaryDigit input_four_throw
Krestol Sep 18, 2018
382305c
green. CharToTernaryDigit input_four_throw
Krestol Sep 18, 2018
2103d5e
refactoring. CharToTernaryDigit input_four_throw
Krestol Sep 18, 2018
7e87822
red. CharToTernaryDigit input_47_throw
Krestol Sep 18, 2018
279152f
green. CharToTernaryDigit input_47_throw
Krestol Sep 18, 2018
8c827b6
refactoring. CharToTernaryDigit input_47_throw
Krestol Sep 18, 2018
e624d8e
red. StringToTernaryNumber input_zero
Krestol Sep 18, 2018
d0b0024
red. StringToTernaryNumber input_zero
Krestol Sep 18, 2018
b3e101c
green. StringToTernaryNumber input_zero
Krestol Sep 18, 2018
6b5bc44
refactoring. StringToTernaryNumber input_zero
Krestol Sep 18, 2018
1c6599e
red. StringToTernaryNumber input_empty_string
Krestol Sep 18, 2018
4e3bed4
green. StringToTernaryNumber input_empty_string
Krestol Sep 18, 2018
ffc2a92
red. StringToTernaryNumber input_10
Krestol Sep 18, 2018
aab42b7
green. StringToTernaryNumber input_10
Krestol Sep 18, 2018
bb4092a
refactoring. StringToTernaryNumber input_10
Krestol Sep 18, 2018
319bb51
refactoring. StringToTernaryNumber input_10
Krestol Sep 18, 2018
04b1343
red. StringToTernaryNumber input_invalid_string
Krestol Sep 18, 2018
7dc7c9c
green. StringToTernaryNumber input_invalid_string
Krestol Sep 18, 2018
07d862a
refactoring. StringToTernaryNumber input_invalid_string
Krestol Sep 18, 2018
19c4012
acceptance
Krestol Sep 18, 2018
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
61 changes: 61 additions & 0 deletions tdd_intro/homework/01_word_count/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,71 @@ free: 1
#include <gtest/gtest.h>
#include <map>
#include <string>
#include <sstream>

using MyMap = std::map<std::string, int>;

MyMap WordsCount(const std::string& str)
{
if (str.empty())
{
return MyMap();
}

MyMap result;

std::istringstream stream(str);
std::string token;

while(std::getline(stream, token, ' '))
{
if (!token.empty())
{
++result[token];
}
}

return result;
}


TEST(WordsCount, empty_line)
{
EXPECT_TRUE(WordsCount("").empty());
}

TEST(WordsCount, single_word)
{
const std::string singleWord = "singleWord";
MyMap expected {std::make_pair(singleWord, 1)};
EXPECT_EQ(expected, WordsCount(singleWord));
}

TEST(WordsCount, two_different_words)
{
MyMap expected {std::make_pair("word_1", 1),
std::make_pair("word_2", 1)};
EXPECT_EQ(expected, WordsCount("word_1 word_2"));
}

TEST(WordsCount, two_same_words)
{
MyMap expected {std::make_pair("word_1", 2)};
EXPECT_EQ(expected, WordsCount("word_1 word_1"));
}

TEST(WordsCount, two_different_words_with_double_space)
{
MyMap expected {std::make_pair("word_1", 1),
std::make_pair("word_2", 1)};
EXPECT_EQ(expected, WordsCount("word_1 word_2"));
}

TEST(WordsCount, acceptance)
{
MyMap expected {std::make_pair("olly", 2),
std::make_pair("in", 1),
std::make_pair("come", 1),
std::make_pair("free", 1)};
EXPECT_EQ(expected, WordsCount("olly olly in come free"));
}
28 changes: 28 additions & 0 deletions tdd_intro/homework/02_leap_year/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,31 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>

bool IsLeapYear(int year)
{
return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
}

TEST(IsYearLeap, one_return_false)
{
EXPECT_FALSE(IsLeapYear(1));
}

TEST(IsYearLeap, hundred_return_false)
{
EXPECT_FALSE(IsLeapYear(100));
}

TEST(IsYearLeap, four_hundred_return_true)
{
EXPECT_TRUE(IsLeapYear(400));
}

TEST(IsYearLeap, acceptance)
{
EXPECT_FALSE(IsLeapYear(1900));
EXPECT_TRUE(IsLeapYear(1996));
EXPECT_FALSE(IsLeapYear(1997));
EXPECT_TRUE(IsLeapYear(2000));
}
72 changes: 72 additions & 0 deletions tdd_intro/homework/02_trinary_numbers/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,75 @@ The last place in a trinary 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.
*/


int CharToTernaryDigit(char ch)
{
if (ch >= '0' && ch < '3')
{
return ch - '0';
}

throw std::runtime_error("non ternary");
}

int StringToTernaryNumber(const std::string& number)
{
int result = 0;
const int numberOfDigits = number.size() - 1;
try
{
for (int i = numberOfDigits; i >= 0; --i)
{
if (!number.empty())
{
result += CharToTernaryDigit(number[i]) * (std::pow(3, numberOfDigits - i));
}
}
}
catch (const std::runtime_error&)
{
result = 0;
}
return result;
}

TEST(CharToTernaryDigit, input_zero)
{
EXPECT_EQ(0, CharToTernaryDigit('0'));
}

TEST(CharToTernaryDigit, input_four_throw)
{
EXPECT_THROW(CharToTernaryDigit('4'), std::runtime_error);
}

TEST(CharToTernaryDigit, input_0)
{
EXPECT_THROW(CharToTernaryDigit('/'), std::runtime_error);
}

TEST(StringToTernaryNumber, input_zero)
{
EXPECT_EQ(0, StringToTernaryNumber("0"));
}

TEST(StringToTernaryNumber, input_empty_string)
{
EXPECT_EQ(0, StringToTernaryNumber(""));
}

TEST(StringToTernaryNumber, input_10)
{
EXPECT_EQ(3, StringToTernaryNumber("10"));
}

TEST(StringToTernaryNumber, input_invalid_number)
{
EXPECT_EQ(0, StringToTernaryNumber("103"));
}

TEST(StringToTernaryNumber, acceptance)
{
EXPECT_EQ(302, StringToTernaryNumber("102012"));
}