Skip to content
Open
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
50e4182
workshop2
prepas May 2, 2018
0687034
change workshop #3
prepas May 9, 2018
f3221cf
03_armstrong_number
prepas May 10, 2018
d20ec51
added 04_roman_numerals task for workshop
Vv-git May 15, 2018
ab6da91
04_roman_numerals
prepas May 16, 2018
fb18071
04_roman_numerals
prepas May 16, 2018
b41c628
fix build
May 23, 2018
c7fe024
add bank ocr
May 23, 2018
429bf52
update readme
May 23, 2018
302c6c8
05_bank_ocr
May 23, 2018
3888d5a
05_bank_ocr
May 23, 2018
174d704
05_bank_ocr
May 23, 2018
8a26ae0
05bankocr_homework
May 23, 2018
9964bf7
05_word_wrapp
May 30, 2018
a19db22
added Allergies task description
driverdevteam May 31, 2018
655c03b
added 06_allergies homework
Vv-git May 31, 2018
dc1a3e2
modified description of 06_allergies homework
Vv-git May 31, 2018
1147cf4
Tests list
RSerhii Jun 3, 2018
f6ccd26
TEST CompareWithCorrectNumber RED
RSerhii Jun 3, 2018
45b3282
TEST CompareWithCorrectNumber GREEN
RSerhii Jun 3, 2018
f453d0a
TEST CompareWithIncorrectNumber RED
RSerhii Jun 3, 2018
f81d758
TEST CompareWithIncorrectNumber GREEN
RSerhii Jun 3, 2018
274accf
Updated tests list
RSerhii Jun 3, 2018
be06f41
TEST CompareWithCorrectNumber_4 RED
RSerhii Jun 3, 2018
4297715
TEST CompareWithCorrectNumber_4 GREEN
RSerhii Jun 3, 2018
b2f388d
TEST CompareWithComplexNumber_5 RED
RSerhii Jun 3, 2018
78a62dd
TEST CompareWithComplexNumber_5 GREEN
RSerhii Jun 3, 2018
a9f2b99
Refactoring removed unneeded test
RSerhii Jun 3, 2018
c11a883
Fixed compiler warnings
RSerhii Jun 3, 2018
17b00d0
TEST WithCorrectName RED
RSerhii Jun 3, 2018
5f2da8e
TEST WithCorrectName GREEN
RSerhii Jun 3, 2018
84c0e3a
TEST WithIncorrectName RED
RSerhii Jun 3, 2018
15eaa8c
TEST WithIncorrectName GREEN
RSerhii Jun 3, 2018
d784431
TEST WithCorrectName_tomatoes RED
RSerhii Jun 3, 2018
d717637
TEST WithCorrectName_tomatoes GREEN
RSerhii Jun 3, 2018
65c0cc6
TEST UnexistentAllergy_EmptyList RED
RSerhii Jun 3, 2018
e691094
TEST UnexistentAllergy_EmptyList GREEN
RSerhii Jun 3, 2018
957a4c1
TEST IsAllergicTo_UnexistentAllergy RED
RSerhii Jun 3, 2018
4aebc7b
TEST IsAllergicTo_UnexistentAllergy GREEN
RSerhii Jun 3, 2018
f5a572c
Refactoring
RSerhii Jun 3, 2018
48b6975
TEST List_OneAllergy RED
RSerhii Jun 3, 2018
dbf5782
TEST List_OneAllergy GREEN
RSerhii Jun 3, 2018
478ab67
Refactoring changed type of AllergiesList from vector to set
RSerhii Jun 3, 2018
7b67255
TEST List_TwoAllergy RED
RSerhii Jun 3, 2018
d4f0596
TEST List_TwoAllergy GREEN
RSerhii Jun 3, 2018
86eae8c
TEST IsAllergicTo_ExistentAllergy RED
RSerhii Jun 3, 2018
7b2492d
TEST IsAllergicTo_ExistentAllergy GREEN
RSerhii Jun 3, 2018
2d2e0a3
TEST IsAllergicTo_TwoAllergy GREEN
RSerhii Jun 3, 2018
4bc5acb
TEST List_ExistentAndUnexistentAllergy GREEN
RSerhii Jun 3, 2018
a5b2bad
Tests list
RSerhii Jun 9, 2018
fa4fc67
Added IFileSystem interface
RSerhii Jun 9, 2018
608fec2
Added const modifier
RSerhii Jun 9, 2018
de23466
Added MockFileSystem
RSerhii Jun 9, 2018
7344689
TEST Copy_NotExistentSrc RED
RSerhii Jun 9, 2018
2fc1fbe
refactoring
RSerhii Jun 9, 2018
634cd48
TEST Copy_GetFilesListEmpty RED
RSerhii Jun 9, 2018
fe8e917
TEST Copy_GetFilesListEmpty GREEN
RSerhii Jun 9, 2018
8867427
TEST ConcatPath_ConcatLeftWithRight RED
RSerhii Jun 9, 2018
905d480
TEST ConcatPath_ConcatLeftWithRight GREEN
RSerhii Jun 9, 2018
b582190
TEST ConcatLeftWithoutRight RED
RSerhii Jun 9, 2018
481060d
TEST ConcatLeftWithoutRight GREEN
RSerhii Jun 9, 2018
c21ef35
TEST ConcatPath_ConcatRightWithoutLeft RED
RSerhii Jun 9, 2018
7168f05
TEST ConcatPath_ConcatRightWithoutLeft GREEN
RSerhii Jun 9, 2018
7e3f122
TEST ConcatPath_ConcatEmpty GREEN
RSerhii Jun 9, 2018
0ef2433
refactoring
RSerhii Jun 9, 2018
b5c264f
TEST Copy_OneFile RED
RSerhii Jun 9, 2018
05ee56f
TEST Copy_OneFile GREEN (+fixed param order in test)
RSerhii Jun 9, 2018
e19f17e
TEST Copy_OneFile RED (added missing operation)
RSerhii Jun 9, 2018
bbdecf9
TEST Copy_OneFile GREEN (+fixed param in test)
RSerhii Jun 9, 2018
9b666c9
TEST Copy_TwoFiles RED
RSerhii Jun 9, 2018
b1b567f
TEST Copy_TwoFiles GREEN
RSerhii Jun 9, 2018
17b1d60
refactoring
RSerhii Jun 9, 2018
bdf6256
TEST Copy_FolderWithFile RED (+2 broken)
RSerhii Jun 10, 2018
bbb2c41
fixed broken tests
RSerhii Jun 10, 2018
f8e774e
TEST Copy_FolderWithFile GREEN
RSerhii Jun 10, 2018
a3595ab
refactoring
RSerhii Jun 10, 2018
59119f3
TEST Copy_FolderWithoutFiles GREEN
RSerhii Jun 10, 2018
abd98e1
refactoring
RSerhii Jun 10, 2018
787e8da
TEST Copy_FileAndFolderWithFile GREEN
RSerhii Jun 10, 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
187 changes: 187 additions & 0 deletions tdd_intro/homework/05_bank_ocr/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*### 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.

