Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
4e12935
Red test (Test for Odd numbers).
krisanovdev Sep 30, 2018
3b9b0e9
Green test (Test for Odd numbers).
krisanovdev Sep 30, 2018
1744071
Red test (Test for numbers that devisible by 400).
krisanovdev Sep 30, 2018
7bd7fca
Green test (Test for numbers that devisible by 400).
krisanovdev Sep 30, 2018
bfa4b73
Red Test
krisanovdev Sep 30, 2018
84ea9db
Green test
krisanovdev Sep 30, 2018
c70e9f3
Red Test
krisanovdev Sep 30, 2018
4b16832
Green Test
krisanovdev Sep 30, 2018
5aa8007
Refactoring.
krisanovdev Sep 30, 2018
a213436
Acceptance test.
krisanovdev Sep 30, 2018
dbb50e3
Small final refactoring.
krisanovdev Sep 30, 2018
eff64d9
Merge remote-tracking branch 'upstream/master'
krisanovdev Oct 10, 2018
3930208
Red
krisanovdev Oct 10, 2018
a3bb0e9
Green
krisanovdev Oct 10, 2018
b515066
Red
krisanovdev Oct 10, 2018
7f60cfa
Green.
krisanovdev Oct 10, 2018
0a2094c
Red
krisanovdev Oct 10, 2018
8f9899d
green
krisanovdev Oct 10, 2018
a75569d
Refactoring.
krisanovdev Oct 10, 2018
f7533fd
Red
krisanovdev Oct 10, 2018
3cc14e6
Green.
krisanovdev Oct 10, 2018
9e55f9f
Refactoring (summarized cases with lenght = 1 and lenght = 2).
krisanovdev Oct 10, 2018
93bed2e
RED
krisanovdev Oct 10, 2018
bf839de
Green.
krisanovdev Oct 10, 2018
196f707
RED.
krisanovdev Oct 10, 2018
9044c1d
Green.
krisanovdev Oct 10, 2018
35c45b3
Refactoring.
krisanovdev Oct 10, 2018
1e556e4
Forgot to build tests - fix problem (GREEN).
krisanovdev Oct 10, 2018
e2dcb1b
Acceptance
krisanovdev Oct 10, 2018
4b79407
Final refactoring.
krisanovdev Oct 10, 2018
a537402
Test list.
krisanovdev Oct 17, 2018
edfa61f
Red
krisanovdev Oct 17, 2018
44af337
Green.
krisanovdev Oct 17, 2018
aa2b61d
Red.
krisanovdev Oct 17, 2018
607b641
Green.
krisanovdev Oct 17, 2018
cc01447
Triangulation.
krisanovdev Oct 17, 2018
a331c51
Red.
krisanovdev Oct 17, 2018
f4a0732
Green.
krisanovdev Oct 17, 2018
0509c22
Red.
krisanovdev Oct 17, 2018
20d13fd
Green.
krisanovdev Oct 17, 2018
21bdd1c
Red.
krisanovdev Oct 17, 2018
05666e2
Green (with fix of test).
krisanovdev Oct 17, 2018
3095775
test list)
krisanovdev Oct 24, 2018
6058f1f
Red.
krisanovdev Oct 24, 2018
bcf5c50
forgot something (still red).
krisanovdev Oct 24, 2018
b95360d
Green.
krisanovdev Oct 24, 2018
0dfbc26
Red.
krisanovdev Oct 24, 2018
aed731d
Green.
krisanovdev Oct 24, 2018
1864c44
Red.
krisanovdev Oct 24, 2018
0ced762
Green.
krisanovdev Oct 24, 2018
8b479d2
Red.
krisanovdev Oct 24, 2018
402e7ac
Green.
krisanovdev Oct 24, 2018
6b39a61
Red.
krisanovdev Oct 24, 2018
a1f2c36
Green.
krisanovdev Oct 24, 2018
3780eb3
Red.
krisanovdev Oct 24, 2018
d3b8e9d
Implemented helpful things (still red).
krisanovdev Oct 24, 2018
8d20e88
Green.
krisanovdev Oct 24, 2018
c85fcd7
Refactoring.
krisanovdev Oct 24, 2018
634e0dc
Refactoring.
krisanovdev Oct 24, 2018
c823a10
Refactoring.
krisanovdev Oct 24, 2018
77d9204
Fixed behavior of fake server (in case of invalid request).
krisanovdev Oct 24, 2018
eb1de2c
Red.
krisanovdev Oct 24, 2018
ad73c86
Green.
krisanovdev Oct 24, 2018
80e7099
Red.
krisanovdev Oct 24, 2018
a7badbb
Green.
krisanovdev Oct 24, 2018
4b7f893
Refactoring.
krisanovdev Oct 24, 2018
c1e6668
Red.
krisanovdev Oct 24, 2018
6b4057c
Green.
krisanovdev Oct 24, 2018
9ae5298
Red.
krisanovdev Oct 24, 2018
fa01dae
Green.
krisanovdev Oct 24, 2018
fbe700c
Refactoring.
krisanovdev Oct 24, 2018
755b935
Merge remote-tracking branch 'upstream/master'
krisanovdev Nov 1, 2018
9c6fd82
Red.
krisanovdev Nov 1, 2018
8c4d507
Green.
krisanovdev Nov 1, 2018
f62436e
Red.
krisanovdev Nov 1, 2018
c3d03c1
Green.
krisanovdev Nov 1, 2018
757ed56
refactoring.
krisanovdev Nov 1, 2018
d8c6e1e
Refactoring + acceptance.
krisanovdev Nov 1, 2018
3749c0a
add test from list (GREEN).
krisanovdev Nov 1, 2018
69fcb93
Merge remote-tracking branch 'upstream/master'
krisanovdev Nov 14, 2018
e7cd3ab
Red.
krisanovdev Nov 14, 2018
b216fc0
Forgot that the last test was red. Fixed. (GREEN).
krisanovdev Nov 14, 2018
0a6491c
Refactoring.
krisanovdev Nov 14, 2018
24fbc6a
Red.
krisanovdev Nov 14, 2018
64e4154
Green.
krisanovdev Nov 14, 2018
bcbe079
Red.
krisanovdev Nov 14, 2018
97cff32
Green.
krisanovdev Nov 14, 2018
d25e52c
Refactoring.
krisanovdev Nov 14, 2018
53af558
Red.
krisanovdev Nov 14, 2018
335a471
Green.
krisanovdev Nov 14, 2018
30bb820
Red.
krisanovdev Nov 14, 2018
ad2e550
Green.
krisanovdev Nov 14, 2018
c9b6046
Red.
krisanovdev Nov 14, 2018
39561ac
Green.
krisanovdev Nov 14, 2018
4d259b7
Red.
krisanovdev Nov 14, 2018
899c191
Green.
krisanovdev Nov 14, 2018
a0987f9
Removed dummy tests.
krisanovdev Nov 14, 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
43 changes: 43 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,46 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>

