Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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));
}
25 changes: 25 additions & 0 deletions tdd_intro/homework/06_allergies/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
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>
88 changes: 0 additions & 88 deletions tdd_intro/homework/06_bank_ocr/test.cpp

This file was deleted.

Loading