<commit_before>"""Tests for the ocr-numbers exercise

Implementation note:
ocr.convert should validate its input and
raise ValueErrors with meaningful error messages
if necessary.
"""

import unittest

from ocr_numbers import convert


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0

class OcrTest(unittest.TestCase):
    def test_recognizes_0(self):
        self.assertEqual(convert([" _ ",
                                  "| |",
                                  "|_|",
                                  "   "]), '0')

    def test_recognizes_1(self):
        self.assertEqual(convert(["   ",
                                  "  |",
                                  "  |",
                                  "   "]), '1')

    def test_unreadable(self):
        self.assertEqual(convert(["   ",
                                  "  _",
                                  "  |",
                                  "   "]), '?')

    def test_line_number_not_multiple_of_four(self):
        with self.assertRaisesWithMessage(ValueError):
            convert([" _ ",
                     "| |",
                     "   "])

    def test_col_number_not_multiple_of_three(self):
        with self.assertRaisesWithMessage(ValueError):
            convert(["    ",
                     "   |",
                     "   |",
                     "    "])

    def test_recognizes_110101100(self):
        input_grid = [
            "       _     _        _  _ ",
            "  |  || |  || |  |  || || |",
            "  |  ||_|  ||_|  |  ||_||_|",
            "                           "
        ]
        self.assertEqual(convert(input_grid), "110101100")

    def test_garbled_numbers_in_string(self):
        input_grid = [
            "       _     _           _ ",
            "  |  || |  || |     || || |",
            "  |  | _|  ||_|  |  ||_||_|",
            "                           "
        ]
        self.assertEqual(convert(input_grid), "11?10?1?0")

    def test_recognizes_2(self):
        self.assertEqual(convert([" _ ",
                                  " _|",
                                  "|_ ",
                                  "   "]), "2")

    def test_recognizes_3(self):
        self.assertEqual(convert([" _ ",
                                  " _|",
                                  " _|",
                                  "   "]), "3")

    def test_recognizes_4(self):
        self.assertEqual(convert(["   ",
                                  "|_|",
                                  "  |",
                                  "   "]), "4")

    def test_recognizes_5(self):
        self.assertEqual(convert([" _ ",
                                  "|_ ",
                                  " _|",
                                  "   "]), "5")

    def test_recognizes_6(self):
        self.assertEqual(convert([" _ ",
                                  "|_ ",
                                  "|_|",
                                  "   "]), "6")

    def test_recognizes_7(self):
        self.assertEqual(convert([" _ ",
                                  "  |",
                                  "  |",
                                  "   "]), "7")

    def test_recognizes_8(self):
        self.assertEqual(convert([" _ ",
                                  "|_|",
                                  "|_|",
                                  "   "]), "8")

    def test_recognizes_9(self):
        self.assertEqual(convert([" _ ",
                                  "|_|",
                                  " _|",
                                  "   "]), "9")

    def test_recognizes_string_of_decimal_numbers(self):
        input_grid = [
            "    _  _     _  _  _  _  _  _ ",
            "  | _| _||_||_ |_   ||_||_|| |",
            "  ||_  _|  | _||_|  ||_| _||_|",
            "                              "
        ]
        self.assertEqual(convert(input_grid), "1234567890")

    def test_recognizes_numbers_separated_by_empty_lines(self):
        input_grid = [
            "    _  _ ",
            "  | _| _|",
            "  ||_  _|",
            "         ",
            "    _  _ ",
            "|_||_ |_ ",
            "  | _||_|",
            "         ",
            " _  _  _ ",
            "  ||_||_|",
            "  ||_| _|",
            "         "
        ]
        self.assertEqual(convert(input_grid), "123,456,789")

    # Utility functions
    def setUp(self):
        try:
            self.assertRaisesRegex
        except AttributeError:
            self.assertRaisesRegex = self.assertRaisesRegexp

    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")


if __name__ == '__main__':
    unittest.main()