bool IsLeap(size_t year)
{
if (year % 400 != 0 && year % 100 == 0)
{
return false;
}

return year % 4 == 0;
}

TEST(IsLeap, ReturnFalseForOddYears)
{
ASSERT_FALSE(IsLeap(1901));
}

TEST(IsLeap, ReturnTrueIfDevisibleBy400)
{
ASSERT_TRUE(IsLeap(1600));
}

TEST(IsLeap, ReturnTrueIfDevisibleBy4AndNotDevisibleBy100)
{
ASSERT_TRUE(IsLeap(1804));
}

TEST(IsLeap, ReturnFalseIfDevisibleBy100AndNotDivisibleBy400)
{
ASSERT_FALSE(IsLeap(1900));
}

TEST(IsLeap, AcceptanceTest)
{
ASSERT_TRUE(IsLeap(4));
ASSERT_TRUE(IsLeap(1604));
ASSERT_TRUE(IsLeap(400));
ASSERT_TRUE(IsLeap(2000));

ASSERT_FALSE(IsLeap(1));
ASSERT_FALSE(IsLeap(1701));
ASSERT_FALSE(IsLeap(1700));
ASSERT_FALSE(IsLeap(1900));
}
75 changes: 75 additions & 0 deletions tdd_intro/homework/02_ternary_numbers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <cctype>

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

int ConvertToTernary(const std::string& number)
{
const size_t inputSize = number.size();
size_t result = 0;

for (size_t i = 1; i <= inputSize; ++i)
{
const char current = number[inputSize - i];
if (!isdigit(current))
{
return 0;
}

std::string curCharStr;
curCharStr += current;

int curNumber = 0;
if ((curNumber = std::atoi(curCharStr.c_str())) > 2)
{
return 0;
}

result += static_cast<size_t>(pow(3, i - 1) * curNumber);
}

return result;
}

TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter)
{
EXPECT_EQ(ConvertToTernary("a"), 0);
}

TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1)
{
EXPECT_EQ(ConvertToTernary("1"), 1);
}

TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1_2)
{
EXPECT_EQ(ConvertToTernary("2"), 2);
}

TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals2)
{
EXPECT_EQ(ConvertToTernary("10"), 3);
}

TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_2)
{
EXPECT_EQ(ConvertToTernary("1a2b"), 0);
}

TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_3)
{
EXPECT_EQ(ConvertToTernary("53"), 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

достаточно было бы ConvertToTernary("3")

}

TEST (ConvertToTernary, AcceptanceTests)
{
EXPECT_EQ(ConvertToTernary("202"), 20);
EXPECT_EQ(ConvertToTernary("2201"), 73);
EXPECT_EQ(ConvertToTernary("12"), 5);

EXPECT_EQ(ConvertToTernary("abc"), 0);
EXPECT_EQ(ConvertToTernary("d1hj"), 0);

EXPECT_EQ(ConvertToTernary("4356"), 0);
EXPECT_EQ(ConvertToTernary("7"), 0);

EXPECT_EQ(ConvertToTernary("a31"), 0);
EXPECT_EQ(ConvertToTernary("zr5"), 0);
}
204 changes: 204 additions & 0 deletions tdd_intro/homework/03_bank_ocr/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,207 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ",
" | _| _||_||_ |_ ||_||_|",
" ||_ _| | _||_| ||_| _|"
};