#### 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
```
*/
#include <gtest/gtest.h>

// check matrix for one digit 3x3
// parse one digit
// - parse 1
// - parse 2
// - parse 0-9
// - check invalid one digit
// parse several digits (27x3)
// parse 27x3 (9 digits)
// - check matrix 27x3
// - parse
// parse several lines

using Digit = std::vector<std::string>;

const Digit s_1({" ",
" |",
" |"});

const Digit s_2({" _ ",
" _|",
"|_ "});

std::vector<Digit> s_digits({

});

bool CheckMatrixDimension(const Digit& digit)
{
const size_t prefferedSize = 3;

if (digit.size() != prefferedSize)
{
return false;
}

for (const std::string& line : digit)
{
if (line.size() != prefferedSize)
{
return false;
}
}

return true;
}

std::string ParseDigit(const Digit& digit)
{
if (digit == Digit({" ",
" |",
" |"}))
{
return "1";
}
else if (digit == Digit({" _ ",
" _|",
"|_ "}))
{
return "2";
}

return "8";
}

TEST(BankOCRTests, Check_Matrix_dimension_true)
{
Digit digit = {" ", " ", " "};
EXPECT_TRUE(CheckMatrixDimension(digit));
}

TEST(BankOCRTests, Check_Matrix_dimension_false)
{
Digit digit = {" ", "! ", " "};
EXPECT_FALSE(CheckMatrixDimension(digit));
}

TEST(BankOCRTests, ParseDigit_1)
{
Digit digit = {" ",
" |",
" |"};
EXPECT_EQ("1", ParseDigit(digit));
}

TEST(BankOCRTests, ParseDigit_2)
{
Digit digit = {" _ ",
" _|",
"|_ "};
EXPECT_EQ("2", ParseDigit(digit));
}

TEST(BankOCRTests, ParseDigit_8)
{
Digit digit = {" _ ",
"|_|",
"|_|"};
EXPECT_EQ("8", ParseDigit(digit));
}
209 changes: 209 additions & 0 deletions tdd_intro/homework/06_allergies/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).
The list of items (and their value) that were tested are:
eggs (1)
peanuts (2)
shellfish (4)
strawberries (8)
tomatoes (16)
chocolate (32)
pollen (64)
cats (128)
So if Tom is allergic to peanuts and chocolate, he gets a score of 34.

Now, given just that score of 34, your program should be able:
To say have Tom allergic to specific product or not.
To give list of all allergens Tom is allergic to.

E.g. it can be class with methods IsAllergicTo(string), List() and receiving allergyScore in constructor

Note: a given score may include allergens not listed above (i.e. allergens that score 256, 512, 1024, etc.).
Your program should ignore those components of the score.
For example, if the allergy score is 257, your program should only report the eggs (1) allergy.
*/
#include <gtest/gtest.h>
#include <map>

/*
- AllergyIndexTests
- Compare allergy index with correct number
- Compare allergy index with incorrect number
- Compare with complex number
- AllergyNameTests
- Find allergy index for correct name
- Throw exceprion for incorrect name
- PersonAllergiesTests
- check with unexistent allergy
- List() returns empty list
- IsAllergicTo() returns false
- check with one allergy
- List() returns name of allergy
- IsAllergicTo() returns true if allergy score = index of allergy name
- IsAllergicTo() returns false if allergy score != index of allergy name
- check with two allergies
- List() returns names of allergies
- IsAllergicTo() returns true if allergy score contains index of allergy name
- IsAllergicTo() returns false if allergy score not contains index of allergy name
- check with existent and unexistent allergies
- List() returns name of existent allergy
*/

enum AllergyIndex : uint64_t
{
AllergyIndexFirst = 0,
AllergyIndexEggs = AllergyIndexFirst,
AllergyIndexPeanuts,
AllergyIndexShellfish,
AllergyIndexStrawberries,
AllergyIndexTomatoes,
AllergyIndexChocolate,
AllergyIndexPollen,
AllergyIndexCats,
AllergyIndexLast = AllergyIndexCats
};

static const std::map<std::string, AllergyIndex> s_allergies({
{"eggs", AllergyIndexEggs},
{"peanuts", AllergyIndexPeanuts},
{"shellfish", AllergyIndexShellfish},
{"strawberries", AllergyIndexStrawberries},
{"tomatoes", AllergyIndexTomatoes},
{"chocolate", AllergyIndexChocolate},
{"pollen", AllergyIndexPollen},
{"cats", AllergyIndexCats} });

bool HaveAllergy(uint64_t allergyScore, AllergyIndex alergyIndex)
{
return (allergyScore & uint64_t(1) << alergyIndex) != 0;
}

using AllergiesList = std::set<std::string>;

AllergyIndex GetAllergyIndex(const std::string& allergyName)
{
auto allergy = s_allergies.find(allergyName);

if (allergy == s_allergies.end())
{
throw std::out_of_range("Allergy has no index.");
}

return allergy->second;
}

class PersonAllergies
{
public:
explicit PersonAllergies(uint64_t allergyScore)
: m_allergyScore(allergyScore)
{}

AllergiesList List()
{
AllergiesList allergiesList;

for (auto allergy : s_allergies)
{
if (HaveAllergy(m_allergyScore, allergy.second))
{
allergiesList.insert(allergy.first);
}
}

return allergiesList;
}

bool IsAllergicTo(const std::string& allergyName)
{
return HaveAllergy(m_allergyScore, GetAllergyIndex(allergyName));
}

private:
uint64_t m_allergyScore;
};

const uint64_t s_unexistentAllergyIndex(256);
const std::string s_tomatoes("tomatoes");
const std::string s_eggs("eggs");
const uint64_t s_tomatoesIndex(16);

TEST(HaveAllergyTests, CompareWithCorrectNumber)
{
EXPECT_TRUE(HaveAllergy(1, AllergyIndexEggs));
}

TEST(HaveAllergyTests, CompareWithIncorrectNumber)
{
EXPECT_FALSE(HaveAllergy(2, AllergyIndexEggs));
}

TEST(HaveAllergyTests, CompareWithComplexNumber)
{
EXPECT_TRUE(HaveAllergy(5, AllergyIndexEggs));
EXPECT_TRUE(HaveAllergy(5, AllergyIndexShellfish));
}

TEST(GetAllergyIndexTests, WithCorrectName)
{
EXPECT_EQ(AllergyIndexEggs, GetAllergyIndex(s_eggs));
}

TEST(GetAllergyIndexTests, WithIncorrectName)
{
EXPECT_THROW(GetAllergyIndex(""), std::out_of_range);
}

TEST(GetAllergyIndexTests, WithCorrectName_tomatoes)
{
EXPECT_EQ(AllergyIndexTomatoes, GetAllergyIndex(s_tomatoes));
}

TEST(PersonAllergiesTests, UnexistentAllergy_EmptyList)
{
PersonAllergies personAllergies(s_unexistentAllergyIndex);
EXPECT_EQ(AllergiesList(), personAllergies.List());
}

TEST(PersonAllergiesTests, IsAllergicTo_UnexistentAllergy)
{
PersonAllergies personAllergies(s_unexistentAllergyIndex);
EXPECT_FALSE(personAllergies.IsAllergicTo(s_tomatoes));
}

TEST(PersonAllergiesTests, List_OneAllergy)
{
PersonAllergies personAllergies(s_tomatoesIndex);
EXPECT_EQ(AllergiesList({s_tomatoes}), personAllergies.List());
}

TEST(PersonAllergiesTests, List_TwoAllergy)
{
PersonAllergies personAllergies(s_tomatoesIndex + 1);
EXPECT_EQ(AllergiesList({s_tomatoes, s_eggs}), personAllergies.List());
}

TEST(PersonAllergiesTests, IsAllergicTo_ExistentAllergy)
{
PersonAllergies personAllergies(s_tomatoesIndex);
EXPECT_TRUE(personAllergies.IsAllergicTo(s_tomatoes));
}

TEST(PersonAllergiesTests, IsAllergicTo_ExistentAllergy_WrongIndex)
{
PersonAllergies personAllergies(s_tomatoesIndex);
EXPECT_FALSE(personAllergies.IsAllergicTo(s_eggs));
}

TEST(PersonAllergiesTests, IsAllergicTo_TwoAllergy)
{
PersonAllergies personAllergies(s_tomatoesIndex + 1);
EXPECT_TRUE(personAllergies.IsAllergicTo(s_tomatoes));
EXPECT_TRUE(personAllergies.IsAllergicTo(s_eggs));
}

TEST(PersonAllergiesTests, List_ExistentAndUnexistentAllergy)
{
PersonAllergies personAllergies(s_tomatoesIndex + s_unexistentAllergyIndex);
EXPECT_EQ(AllergiesList({s_tomatoes}), personAllergies.List());
}
Loading