Exemplo n.º 1
0
def test_strange_width_characters():
    # Split into list of lines for readability/formatting
    string = "\n".join([
        "####.####.####.#...##..#.####.###..####..###...##.",
        "#....#....#....#...##.#..#....#..#.#......#.....#.",
        "###..###..###...#.#.##...###..#..#.###....#.....#.",
        "#....#....#......#..#.#..#....###..#......#.....#.",
        "#....#....#......#..#.#..#....#.#..#......#..#..#.",
        "####.#....####...#..#..#.#....#..#.#.....###..##..",
    ])
    assert convert_6(string) == "EFEYKFRFIJ"
Exemplo n.º 2
0
def test_long_string():
    # Split into list of lines for readability/formatting
    string = "\n".join([
        ".##..###...##..####.####..##..#..#..###...##.#..#.#.....##..###..###...###.#..#.#...#####",
        "#..#.#..#.#..#.#....#....#..#.#..#...#.....#.#.#..#....#..#.#..#.#..#.#....#..#.#...#...#",
        "#..#.###..#....###..###..#....####...#.....#.##...#....#..#.#..#.#..#.#....#..#..#.#...#.",
        "####.#..#.#....#....#....#.##.#..#...#.....#.#.#..#....#..#.###..###...##..#..#...#...#..",
        "#..#.#..#.#..#.#....#....#..#.#..#...#..#..#.#.#..#....#..#.#....#.#.....#.#..#...#..#...",
        "#..#.###...##..####.#.....###.#..#..###..##..#..#.####..##..#....#..#.###...##....#..####",
    ])
    assert convert_6(string) == "ABCEFGHIJKLOPRSUYZ"
Exemplo n.º 3
0
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")
Exemplo n.º 4
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)
Exemplo n.º 5
0
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)))
Exemplo n.º 6
0
def test_different_characters(test_input, fill_char, empty_char):
    assert (convert_6(test_input, fill_pixel=fill_char,
                      empty_pixel=empty_char) == "ABC")
Exemplo n.º 7
0
def test_three_letters(test_input, expected):
    assert convert_6(test_input) == expected
Exemplo n.º 8
0
def test_single_letter(test_input, expected):
    assert convert_6(test_input) == expected