/*
* test list :
* throws if empty file
* throws if not each line 27 long
* throws if line count mod 3 != 0
* throws in case of invalid number form
* successful conversation (one id)
* successful conversation (two id's)
* successful conversation (unlimited size)
*/

class EmptyFileError : public std::runtime_error
{
public:
EmptyFileError(const char* what)
: std::runtime_error(what)
{}
};

class LenghtError : public std::runtime_error
{
public:
LenghtError(const char* what)
: std::runtime_error(what)
{}
};

class LineCountError : public std::runtime_error
{
public:
LineCountError(const char* what)
: std::runtime_error(what)
{}
};

class NumberFormatError : public std::runtime_error
{
public:
NumberFormatError(const char* what)
: std::runtime_error(what)
{}
};

std::vector<std::string> SplitByLines(const std::string& strToSplit)
{
std::stringstream ss(strToSplit);
std::string item;
std::vector<std::string> splittedStrings;
while (std::getline(ss, item, '\n'))
{
if (item.size() != 27)
{
throw LenghtError("OOPS");
Copy link
Collaborator

Choose a reason for hiding this comment

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

только этот кейс мог быть вынесен в отдельную ф-ю, т.к. во внешней функции реализован только он.

}

splittedStrings.push_back(item);
}
return splittedStrings;
}

bool operator == (const Digit& lhs, const Digit& rhs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не по ТДД

{
bool equals = true;
for (size_t i = 0; i < 3; ++i)
{
equals = equals && lhs.lines[i] == rhs.lines[i];
}

return equals;
}

size_t GetDigit(const Digit& digit)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не по ТДД

{
if (digit == s_digit0)
{
return 0;
}
if (digit == s_digit1)
{
return 1;
}
if (digit == s_digit2)
{
return 2;
}
if (digit == s_digit3)
{
return 3;
}
if (digit == s_digit4)
{
return 4;
}
if (digit == s_digit5)
{
return 5;
}
if (digit == s_digit6)
{
return 6;
}
if (digit == s_digit7)
{
return 7;
}
if (digit == s_digit8)
{
return 8;
}
if (digit == s_digit9)
{
return 9;
}

throw NumberFormatError("OOPS");
}
std::string GetNumberFromThreeStrings(const std::string& first, const std::string& second, const std::string& third)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не по ТДД

{
std::stringstream stream;
size_t pos = 0;
while (pos < 27)
{
Digit digit;
digit.lines[0] = first.substr(pos, 3);
digit.lines[1] = second.substr(pos, 3);
digit.lines[2] = third.substr(pos, 3);
stream << GetDigit(digit);
pos += 3;
}

return stream.str();
}

std::vector<std::string> SplitByNumbers(const std::vector<std::string>& lines)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не по ТДД

{
std::vector<std::string> numbers;
for (size_t i = 0; i < lines.size() / 3; ++i)
{
std::string firstLine = lines[3*i];
std::string secondLine = lines[3*i + 1];
std::string thirdLine = lines[3*i + 2];
numbers.push_back(GetNumberFromThreeStrings(firstLine, secondLine, thirdLine));
}

return numbers;
}

std::vector<std::string> ParseFile(const std::string& file)
{
if (file.empty())
{
throw EmptyFileError("empty file");
}

std::vector<std::string> lines = SplitByLines(file);

if (lines.size() % 3 != 0)
{
throw LineCountError("line count error");
}

return SplitByNumbers(lines);
}

TEST(ParseFile, ThrowsIfEmptyFile)
{
ASSERT_THROW(ParseFile(""), EmptyFileError);
}

TEST(ParseFile, ThrowsIfNotEachLine27Long)
{
ASSERT_THROW(ParseFile("abc"), LenghtError);
}

TEST(ParseFile, ThrowsIfLineCountMod3NotZero)
{
std::string file(27, '_');
file = file + '\n' + file;
ASSERT_THROW(ParseFile(file), LineCountError);
}

TEST(SplitByNumbers, ThrowsInCaseOfInvalidNumberForm)
{
std::string file(27, '_');
file = file + '\n' + file + '\n' + file;
std::vector<std::string> files {file, file, file};
ASSERT_THROW(SplitByNumbers(files), NumberFormatError);
}

TEST(SplitByNumbers, SuccessfulSplit)
{
std::vector<std::string> lines = {s_display123456789.lines[0], s_display123456789.lines[1], s_display123456789.lines[2]};
auto result = SplitByNumbers(lines);
ASSERT_EQ(result.size(), 1);
ASSERT_EQ(result[0], "123456789");
}

TEST(ParseFile, SuccessfulParse)
{
std::string file = s_display123456789.lines[0] + "\n" + s_display123456789.lines[1] + "\n" + s_display123456789.lines[2];
std::vector<std::string> result = ParseFile(file);
ASSERT_EQ(result[0], "123456789");
}
Loading