def test_strange_width_characters(): # Split into list of lines for readability/formatting string = "\n".join([ "####.####.####.#...##..#.####.###..####..###...##.", "#....#....#....#...##.#..#....#..#.#......#.....#.", "###..###..###...#.#.##...###..#..#.###....#.....#.", "#....#....#......#..#.#..#....###..#......#.....#.", "#....#....#......#..#.#..#....#.#..#......#..#..#.", "####.#....####...#..#..#.#....#..#.#.....###..##..", ]) assert convert_6(string) == "EFEYKFRFIJ"
def test_long_string(): # Split into list of lines for readability/formatting string = "\n".join([ ".##..###...##..####.####..##..#..#..###...##.#..#.#.....##..###..###...###.#..#.#...#####", "#..#.#..#.#..#.#....#....#..#.#..#...#.....#.#.#..#....#..#.#..#.#..#.#....#..#.#...#...#", "#..#.###..#....###..###..#....####...#.....#.##...#....#..#.#..#.#..#.#....#..#..#.#...#.", "####.#..#.#....#....#....#.##.#..#...#.....#.#.#..#....#..#.###..###...##..#..#...#...#..", "#..#.#..#.#..#.#....#....#..#.#..#...#..#..#.#.#..#....#..#.#....#.#.....#.#..#...#..#...", "#..#.###...##..####.#.....###.#..#..###..##..#..#.####..##..#....#..#.###...##....#..####", ]) assert convert_6(string) == "ABCEFGHIJKLOPRSUYZ"
def part_2(inputs: tuple[str]) -> str: image = _get_image(inputs, WIDTH, HEIGHT) to_ocr = "\n".join([image[i:i+WIDTH] for i in range(0, WIDTH * HEIGHT, WIDTH)]) return convert_6(to_ocr, fill_pixel="1", empty_pixel="0")
def part_2(inputs: tuple[str]) -> int: to_ocr = os.linesep.join(_solve_2(inputs)) return convert_6(to_ocr, fill_pixel=FILL, empty_pixel=EMPTY)
def test_number_of_rows(rows): with raises(ValueError, match=escape("incorrect number of rows (expected 6)")): convert_6("\n".join("" for _ in range(rows)))
def test_different_characters(test_input, fill_char, empty_char): assert (convert_6(test_input, fill_pixel=fill_char, empty_pixel=empty_char) == "ABC")
def test_three_letters(test_input, expected): assert convert_6(test_input) == expected
def test_single_letter(test_input, expected): assert convert_6(test_input) == expected