-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr_test.py
More file actions
106 lines (85 loc) · 3.8 KB
/
ocr_test.py
File metadata and controls
106 lines (85 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""Tests for the ocr-numbers exercise
Implementation note:
Both ocr.grid and ocr.number should validate their input
and raise ValueErrors with meaningful error messages
if necessary.
"""
import unittest
from ocr import grid, number
class OcrTest(unittest.TestCase):
def test_0(self):
self.assertEqual('0', number([" _ ",
"| |",
"|_|",
" "]))
def test_1(self):
self.assertEqual('1', number([" ",
" |",
" |",
" "]))
def test_garbage(self):
self.assertEqual('?', number([" _ ",
" _|",
" |",
" "]))
def test_last_line_nonblank(self):
self.assertEqual('?', number([" ",
" |",
" |",
"| |"]))
def test_unknown_char(self):
self.assertEqual('?', number([" - ",
" _|",
" X|",
" "]))
def test_too_short_row(self):
self.assertRaises(ValueError, number, [" ",
" _|",
" |",
" "])
def test_insufficient_rows(self):
self.assertRaises(ValueError, number, [" ",
" _|",
" X|"])
def test_grid0(self):
self.assertEqual([" _ ",
"| |",
"|_|",
" "], grid('0'))
def test_grid1(self):
self.assertEqual([" ",
" |",
" |",
" "], grid('1'))
def test_0010110(self):
self.assertEqual('0010110', number([" _ _ _ _ ",
"| || | || | | || |",
"|_||_| ||_| | ||_|",
" "]))
def test_3186547290(self):
digits = '3186547290'
self.assertEqual(digits, number([" _ _ _ _ _ _ _ _ ",
" _| ||_||_ |_ |_| | _||_|| |",
" _| ||_||_| _| | ||_ _||_|",
" "]))
def test_Lost(self):
digits = '4815162342'
self.assertEqual(digits, number([" _ _ _ _ _ _ ",
"|_||_| ||_ ||_ _| _||_| _|",
" ||_| | _| ||_||_ _| ||_ ",
" "]))
def test_garble_middle(self):
self.assertEqual('12?45', number([" _ _ _ ",
" | _| ||_||_ ",
" ||_ _| | _|",
" "]))
def test_grid3186547290(self):
digits = '3186547290'
self.assertEqual([" _ _ _ _ _ _ _ _ ",
" _| ||_||_ |_ |_| | _||_|| |",
" _| ||_||_| _| | ||_ _||_|",
" "], grid(digits))
def test_invalid_grid(self):
self.assertRaises(ValueError, grid, '123a')
if __name__ == '__main__':
unittest.main()