Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ocr-numbers test suite, update description #291

Merged
merged 3 commits into from
Jul 16, 2016
Merged
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 ocr-numbers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"#": [
"An expectation of -1 indicates that a failure should be raised"
],
"convert": {
"description": "Converts lines of OCR Numbers to a string of integers",
"cases": [
{
"description": "Recognizes 0",
"input": [
" _ ",
"| |",
"|_|",
" "
],
"expected": "0"
},
{
"description": "Recognizes 1",
"input": [
" ",
" |",
" |",
" "
],
"expected": "1"
},
{
"description": "Unreadable but correctly sized inputs return ?",
"input": [
" ",
" _",
" |",
" "
],
"expected": "?"
},
{
"description": "Input with a number of lines that is not a multiple of four raises an error",
"input": [
" _ ",
"| |",
" "
],
"expected": -1
},
{
"description": "Input with a number of columns that is not a multiple of three raises an error",
"input": [
" ",
" |",
" |",
" "
],
"expected": -1
},
{
"description": "Recognizes 110101100",
"input": [
" _ _ _ _ ",
" | || | || | | || || |",
" | ||_| ||_| | ||_||_|",
" "
],
"expected": "110101100"
},
{
"description": "Garbled numbers in a string are replaced with ?",
"input": [
" _ _ _ ",
" | || | || | || || |",
" | | _| ||_| | ||_||_|",
" "
],
"expected": "11?10?1?0"
},
{
"description": "Recognizes 2",
"input": [
" _ ",
" _|",
"|_ ",
" "
],
"expected": "2"
},
{
"description": "Recognizes 3",
"input": [
" _ ",
" _|",
" _|",
" "
],
"expected": "3"
},
{
"description": "Recognizes 4",
"input": [
" ",
"|_|",
" |",
" "
],
"expected": "4"
},
{
"description": "Recognizes 5",
"input": [
" _ ",
"|_ ",
" _|",
" "
],
"expected": "5"
},
{
"description": "Recognizes 6",
"input": [
" _ ",
"|_ ",
"|_|",
" "
],
"expected": "6"
},
{
"description": "Recognizes 7",
"input": [
" _ ",
" |",
" |",
" "
],
"expected": "7"
},
{
"description": "Recognizes 8",
"input": [
" _ ",
"|_|",
"|_|",
" "
],
"expected": "8"
},
{
"description": "Recognizes 9",
"input": [
" _ ",
"|_|",
" _|",
" "
],
"expected": "9"
},
{
"description": "Recognizes string of decimal numbers",
"input": [
" _ _ _ _ _ _ _ _ ",
" | _| _||_||_ |_ ||_||_|| |",
" ||_ _| | _||_| ||_| _||_|",
" "
],
"expected": "1234567890"
},
{
"description": "Numbers separated by empty lines are recognized. Lines are joined by commas.",
"input": [
" _ _ ",
" | _| _|",
" ||_ _|",
" ",
" _ _ ",
"|_||_ |_ ",
" | _||_|",
" ",
" _ _ _ ",
" ||_||_|",
" ||_| _|",
" "
],
"expected": "123,456,789"
}
]
}
}
64 changes: 51 additions & 13 deletions ocr-numbers.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
## Step 1
# Step One

A simple binary font has been constructed using only pipes and
underscores.
To begin with, convert a simple binary font to a string containing 0 or 1.

The number is four rows high, three columns wide:
The binary font uses pipes and underscores, four rows high and three columns wide.

```
_ #
| | # zero.
|_| #
# the fourth row is always blank
```

Is converted to "0"

```
#
| # one.
| #
# (blank fourth row)
```

Is converted to "1"

If the input is the correct size, but not recognizable, your program should return '?'

If the input is the incorrect size, your program should return an error.

# Step Two

Write a program that, given a 3 x 4 grid of pipes, underscores, and
spaces, can determine whether the the grid represents a zero, a one, or
garble.
Update your program to recognize multi-character binary strings, replacing garbled numbers with ?

Anything else is considered garble, and can be represented with a '?'
# Step Three

## Step 2
Update your program to recognize all numbers 0 through 9, both individually and as part of a larger string.

A simple numeric font has been constructed using only pipes and
underscores.
```
_
_|
|_

```

The number consists of four rows high, three columns wide:
Is converted to "2"

```
_ _ _ _ _ _ _ _ #
| _| _||_||_ |_ ||_||_|| | # decimal numbers.
||_ _| | _||_| ||_| _||_| #
# fourth line is always blank
```

Is converted to "1234567890"

# Step Four

Update your program to handle multiple numbers, one per line. When converting several lines, join the lines with commas.

```
_ _
| _| _|
||_ _|

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

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

```

There may be several numbers in the input text, one per line.
Is converted to "123,456,789"