Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
f0dc6d8
First test
alexchernysh92 Oct 31, 2018
ef5f02c
Green
alexchernysh92 Oct 31, 2018
7808524
Refactoring
alexchernysh92 Oct 31, 2018
62d0f6d
Red
alexchernysh92 Oct 31, 2018
44b9696
Green
alexchernysh92 Oct 31, 2018
de71170
refactoring
alexchernysh92 Oct 31, 2018
0cfe902
Read
alexchernysh92 Oct 31, 2018
93dd7e4
Green
alexchernysh92 Oct 31, 2018
56f373b
Refactoring
alexchernysh92 Oct 31, 2018
de62609
Green
alexchernysh92 Oct 31, 2018
c54701b
WS#2 added word count demo project
mokychandrey Nov 2, 2018
b020cff
First red test
alexchernysh92 Nov 9, 2018
2e932c2
Green
alexchernysh92 Nov 9, 2018
a22a075
Refactoring
alexchernysh92 Nov 9, 2018
aa48d05
Red
alexchernysh92 Nov 9, 2018
47c09e6
Green
alexchernysh92 Nov 9, 2018
cfcbb1d
Red
alexchernysh92 Nov 9, 2018
c6d369a
Green
alexchernysh92 Nov 9, 2018
c4d0e8d
Refactoring
alexchernysh92 Nov 9, 2018
1b77c23
Red
alexchernysh92 Nov 9, 2018
66d9de7
Green
alexchernysh92 Nov 9, 2018
e904716
Added several green tests
alexchernysh92 Nov 9, 2018
f1b20f5
AcceptanceTest
alexchernysh92 Nov 9, 2018
4080ca5
Refactoring tests
alexchernysh92 Nov 9, 2018
0e34d7e
Red
alexchernysh92 Nov 13, 2018
98552d9
Green + refactoring
alexchernysh92 Nov 13, 2018
fb09975
Red
alexchernysh92 Nov 13, 2018
99cdcdd
Green
alexchernysh92 Nov 13, 2018
a90cf74
Refactoring
alexchernysh92 Nov 13, 2018
9ff8ab3
Red
alexchernysh92 Nov 13, 2018
3cd4607
Green
alexchernysh92 Nov 13, 2018
9b15365
Refactoring
alexchernysh92 Nov 14, 2018
c8073c7
Red
alexchernysh92 Nov 14, 2018
944f4c7
Green
alexchernysh92 Nov 14, 2018
a004cfc
Added some test
alexchernysh92 Nov 14, 2018
afdf9fb
Added some test
alexchernysh92 Nov 14, 2018
456014f
Refactoring
alexchernysh92 Nov 14, 2018
f417ef6
Red
alexchernysh92 Nov 14, 2018
6f1e44a
Green
alexchernysh92 Nov 14, 2018
d4daf34
Red
alexchernysh92 Nov 14, 2018
c8c79c7
Green
alexchernysh92 Nov 14, 2018
23dea11
Refactoring
alexchernysh92 Nov 14, 2018
73f188e
Red
alexchernysh92 Nov 14, 2018
858047c
Green
alexchernysh92 Nov 14, 2018
967c443
Red
alexchernysh92 Nov 14, 2018
550d7fd
Refactoring
alexchernysh92 Nov 14, 2018
1a58753
Red + Green
alexchernysh92 Nov 14, 2018
ef3ee18
Red
alexchernysh92 Nov 14, 2018
a220bac
Green
alexchernysh92 Nov 14, 2018
3068f7d
Red
alexchernysh92 Nov 14, 2018
f072293
Green
alexchernysh92 Nov 14, 2018
272870e
Added test
alexchernysh92 Nov 14, 2018
a97542a
Red
alexchernysh92 Nov 14, 2018
14f8f04
Green
alexchernysh92 Nov 14, 2018
7fa9305
AcceptanceTest
alexchernysh92 Nov 14, 2018
a719696
Refactoring
alexchernysh92 Nov 14, 2018
532681f
First red test
alexchernysh92 Nov 22, 2018
70c89b5
green
alexchernysh92 Nov 22, 2018
e0859a2
Refactoring + red test
alexchernysh92 Nov 22, 2018
73da9dc
Green
alexchernysh92 Nov 22, 2018
d834675
Red
alexchernysh92 Nov 22, 2018
82e6d50
Green
alexchernysh92 Nov 22, 2018
34862d7
Refactoring
alexchernysh92 Nov 22, 2018
6ec87e2
Red
alexchernysh92 Nov 22, 2018
ca60ec4
Green
alexchernysh92 Nov 22, 2018
8a3099d
Refactoring + next Redtest
alexchernysh92 Nov 22, 2018
fb6d2f2
Green
alexchernysh92 Nov 22, 2018
6c1fbe7
Red
alexchernysh92 Nov 22, 2018
1be25c4
Green
alexchernysh92 Nov 22, 2018
3e857a5
Refactoring
alexchernysh92 Nov 22, 2018
f121f21
Red
alexchernysh92 Nov 22, 2018
c512957
Green
alexchernysh92 Nov 22, 2018
441f249
Merge pull request #3 from Alexandr1992/BankOCR
Nov 22, 2018
b2c20c7
Merge pull request #4 from Alexandr1992/BankOCR
Nov 29, 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
10 changes: 10 additions & 0 deletions tdd_intro/demo/02_word_count/02_word_count.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(../../gtest.pri)

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
test.cpp

