Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
b8b350d
07_coffee
Jun 6, 2018
69b5a3f
07_coffee
Jun 6, 2018
c0c03e6
Merge branch 'master' of https://github.com/driverdevteam/tdd-course-2
Jun 6, 2018
274381f
07_coffee
Jun 6, 2018
7eaa1fc
07_coffee
Jun 6, 2018
89b4045
tests list
Krestol Jun 12, 2018
637f173
[red] IsAllergicToTest Takes_eggs_score_1_return_true
Krestol Jun 12, 2018
6fde58a
[green] IsAllergicToTest Takes_eggs_score_1_return_true
Krestol Jun 12, 2018
fe6df31
[red] IsAllergicToTest Takes_eggs_score_2_return_false
Krestol Jun 12, 2018
899be49
[green] IsAllergicToTest Takes_eggs_score_2_return_false
Krestol Jun 12, 2018
d8684d5
[refactoring] IsAllergicToTest Takes_eggs_score_2_return_false
Krestol Jun 12, 2018
0387adc
[red] IsAllergicToTest Takes_eggs_score_5_return_true
Krestol Jun 12, 2018
92e737f
[green] IsAllergicToTest Takes_eggs_score_5_return_true
Krestol Jun 12, 2018
dd6ebdf
[refactoring] IsAllergicToTest Takes_eggs_score_5_return_true
Krestol Jun 12, 2018
6fc0704
[red] IsAllergicToTest Takes_eggs_score_0_return_false
Krestol Jun 12, 2018
8c2df72
[green] IsAllergicToTest Takes_eggs_score_0_return_false
Krestol Jun 12, 2018
517054c
[red] IsAllergicToTest Takes_peanuts_score_2_return_true
Krestol Jun 12, 2018
d1a0e35
[green] IsAllergicToTest Takes_peanuts_score_2_return_true
Krestol Jun 12, 2018
b7a99d3
IsAllergicTo all allergies with it's minimum score
Krestol Jun 12, 2018
fb8af01
[red] IsAllergicToTest Takes_empty_string_score_128_return_false
Krestol Jun 12, 2018
643c44c
[green] IsAllergicToTest Takes_empty_string_score_128_return_false
Krestol Jun 12, 2018
36d816f
[refactoring] IsAllergicToTest Takes_empty_string_score_128_return_false
Krestol Jun 12, 2018
75b944c
[red] ListTest Takes_0_return_empty_list
Krestol Jun 12, 2018
403824f
for previous commit
Krestol Jun 12, 2018
67e0893
[green] ListTest Takes_0_return_empty_list
Krestol Jun 12, 2018
9d4a877
[red] ListTest Takes_1_return_eggs
Krestol Jun 12, 2018
0886956
[green] ListTest Takes_1_return_eggs
Krestol Jun 12, 2018
8e185f1
[refactoring] ListTest Takes_1_return_eggs
Krestol Jun 12, 2018
77458f7
[red] ListTest Takes_256_return_all
Krestol Jun 12, 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));
}
180 changes: 180 additions & 0 deletions tdd_intro/homework/06_allergies/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
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.
*/

//1. IsAllergicTo eggs score 1 -> true
//2. IsAllergicTo eggs score 2 -> false
//3. IsAllergicTo eggs score 5 -> true
//4. IsAllergicTo eggs score 257 -> true
//5. IsAllergicTo eggs score 0 -> false
//6. IsAllergicTo all allergies with it's minimum score

//7. List score 0
//8. List score 255

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

enum Allergy
{
allergiesFirst = 0,
eggs = allergiesFirst,
peanuts,
shellfish,
strawberries,
tomatoes,
chocolate,
pollen,
cats,
allergiesLast = cats
};

const std::map<std::string, Allergy> allergies {
{"eggs", eggs},
{"peanuts", peanuts},
{"shellfish", shellfish},
{"strawberries", strawberries},
{"tomatoes", tomatoes},
{"chocolate", chocolate},
{"pollen", pollen},
{"cats", cats},
};

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

bool IsAllergicTo(const std::string& allergy, int score)
{
auto it = allergies.find(allergy);
if (it != allergies.end())
{
int degreeOfAllergy = it->second;
return (score & 1 << degreeOfAllergy) != 0;
}
return false;
}

Allergies_vt List(int score)
{
Allergies_vt result;
for (const auto& allergy : allergies)
{
if (IsAllergicTo(allergy.first, score))
{
result.insert(allergy.first);
}
}

return result;
}

TEST(IsAllergicToTest, Takes_eggs_score_1_return_true)
{
EXPECT_TRUE(IsAllergicTo("eggs", 1));
}

TEST(IsAllergicToTest, Takes_eggs_score_2_return_false)
{
EXPECT_FALSE(IsAllergicTo("eggs", 2));
}

TEST(IsAllergicToTest, Takes_eggs_score_5_return_true)
{
EXPECT_TRUE(IsAllergicTo("eggs", 5));
}

TEST(IsAllergicToTest, Takes_eggs_score_257_return_true)
{
EXPECT_TRUE(IsAllergicTo("eggs", 257));
}

TEST(IsAllergicToTest, Takes_eggs_score_0_return_false)
{
EXPECT_FALSE(IsAllergicTo("eggs", 0));
}

TEST(IsAllergicToTest, Takes_peanuts_score_2_return_true)
{
EXPECT_TRUE(IsAllergicTo("peanuts", 2));
}

TEST(IsAllergicToTest, Takes_shellfish_score_4_return_true)
{
EXPECT_TRUE(IsAllergicTo("shellfish", 4));
}

TEST(IsAllergicToTest, Takes_strawberries_score_8_return_true)
{
EXPECT_TRUE(IsAllergicTo("strawberries", 8));
}

TEST(IsAllergicToTest, Takes_tomatoes_score_16_return_true)
{
EXPECT_TRUE(IsAllergicTo("tomatoes", 16));
}

TEST(IsAllergicToTest, Takes_chocolate_score_32_return_true)
{
EXPECT_TRUE(IsAllergicTo("chocolate", 32));
}

TEST(IsAllergicToTest, Takes_pollen_score_64_return_true)
{
EXPECT_TRUE(IsAllergicTo("pollen", 64));
}

TEST(IsAllergicToTest, Takes_cats_score_128_return_true)
{
EXPECT_TRUE(IsAllergicTo("cats", 128));
}

TEST(IsAllergicToTest, Takes_pollen_score_128_return_false)
{
EXPECT_FALSE(IsAllergicTo("pollen", 128));
}

TEST(IsAllergicToTest, Takes_empty_string_score_128_return_false)
{
EXPECT_FALSE(IsAllergicTo("", 128));
}

TEST(ListTest, Takes_0_return_empty_list)
{
EXPECT_TRUE(List(0).empty());
}

TEST(ListTest, Takes_1_return_eggs)
{
Allergies_vt allergiesList = List(1);
ASSERT_EQ(1, allergiesList.size());
EXPECT_TRUE("eggs", allergiesList[0]);
}

TEST(ListTest, Takes_256_return_all)
{
Allergies_vt allergiesList = List(255);
Allergies_vt expected {"eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"};
ASSERT_EQ(expected.size(), allergiesList.size());
EXPECT_EQ(expected, allergiesList);
}
Loading