Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6cd9cd3
Red - Initial commit
Oct 4, 2018
93d36ab
Green: ordinary year
vladyslavkv Oct 4, 2018
8315bf1
Red: leap year
vladyslavkv Oct 4, 2018
9489d9b
Green: leap year
vladyslavkv Oct 4, 2018
da544fb
Red: another leap year
vladyslavkv Oct 4, 2018
f917aa4
Green: another leap year
vladyslavkv Oct 4, 2018
214c074
First Refactoring
vladyslavkv Oct 4, 2018
677eb8b
Red: derived by 100 year
vladyslavkv Oct 4, 2018
0916531
Red: derived by 100 year - fixed test
vladyslavkv Oct 4, 2018
8a2b230
Green: derived by 100 year
vladyslavkv Oct 4, 2018
e77e255
Red: derived by 400 year
vladyslavkv Oct 4, 2018
0cebc51
Green: derived by 400 year
vladyslavkv Oct 4, 2018
6730550
Red: Initial test - ordinary year
vladyslavkv Oct 4, 2018
18c2904
Green: Ordinary year
vladyslavkv Oct 4, 2018
787f8bf
Red: Leap year
vladyslavkv Oct 4, 2018
a117721
Really Red: second ordinary year
vladyslavkv Oct 4, 2018
32be5f6
Green: second ordinary year
vladyslavkv Oct 4, 2018
9b13cff
First refactoring
vladyslavkv Oct 4, 2018
20cf474
Red: ordinary year derived by 100
vladyslavkv Oct 4, 2018
f7b8aa9
Green: ordinary year derived by 100
vladyslavkv Oct 4, 2018
72f75c3
Red: leap year derived by 400
vladyslavkv Oct 4, 2018
ccc746a
Green: leap year derived by 400
vladyslavkv Oct 4, 2018
2de5f43
Second Refactoring
vladyslavkv Oct 4, 2018
25d20eb
Green: acceptance test
vladyslavkv Oct 4, 2018
d42dd8e
initial red
vladyslavkv Oct 11, 2018
24ef5c2
green
vladyslavkv Oct 11, 2018
deb4271
refactoring
vladyslavkv Oct 11, 2018
e558842
red
vladyslavkv Oct 11, 2018
21ca35e
green
vladyslavkv Oct 11, 2018
684b144
red
vladyslavkv Oct 11, 2018
1f19f56
green
vladyslavkv Oct 11, 2018
3948a2c
red
vladyslavkv Oct 11, 2018
30ad190
green
vladyslavkv Oct 11, 2018
047b1d6
refactoring
vladyslavkv Oct 11, 2018
c98b6d5
refactored
vladyslavkv Oct 14, 2018
9577126
acceptance
vladyslavkv Oct 14, 2018
175d140
Merge branch 'Dz1' of https://github.com/Vladyslavru/tdd-course-3 int…
vladyslavkv Oct 17, 2018
7bd5ef9
red
vladyslavkv Oct 17, 2018
0825774
green
vladyslavkv Oct 17, 2018
a30d479
red
vladyslavkv Oct 17, 2018
40fac0d
Reverted
vladyslavkv Oct 17, 2018
21025b7
red
vladyslavkv Oct 17, 2018
e46dc50
green
vladyslavkv Oct 17, 2018
9b3fb5a
red
vladyslavkv Oct 17, 2018
594bdee
green
vladyslavkv Oct 17, 2018
fcc9792
red
vladyslavkv Oct 17, 2018
40a88eb
green
vladyslavkv Oct 17, 2018
4fd2ab2
red
vladyslavkv Oct 17, 2018
41b4c2b
green
vladyslavkv Oct 17, 2018
d489126
red
vladyslavkv Oct 17, 2018
bd1a8fb
green
vladyslavkv Oct 17, 2018
4a9de6e
red
vladyslavkv Oct 17, 2018
bcb3637
green
vladyslavkv Oct 17, 2018
495c2a2
refactored
vladyslavkv Oct 17, 2018
4ff867e
red - implementation problem detected
vladyslavkv Oct 17, 2018
c8c7bf9
green
vladyslavkv Oct 17, 2018
9e08be1
to prev commit
vladyslavkv Oct 17, 2018
d119493
acceptence
vladyslavkv Oct 17, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/tdd_intro/build-3rd_party-5_7_0-Debug/

# Prerequisites
*.d

Expand Down
547 changes: 547 additions & 0 deletions tdd_intro/3rd_party/3rd_party.pro.user

Large diffs are not rendered by default.

397 changes: 397 additions & 0 deletions tdd_intro/3rd_party/build-gtest-5_7_0-Debug/Makefile

