Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6504f38
RED
Oct 2, 2018
1fba6ce
RED
Oct 2, 2018
c035067
Green
Oct 2, 2018
b795886
Red
Oct 2, 2018
553eac2
Green
Oct 2, 2018
6e72467
Red
Oct 2, 2018
03397dd
Green
Oct 2, 2018
35d5e67
Green
Oct 2, 2018
c823ffb
Green
Oct 2, 2018
1161ec0
Red
Oct 10, 2018
20c6e9d
Green
Oct 10, 2018
5a8042e
Red
Oct 10, 2018
86ac94c
Green
Oct 10, 2018
d3940b8
Red
Oct 10, 2018
37b3eca
Green
Oct 10, 2018
420c40f
Refactored
Oct 10, 2018
bce290f
Red
Oct 10, 2018
d7cec8e
Green
Oct 10, 2018
826c85e
Red
Oct 10, 2018
dba60a2
Green
Oct 10, 2018
8a30a05
Green
Oct 10, 2018
9ebf07f
RED
Oct 17, 2018
19f4597
GREEN
Oct 17, 2018
ac52868
RED
Oct 17, 2018
e2af60a
GREEN
Oct 17, 2018
ff3a01f
REFACTORING
Oct 17, 2018
42618c4
RED
Oct 17, 2018
2bba6aa
GREEN
Oct 17, 2018
a2bfbbc
REFACTORED
Oct 17, 2018
7682935
GREEN wrongNumber
Oct 17, 2018
02f2d9c
GREEN EmptyDigit
Oct 17, 2018
9c8e787
RED
Oct 17, 2018
d210926
GREEN
Oct 17, 2018
6b11693
RED
Oct 17, 2018
77c0cc5
RED Change test. So large step.
Oct 17, 2018
1dba3c5
GREEN
Oct 17, 2018
cd01843
GREEN largeDisplay
Oct 17, 2018
0ff6185
RED
Oct 17, 2018
379997a
GREEN
Oct 17, 2018
b4bcbf1
RED
Oct 17, 2018
8988a66
GREEN
Oct 17, 2018
210e8a5
REFACTORING
Oct 17, 2018
f937abc
RED
Oct 17, 2018
0de9281
GREEN
Oct 17, 2018
3e9433d
GREEN wrongDisplay
Oct 17, 2018
523f777
RED
Oct 17, 2018
b3d1000
GREEN
Oct 17, 2018
c7b9832
RED
Oct 17, 2018
ed19e63
GREEN
Oct 17, 2018
b484a4b
REFACTORING
Oct 17, 2018
f10a8dd
GREEN
Oct 17, 2018
679c5d5
Add files
Oct 31, 2018
c54eeb7
Red
Oct 31, 2018
007198d
Green
Oct 31, 2018
f304f56
Red
Oct 31, 2018
ea0ca2f
Green
Oct 31, 2018
c762106
Red
Oct 31, 2018
ea9cb40
Green
Oct 31, 2018
6721c9f
Final Green test
Oct 31, 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
44 changes: 44 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,47 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>

bool LeapYear(int year)
{
if (year%400 == 0)
{
return true;
}
if (year%100 == 0)
{
return false;
}
if (year%4 == 0)
{
return true;
}
return false;
}

TEST(LeapYear, DevidedBy4)
{
ASSERT_TRUE(LeapYear(4));
}

TEST(LeapYear, DevidedBy100)
{
ASSERT_FALSE(LeapYear(100));
}

TEST(LeapYear, DevidedBy400)
{
ASSERT_TRUE(LeapYear(400));
}

TEST(LeapYear, RandomYearsTest)
{
ASSERT_TRUE(LeapYear(2000));
ASSERT_FALSE(LeapYear(1000));
ASSERT_TRUE(LeapYear(1996));
ASSERT_FALSE(LeapYear(1997));
ASSERT_TRUE(LeapYear(2020));
ASSERT_FALSE(LeapYear(2018));
ASSERT_TRUE(LeapYear(-2000));
ASSERT_FALSE(LeapYear(-1000));
}
58 changes: 58 additions & 0 deletions tdd_intro/homework/02_ternary_numbers/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,61 @@ 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.
*/

#include <gtest/gtest.h>

int OneSignDemicalView(const std::string& oneSign)
{
if (oneSign == "1" || oneSign == "2" || oneSign == "0")
{

return std::stoi( oneSign );
}
return -1;
}

int DemicalView(const std::string& str)
{
if (str.empty())
{
return 0;
}
int answer = 0;
for(size_t i = 1; i <= str.size(); ++i)
{
answer += OneSignDemicalView(str.substr(str.size() - i , 1)) * pow(3, i - 1) ;
}
return (answer > 0) ? answer : 0;
}

TEST(TernaryNumbers, EmptyString)
{
ASSERT_EQ(0, DemicalView(""));
}

TEST(TernaryNumbers, EqualOne)
{
ASSERT_EQ(1, DemicalView("1"));
}

TEST(TernaryNumbers, EqualTwo)
{
ASSERT_EQ(2, DemicalView("2"));
}

TEST(TernaryNumbers, TwoSignString01)
{
ASSERT_EQ(1, DemicalView("01"));
}


TEST(TernaryNumbers, TwoSignString11)
{
ASSERT_EQ(4, DemicalView("11"));
}


TEST(TernaryNumbers, SpecifcationTest)
{
ASSERT_EQ(302, DemicalView("102012"));
}
198 changes: 198 additions & 0 deletions tdd_intro/homework/03_bank_ocr/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Example input and output
*/
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include <iterator>

const unsigned short g_linesInDigit = 3;
struct Digit
Expand Down Expand Up @@ -139,6 +141,10 @@ const Digit s_digit9 = { " _ ",
"|_|",
" _|"
};
const Digit s_noDigit = { " _ ",
"|_|",
" _ "
};

