def test_draw_entries_and_lines_with_emphasize(): d = TextDiagramDrawer() d.write(0, 0, '!') d.write(6, 2, 'span') d.horizontal_line(y=3, x1=2, x2=8, emphasize=True) d.horizontal_line(y=5, x1=2, x2=9, emphasize=False) d.vertical_line(x=7, y1=1, y2=6, emphasize=True) d.vertical_line(x=5, y1=1, y2=7, emphasize=False) _assert_same_diagram( d.render().strip(), """ ! ╷ ╻ │ ┃ │ span ┃ │ ┃ ╺━━━━━┿━━━━━━╋━╸ │ ┃ │ ┃ │ ┃ ╶─────┼──────╂─── │ ┃ │ ╹ │ """.strip())
def test_draw_entries_and_lines_with_options(): d = TextDiagramDrawer() d.write(0, 0, '!') d.write(6, 2, 'span') d.horizontal_line(y=3, x1=2, x2=8) d.vertical_line(x=7, y1=1, y2=4) assert d.render().strip() == """ ! │ │ span │ │ ─────────────┼─ │ """.strip() assert d.render(use_unicode_characters=False).strip() == """ ! | | span | | -------------+- | """.strip() assert d.render(crossing_char='@').strip() == """ ! │ │ span │ │ ─────────────@─ │ """.strip() assert d.render(horizontal_spacing=0).strip() == """ ! │ │ span│ │ ────────┼ │ """.strip() assert d.render(vertical_spacing=0).strip() == """ ! │ span │ ─────────────┼─ """.strip()
def test_draw_entries_and_lines_with_options(): d = TextDiagramDrawer() d.write(0, 0, '!') d.write(6, 2, 'span') d.horizontal_line(y=3, x1=2, x2=8) d.vertical_line(x=7, y1=1, y2=4) assert d.render().strip() == """ ! │ │ span │ │ ─────────────┼─ │ """.strip() assert d.render(use_unicode_characters=False).strip() == """ ! | | span | | -------------+- | """.strip() assert d.render(crossing_char='@').strip() == """ ! │ │ span │ │ ─────────────@─ │ """.strip() assert d.render(horizontal_spacing=0).strip() == """ ! │ │ span│ │ ────────┼ │ """.strip() assert d.render(vertical_spacing=0).strip() == """ ! │ span │ ─────────────┼─ """.strip()
def __str__(self): diagram = TextDiagramDrawer() for q in self.qubits: diagram.write(q.col, q.row, str(q)) for q2 in self.neighbors_of(q): if q2.col != q.col: diagram.horizontal_line(q.row, q.col, q2.col) else: diagram.vertical_line(q.col, q.row, q2.row) return diagram.render( horizontal_spacing=3, vertical_spacing=2, use_unicode_characters=True)
def test_multiline_entries(): d = TextDiagramDrawer() d.write(0, 0, 'hello\nthere') d.write(0, 1, 'next') d.write(5, 1, '1\n2\n3') d.write(5, 2, '4n') d.vertical_line(x=5, y1=1, y2=2) d.horizontal_line(y=1, x1=0, x2=8) _assert_same_diagram( d.render().strip(), """ hello there 1 next──────────2────── 3 │ 4n """.strip(), ) d = TextDiagramDrawer() d.vertical_line(x=0, y1=0, y2=3) d.vertical_line(x=1, y1=0, y2=3) d.vertical_line(x=2, y1=0, y2=3) d.vertical_line(x=3, y1=0, y2=3) d.write(0, 0, 'long line\nshort') d.write(2, 2, 'short\nlong line') _assert_same_diagram( d.render().strip(), """ long line ╷ ╷ ╷ short │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ short │ │ │ long line │ │ │ │ │ """.strip(), )
def test_draw_entries_and_lines_with_emphasize(): d = TextDiagramDrawer() d.write(0, 0, '!') d.write(6, 2, 'span') d.horizontal_line(y=3, x1=2, x2=8, emphasize=True) d.horizontal_line(y=5, x1=2, x2=9, emphasize=False) d.vertical_line(x=7, y1=1, y2=6, emphasize=True) d.vertical_line(x=5, y1=1, y2=7, emphasize=False) assert d.render().strip() == """ ! │ ┃ │ ┃ │ span ┃ │ ┃ ━━━━━━┿━━━━━━╋━ │ ┃ │ ┃ │ ┃ ──────┼──────╂─── │ ┃ │ │ """.strip()