Large diffs are not rendered by default.

232 changes: 232 additions & 0 deletions tdd_intro/3rd_party/build-gtest-5_7_0-Debug/Makefile.Debug

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions tdd_intro/3rd_party/build-gtest-5_7_0-Debug/Makefile.Release

Large diffs are not rendered by default.

Binary file not shown.
456 changes: 456 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/Makefile

Large diffs are not rendered by default.

397 changes: 397 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gmock/Makefile

Large diffs are not rendered by default.

289 changes: 289 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gmock/Makefile.Debug

Large diffs are not rendered by default.

287 changes: 287 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gmock/Makefile.Release

Large diffs are not rendered by default.

Binary file not shown.
397 changes: 397 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gtest/Makefile

Large diffs are not rendered by default.

232 changes: 232 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gtest/Makefile.Debug

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions tdd_intro/build-3rd_party-5_7_0-Debug/gtest/Makefile.Release

Large diffs are not rendered by default.

Binary file not shown.
318 changes: 318 additions & 0 deletions tdd_intro/homework/01_leap_year/01_leap_year.pro.user

Large diffs are not rendered by default.

38 changes: 38 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,41 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>

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

TEST(YearTest, OrdinaryYear)
{
EXPECT_FALSE(IsLeapYear(1997));
}

TEST(YearTest, LeapYear)
{
EXPECT_TRUE(IsLeapYear(1996));
}

TEST(YearTest, AnotherLeapYear)
{
EXPECT_TRUE(IsLeapYear(1992));
}

TEST(YearTest, OrdinaryYearDerivedBy100)
{
EXPECT_FALSE(IsLeapYear(1900));
}

TEST(YearTest, LeapYearDerivedBy400)
{
EXPECT_FALSE(IsLeapYear(2000));
}
54 changes: 53 additions & 1 deletion tdd_intro/homework/02_ternary_numbers/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>

#include <string>
/*
Convert a ternary number, represented as a string (e.g. '102012'), to its decimal equivalent using first principles.

Expand All @@ -16,3 +16,55 @@ 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.
*/

std::string ConvertTernary(const std::string& ternaryNumber)
{
if (ternaryNumber.empty())
{
return std::string("");
}

int result = 0;
for (int i = ternaryNumber.size() - 1, value = 1; i >= 0; --i)
{
int currentSymbol = static_cast<int>(ternaryNumber[i]) - 48; // ASCII. 48 - 0, 49 - 1 and so on
if (!(currentSymbol >= 0 && currentSymbol <= 3))
{
return 0;
}

result += currentSymbol * value;
value *= 3;
}

return std::to_string(result);
}

TEST(TernaryConvertion, Convert1)
{
EXPECT_EQ("1", ConvertTernary("1"));
}

TEST(TernaryConvertion, Convert20)
{
EXPECT_EQ("6", ConvertTernary("20"));
}

TEST(TernaryConvertion, ConvertEmpty)
{
EXPECT_EQ("", ConvertTernary(""));
}

TEST(TernaryConvertion, Convert20201)
{
EXPECT_EQ("181", ConvertTernary("20201"));
}

TEST(TernaryConvertion, Acceptance)
{
EXPECT_EQ("211", ConvertTernary("21211"));
EXPECT_EQ("4113", ConvertTernary("12122100"));
EXPECT_EQ("468", ConvertTernary("122100"));
EXPECT_EQ("149", ConvertTernary("12112"));
}