const Display s_displayAll0 = { " _ _ _ _ _ _ _ _ _ ",
"| || || || || || || || || |",
Expand Down Expand Up @@ -194,3 +200,195 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ",
" | _| _||_||_ |_ ||_||_|",
" ||_ _| | _||_| ||_| _|"
};
const Display s_wrongDisplay = { " _ _ _ _ _ _ _ _ _ ",
"|_||_||_||_||_||_||_||_||_|",
" _| _| _| _ _| _| _| _| _|"
};

// parse 1 number 0-9
// right numbers
// wrong numbers
// empty digit

// parse line
// more than 27 symbols in string
// less than 27 symbols in string
// 27 symbols in string

// parse several structs



// assumptions:
// one function, take vector of Display and return vector of string
// second function, take 1 Display and return one string with 9 digit.
// third function, take 1 Digit and return one int.
// No information about wrong entry*

bool CompareDigits(const Digit& left, const Digit& right)
{
return left.lines[0] == right.lines[0] && left.lines[1] == right.lines[1] && left.lines[2] == right.lines[2];
}

int ZipNumberParser(const Digit& digit)
{
std::vector<Digit> allNumbers;
allNumbers.reserve(10);
allNumbers.push_back(s_digit0);
allNumbers.push_back(s_digit1);
allNumbers.push_back(s_digit2);
allNumbers.push_back(s_digit3);
allNumbers.push_back(s_digit4);
allNumbers.push_back(s_digit5);
allNumbers.push_back(s_digit6);
allNumbers.push_back(s_digit7);
allNumbers.push_back(s_digit8);
allNumbers.push_back(s_digit9);

for (int i = 0; i < allNumbers.size(); ++i)
{
if ( CompareDigits(digit, allNumbers[i]) )
{
return i;
}
}
return -1;
}

std::string ZipLineParser(const Display& display)
{
if (display.lines[0].size() != 27 || display.lines[1].size() != 27 || display.lines[2].size() != 27)
{
return "-1";
}
std::string answer="";
for(int i = 0; i < 27; i+=3)
{
Digit tempDigit{ std::string(display.lines[0].begin() + i,display.lines[0].begin()+3 + i),
std::string(display.lines[1].begin() + i,display.lines[1].begin()+3 + i),
std::string(display.lines[2].begin() + i,display.lines[2].begin()+3 + i)};
int temp = ZipNumberParser(tempDigit);
if(temp == -1)
{
return "-1";
}
else
{
answer = answer + std::to_string(temp);
}
}
return answer;
}

std::vector<std::string> ZipVectorParser(std::vector<Display> displays)
{
std::vector<std::string> answer;
for(auto disp:displays)
{
answer.push_back(ZipLineParser(disp));
}
return answer;
}


TEST(Bank, NumberZero)
{
ASSERT_EQ(0, ZipNumberParser(s_digit0));
}

TEST(Bank, NumberOne)
{
ASSERT_EQ(1, ZipNumberParser(s_digit1));
}

TEST(Bank, NumberThree)
{
ASSERT_EQ(3, ZipNumberParser(s_digit3));
}

TEST(Bank, WrongNumber)
{
ASSERT_EQ(-1, ZipNumberParser(s_noDigit));
}

TEST(Bank, EmptyDigit)
{
const Digit emptyDigit{"", "", ""};
ASSERT_EQ(-1, ZipNumberParser(emptyDigit));
}

TEST(Bank, LineOfZero)
{
ASSERT_EQ("000000000", ZipLineParser(s_displayAll0));
}

TEST(Bank, emptyDisplay)
{
Display emptyDisplay{"", "", ""};
ASSERT_EQ("-1", ZipLineParser(emptyDisplay));
}

TEST(Bank, largeDisplay)
{
Display largeDisplay{"______________________________",
"___________________________",
"___________________________"};
ASSERT_EQ("-1", ZipLineParser(largeDisplay));
}
TEST(Bank, LineOf1)
{
ASSERT_EQ("111111111", ZipLineParser(s_displayAll1));
}

TEST(Bank, LineOf2)
{
ASSERT_EQ("222222222", ZipLineParser(s_displayAll2));
}

TEST(Bank, Line123456789)
{
ASSERT_EQ("123456789", ZipLineParser(s_display123456789));
}

TEST(Bank, WrongDispley)
{
ASSERT_EQ("-1", ZipLineParser(s_wrongDisplay));
}

TEST(Bank, TwoLines)
{
std::vector<Display> linesOfDisplay;
linesOfDisplay.push_back(s_displayAll0);
linesOfDisplay.push_back(s_displayAll1);
std::vector<std::string> answer;
answer.push_back("000000000");
answer.push_back("111111111");
ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay));
}

TEST(Bank, ThreeLines)
{
std::vector<Display> linesOfDisplay;
linesOfDisplay.push_back(s_displayAll0);
linesOfDisplay.push_back(s_displayAll1);
linesOfDisplay.push_back(s_display123456789);
std::vector<std::string> answer;
answer.push_back("000000000");
answer.push_back("111111111");
answer.push_back("123456789");
ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay));
}

TEST(Bank, ThreeLinesWithWrongDisplay)
{
std::vector<Display> linesOfDisplay;
linesOfDisplay.push_back(s_displayAll0);
linesOfDisplay.push_back(s_wrongDisplay);
linesOfDisplay.push_back(s_display123456789);
std::vector<std::string> answer;
answer.push_back("000000000");
answer.push_back("-1");
answer.push_back("123456789");
ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay));
}

9 changes: 9 additions & 0 deletions tdd_intro/homework/05_word_wrapp/05_word_wrapp.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(../../gtest.pri)

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

SOURCES += \
test.cpp
Loading