<commit_msg>ocr-numbers: update tests to v1.1.0 (#1313)<commit_after>"""Tests for the ocr-numbers exercise

Implementation note:
ocr.convert should validate its input and
raise ValueErrors with meaningful error messages
if necessary.
"""

import unittest

from ocr_numbers import convert


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class OcrTest(unittest.TestCase):
    def test_recognizes_0(self):
        self.assertEqual(convert([" _ ",
                                  "| |",
                                  "|_|",
                                  "   "]), '0')

    def test_recognizes_1(self):
        self.assertEqual(convert(["   ",
                                  "  |",
                                  "  |",
                                  "   "]), '1')

    def test_unreadable(self):
        self.assertEqual(convert(["   ",
                                  "  _",
                                  "  |",
                                  "   "]), '?')

    def test_line_number_not_multiple_of_four(self):
        with self.assertRaisesWithMessage(ValueError):
            convert([" _ ",
                     "| |",
                     "   "])

    def test_col_number_not_multiple_of_three(self):
        with self.assertRaisesWithMessage(ValueError):
            convert(["    ",
                     "   |",
                     "   |",
                     "    "])

    def test_recognizes_110101100(self):
        input_grid = [
            "       _     _        _  _ ",
            "  |  || |  || |  |  || || |",
            "  |  ||_|  ||_|  |  ||_||_|",
            "                           "
        ]
        self.assertEqual(convert(input_grid), "110101100")

    def test_garbled_numbers_in_string(self):
        input_grid = [
            "       _     _           _ ",
            "  |  || |  || |     || || |",
            "  |  | _|  ||_|  |  ||_||_|",
            "                           "
        ]
        self.assertEqual(convert(input_grid), "11?10?1?0")

    def test_recognizes_2(self):
        self.assertEqual(convert([" _ ",
                                  " _|",
                                  "|_ ",
                                  "   "]), "2")

    def test_recognizes_3(self):
        self.assertEqual(convert([" _ ",
                                  " _|",
                                  " _|",
                                  "   "]), "3")

    def test_recognizes_4(self):
        self.assertEqual(convert(["   ",
                                  "|_|",
                                  "  |",
                                  "   "]), "4")

    def test_recognizes_5(self):
        self.assertEqual(convert([" _ ",
                                  "|_ ",
                                  " _|",
                                  "   "]), "5")

    def test_recognizes_6(self):
        self.assertEqual(convert([" _ ",
                                  "|_ ",
                                  "|_|",
                                  "   "]), "6")

    def test_recognizes_7(self):
        self.assertEqual(convert([" _ ",
                                  "  |",
                                  "  |",
                                  "   "]), "7")

    def test_recognizes_8(self):
        self.assertEqual(convert([" _ ",
                                  "|_|",
                                  "|_|",
                                  "   "]), "8")

    def test_recognizes_9(self):
        self.assertEqual(convert([" _ ",
                                  "|_|",
                                  " _|",
                                  "   "]), "9")

    def test_recognizes_string_of_decimal_numbers(self):
        input_grid = [
            "    _  _     _  _  _  _  _  _ ",
            "  | _| _||_||_ |_   ||_||_|| |",
            "  ||_  _|  | _||_|  ||_| _||_|",
            "                              "
        ]
        self.assertEqual(convert(input_grid), "1234567890")

    def test_recognizes_numbers_separated_by_empty_lines(self):
        input_grid = [
            "    _  _ ",
            "  | _| _|",
            "  ||_  _|",
            "         ",
            "    _  _ ",
            "|_||_ |_ ",
            "  | _||_|",
            "         ",
            " _  _  _ ",
            "  ||_||_|",
            "  ||_| _|",
            "         "
        ]
        self.assertEqual(convert(input_grid), "123,456,789")

    # Utility functions
    def setUp(self):
        try:
            self.assertRaisesRegex
        except AttributeError:
            self.assertRaisesRegex = self.assertRaisesRegexp

    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")


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

{'fraction_non_alphanumeric': 0.1310740354535975, 'fraction_numerical': 0.014494264859228364, 'mean_word_length': 0.8943314240568833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 98, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '400114', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2569, 'n_words': 259}