132 changes: 132 additions & 0 deletions tdd_intro/demo/02_word_count/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
Given a phrase, count the occurrences of each word in that phrase. Ignore whitespaces and punctual symbols
For example for the input "olly olly in come free please please let it be in such manner olly"
olly: 3
in: 2
come: 1
free: 1
please: 2
let: 1
it: 1
be: 1
manner: 1
such: 1
*/

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

using words_mt = std::map<std::string, size_t>;
const static char wordSeparator = ' ';

bool TrimWord(std::string& phrase, std::string& word, const char seperator)
{
if (phrase.empty())
{
return false;
}

size_t index = phrase.find_first_of(seperator);
if (index == std::string::npos || index == phrase.size())
{
word = phrase;
phrase.clear();
}
else
{
word = phrase.substr(0, index);
phrase = phrase.substr(index + 1, phrase.size() - index);
}

return true;
}

words_mt SeparateWords(const std::string& phrase)
{
words_mt words;
std::string currentPhrase = phrase;
std::string curentWord;

while (TrimWord(currentPhrase, curentWord, wordSeparator))
{
++words[curentWord];
}

return words;
}

TEST(WordsCount, TestSeparateFirstWord)
{
words_mt words = SeparateWords("hello");
EXPECT_EQ(1, words.size());
EXPECT_TRUE(words.find("hello") != words.end());
EXPECT_EQ(1, words["hello"]);
}

TEST(WordsCount, TestTrimOneWord)
{
std::string phrase = "tdd course";
std::string word;
EXPECT_TRUE(TrimWord(phrase, word, ' '));
EXPECT_EQ("course", phrase);

EXPECT_TRUE(TrimWord(phrase, word, ' '));
EXPECT_EQ("", phrase);

EXPECT_FALSE(TrimWord(phrase, word, ' '));
}

TEST(WordsCount, TestCountSeveralDifferentWords)
{
words_mt words = SeparateWords("hello bro");
EXPECT_EQ(2, words.size());

EXPECT_TRUE(words.find("hello") != words.end());
EXPECT_EQ(1, words["hello"]);

EXPECT_TRUE(words.find("bro") != words.end());
EXPECT_EQ(1, words["bro"]);
}

TEST(WordsCount, TestCountSeveralSameWords)
{
words_mt words = SeparateWords("hello bro hello");

EXPECT_EQ(2, words.size());
EXPECT_TRUE(words.find("hello") != words.end());
EXPECT_EQ(2, words["hello"]);
}

TEST(WordsCount, TestNoWordsWhenEmptyInput)
{
words_mt words = SeparateWords("");
EXPECT_TRUE(words.empty());
}

TEST(WordsCount, TestOneWordWhenSeparatorInEnd)
{
words_mt words = SeparateWords("hello ");

EXPECT_EQ(1, words.size());
EXPECT_TRUE(words.find("hello") != words.end());
EXPECT_EQ(1, words["hello"]);
}

TEST(WordsCount, AcceptanceTest)
{
words_mt words = SeparateWords("olly olly in come free please please let it be in such manner olly");

ASSERT_EQ(10, words.size());

ASSERT_EQ(3, words["olly"]);
ASSERT_EQ(2, words["in"]);
ASSERT_EQ(1, words["come"]);
ASSERT_EQ(1, words["free"]);
ASSERT_EQ(2, words["please"]);
ASSERT_EQ(1, words["let"]);
ASSERT_EQ(1, words["it"]);
ASSERT_EQ(1, words["be"]);
ASSERT_EQ(1, words["manner"]);
ASSERT_EQ(1, words["such"]);
}
1 change: 1 addition & 0 deletions tdd_intro/demo/demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SUBDIRS += \
01_bob \
01_fizz_buzz \
02_anagram \
02_word_count \
#03_allergies \
03_roman_numerals \
04_timer
55 changes: 55 additions & 0 deletions tdd_intro/homework/01_leap_year/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,58 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>


