"""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 os
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_invalid_digit(self):
        self.assertRaises(ValueError, grid, '2')


if __name__ == '__main__':
    unittest.main()

@@ -240,16 +240,125 @@
 umber%0A%0A%0A
+ZERO = %5B%0A    %22 _ %22,%0A    %22%7C %7C%22,%0A    %22%7C_%7C%22,%0A    %22   %22%0A%5D%0A%0AONE = %5B%0A    %22   %22,%0A    %22  %7C%22,%0A    %22  %7C%22,%0A    %22   %22%0A%5D%0A%0A
 class Oc
@@ -447,36 +447,12 @@
 ber(
-%5B%22 _ %22, %22%7C %7C%22, %22%7C_%7C%22, %22   %22%5D
+ZERO
 ))%0A%0A
@@ -514,36 +514,11 @@
 ber(
-%5B%22   %22, %22  %7C%22, %22  %7C%22, %22   %22%5D
+ONE
 ))%0A%0A
@@ -593,343 +593,826 @@
 _ %22,
- %22 _%7C%22, %22  %7C%22, %22   %22%5D))%0A%0A    def test_last_line_nonblank(self):%0A        self.assertEqual('?', number(%5B%22   %22, %22  %7C%22, %22  %7C%22, %22%7C %7C%22%5D))%0A%0A    def test_unknown_char(self):%0A        self.assertEqual('?', number(%5B%22 - %22, %22 _%7C%22, %22 X%7C%22, %22   %22%5D))%0A%0A    def test_too_short_row(self):%0A        self.assertRaises(ValueError, number, %5B%22   %22, %22 _%7C%22, %22 %7C%22,
+%0A                                      %22 _%7C%22,%0A                                      %22  %7C%22,%0A                                      %22   %22%5D))%0A%0A    def test_last_line_nonblank(self):%0A        self.assertEqual('?', number(%5B%22   %22,%0A                                      %22  %7C%22,%0A                                      %22  %7C%22,%0A                                      %22%7C %7C%22%5D))%0A%0A    def test_unknown_char(self):%0A        self.assertEqual('?', number(%5B%22 - %22,%0A                                      %22 _%7C%22,%0A                                      %22 X%7C%22,%0A                                      %22   %22%5D))%0A%0A    def test_too_short_row(self):%0A        self.assertRaises(ValueError, number, %5B%22   %22,%0A                                               %22 _%7C%22,%0A                                               %22 %7C%22,%0A                                              
  %22  
@@ -1512,115 +1512,116 @@
   %22,
- %22 _%7C%22, %22 X%7C%22%5D)%0A%0A    def test_grid0(self):%0A        self.assertEqual(%5B%22 _ %22, %22%7C %7C%22, %22%7C
+%0A                                               %22 
 _%7C%22,
- %22   %22%5D, grid('0')
+%0A                                               %22 X%7C%22%5D
 )%0A%0A 
@@ -1636,17 +1636,17 @@
 est_grid
-1
+0
 (self):%0A
@@ -1674,44 +1674,20 @@
 ual(
-%5B%22   %22, %22  %7C%22, %22  %7C%22, %22   %22%5D
+ZERO
 , grid('
 1'))
@@ -1682,17 +1682,17 @@
 , grid('
-1
+0
 '))%0A%0A   
@@ -1705,21 +1705,13 @@
 est_
-invalid_digit
+grid1
 (sel
@@ -1737,36 +1737,28 @@
 sert
-Raises(ValueError
+Equal(ONE
 , grid
-, '2'
+('1')
 )%0A%0A%0A

Improve readability of tests by formatting the pipe grids.