133 changes: 104 additions & 29 deletions tdd_intro/homework/03_bank_ocr/test.cpp
Original file line number Diff line number Diff line change
@@ -1,86 +1,60 @@
/*### Bank OCR

Your manager has recently purchased a machine that assists in reading letters and faxes sent in by branch offices. The machine scans the paper documents, and produces a file with a number of entries. You will write a program to parse this file.

Your manager has recently purchased a machine that assists in reading letters and faxes sent in by branch offices.
The machine scans the paper documents, and produces a file with a number of entries. You will write a program to parse this file.
#### Specification
#### User Story 1

The following format is created by the machine:
```
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
```
Each entry is 3 lines long, and each line has 27 characters. 3 lines of each entry contain an account number written using pipes and underscores.

Each account number should have 9 digits, all of which should be in the range 0-9. A normal file contains around 500 entries.

Write a program that can take this file and parse it into actual account numbers.

Example input and output
```
_ _ _ _ _ _ _ _ _
| || || || || || || || || |
|_||_||_||_||_||_||_||_||_|

=> 000000000

| | | | | | | | |
| | | | | | | | |

=> 111111111

_ _ _ _ _ _ _ _ _
_| _| _| _| _| _| _| _| _|
|_ |_ |_ |_ |_ |_ |_ |_ |_

=> 222222222

_ _ _ _ _ _ _ _ _
_| _| _| _| _| _| _| _| _|
_| _| _| _| _| _| _| _| _|

=> 333333333

|_||_||_||_||_||_||_||_||_|
| | | | | | | | |

=> 444444444

_ _ _ _ _ _ _ _ _
|_ |_ |_ |_ |_ |_ |_ |_ |_
_| _| _| _| _| _| _| _| _|

=> 555555555

_ _ _ _ _ _ _ _ _
|_ |_ |_ |_ |_ |_ |_ |_ |_
|_||_||_||_||_||_||_||_||_|

=> 666666666

_ _ _ _ _ _ _ _ _
| | | | | | | | |
| | | | | | | | |

=> 777777777

_ _ _ _ _ _ _ _ _
|_||_||_||_||_||_||_||_||_|
|_||_||_||_||_||_||_||_||_|

=> 888888888

_ _ _ _ _ _ _ _ _
|_||_||_||_||_||_||_||_||_|
_| _| _| _| _| _| _| _| _|

=> 999999999

_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|

=> 123456789
```
*/
Expand All @@ -91,13 +65,25 @@ const unsigned short g_digitLen = 3;
const unsigned short g_linesInDigit = 3;
struct Digit
{
bool operator ==(const Digit& digit)
{
for (unsigned int i = 0; i < g_linesInDigit; i++)
{
if (lines[i] != digit.lines[i])
{
return false;
}
}
return true;
}

std::string lines[g_linesInDigit];
};

const unsigned short g_digitsOnDisplay = 9;
struct Display
{
std::string lines[g_linesInDigit];
Digit digits[g_linesInDigit];
};

const Digit s_digit0 = { " _ ",
Expand Down Expand Up @@ -195,3 +181,92 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ",
" | _| _||_||_ |_ ||_||_|",
" ||_ _| | _||_| ||_| _|"
};

// Test list:
// Digit
// Another digit
// Invalid symbols in input
// Display
// Another display
// Acceptance

unsigned long long ConvertDigit(Digit digit)
{
static const Digit allDigits[] = { s_digit0, s_digit1, s_digit2,
s_digit3, s_digit4, s_digit5,
s_digit6, s_digit7, s_digit8,
s_digit9
};

for (size_t i = 0; i < 10; i++)
{
if (digit == allDigits[i])
{
return i;
}
}
throw std::runtime_error("Invalid input");
}

unsigned long long ConvertDisplay(Display display)
{
unsigned long long result = 0;
for (size_t digitNumber = 0, powIndex = g_digitsOnDisplay - 1; digitNumber < g_digitsOnDisplay; digitNumber++, powIndex--)
{
Digit digit;
for (size_t lineNumber = 0; lineNumber < g_linesInDigit; lineNumber++)
{
digit.lines[lineNumber].assign(display.digits[0].lines[lineNumber].cbegin() + digitNumber * g_digitLen,
display.digits[0].lines[lineNumber].cbegin() + digitNumber * g_digitLen + g_digitLen);
}
result += ConvertDigit(digit) * std::pow(10, powIndex);
}
return result;
}

TEST(BankOcr, Convert1)
{
EXPECT_EQ(ConvertDigit(s_digit0), 0);
}

TEST(BankOcr, Convert3)
{
EXPECT_EQ(ConvertDigit(s_digit3), 3);
}

TEST(BankOcr, Convert5)
{
EXPECT_EQ(ConvertDigit(s_digit5), 5);
}

TEST(BankOcr, ConvertInvalid)
{
const Digit s_digitInvalid = { " 1 ",
"|3 ",
" 4|"
};
EXPECT_THROW(ConvertDigit(s_digitInvalid), std::runtime_error);
}

TEST(BankOcr, ConvertDisplay0)
{
EXPECT_EQ(ConvertDisplay(s_displayAll0), 000000000);
}

TEST(BankOcr, ConvertDisplay2)
{
EXPECT_EQ(ConvertDisplay(s_displayAll2), 222222222);
}

TEST(BankOcr, ConvertDisplayAll)
{
EXPECT_EQ(ConvertDisplay(s_display123456789), 123456789);
}

TEST(BankOcr, Acceptence)
{
EXPECT_EQ(ConvertDisplay(s_displayAll3), 333333333);
EXPECT_EQ(ConvertDisplay(s_displayAll8), 888888888);
EXPECT_EQ(ConvertDisplay(s_displayAll4), 444444444);
}

Loading