const size_t g_four = 4;
const size_t g_oneHundred = 100;
const size_t g_fourHundred = g_four * g_oneHundred;

bool isDivisible(size_t number, size_t divider)
{
return number % divider == 0;
}

bool IsLeapYear(size_t year)
{
if (isDivisible(year, g_fourHundred))
{
return true;
}
if (isDivisible(year, g_oneHundred))
{
return false;
}
if (isDivisible(year, g_four))
{
return true;
}

return false;
}

TEST(LeapYear, TestDivisible400)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает непосредственно ожидания - понятно, что он проверяет кратность 400, но непонятно что должно стать с таким числом - каково ожидаемое поведение

{
EXPECT_TRUE(IsLeapYear(g_fourHundred));
EXPECT_TRUE(IsLeapYear(g_fourHundred * 2));
EXPECT_TRUE(IsLeapYear(g_fourHundred * 3));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличное дополнение теста 👍 (но название немного портит картину ))

}

TEST(LeapYear, TestDivisible4AndNot100)
{
EXPECT_TRUE(IsLeapYear(104));
EXPECT_TRUE(IsLeapYear(404));
EXPECT_TRUE(IsLeapYear(2008));
EXPECT_TRUE(IsLeapYear(2012));
}

TEST(LeapYear, TestDivisible100)
{
EXPECT_FALSE(IsLeapYear(g_oneHundred));
EXPECT_FALSE(IsLeapYear(g_oneHundred * 5));
}

TEST(LeapYear, TestNotDivisible4_400_100)
{
EXPECT_FALSE(IsLeapYear(333));
EXPECT_FALSE(IsLeapYear(555));
}
71 changes: 71 additions & 0 deletions tdd_intro/homework/02_ternary_numbers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <gtest/gtest.h>
#include <cmath>
#include <string>

/*
Convert a ternary number, represented as a string (e.g. '102012'), to its decimal equivalent using first principles.
Expand All @@ -16,3 +18,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.
*/

size_t ConvertTernaryToDecimal(size_t numerical, size_t position)
{
if(numerical > 2)
{
return 0;
}

double ternaryPow = std::pow(3, position);
return static_cast<size_t>(ternaryPow) * numerical;
}

size_t ConvertTernaryToDecimal(const std::string& ternary)
{
size_t result = 0;
size_t position = ternary.size();
for (const char ternarySymbChar: ternary)
{
int ternaryNumb = std::atoi(&ternarySymbChar);
result += ConvertTernaryToDecimal(static_cast<size_t>(ternaryNumb), --position);
}

return result;
}

TEST(TernaryNumber, TestConvertTernaryNum_Pos0_ToDecimal)
{
EXPECT_EQ(0, ConvertTernaryToDecimal(0, 0));
EXPECT_EQ(1, ConvertTernaryToDecimal(1, 0));
EXPECT_EQ(2, ConvertTernaryToDecimal(2, 0));
}

TEST(TernaryNumber, TestConvertTernaryNum_Larger0_ToDecimal)
{
EXPECT_EQ(3, ConvertTernaryToDecimal(1, 1));
EXPECT_EQ(0, ConvertTernaryToDecimal(0, 2));
EXPECT_EQ(54, ConvertTernaryToDecimal(2, 3));
}

TEST(TernaryNumber, TestConvertInvalidTernary)
{
EXPECT_EQ(0, ConvertTernaryToDecimal(4, 0));
EXPECT_EQ(0, ConvertTernaryToDecimal(5, 0));
EXPECT_EQ(0, ConvertTernaryToDecimal(20, 0));
}

TEST(TernaryNumber, TestConvertOneTernaryNumericalStrToDecimal)
{
EXPECT_EQ(0, ConvertTernaryToDecimal("0"));
EXPECT_EQ(1, ConvertTernaryToDecimal("1"));
EXPECT_EQ(2, ConvertTernaryToDecimal("2"));
EXPECT_EQ(0, ConvertTernaryToDecimal("3"));
}

TEST(TernaryNumber, TestConvertTernaryStrToDecimal)
{
EXPECT_EQ(302, ConvertTernaryToDecimal("102012"));
}

TEST(TernaryNumber, TestEmptyTernaryString)
{
EXPECT_EQ(0, ConvertTernaryToDecimal(""));
}

TEST(TernaryNumber, TestIncorrectTernaryNumberInString)
{
EXPECT_EQ(302, ConvertTernaryToDecimal("192612"));
EXPECT_EQ(302, ConvertTernaryToDecimal("1*2%12"));
}
Loading