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): diagram.grid_line(q.col, q.row, q2.col, q2.row) return diagram.render(horizontal_spacing=3, vertical_spacing=2, use_unicode_characters=True)
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): diagram.grid_line(q.col, q.row, q2.col, q2.row) return diagram.render( horizontal_spacing=3, vertical_spacing=2, use_unicode_characters=True)
def __str__(self) -> str: diagram = TextDiagramDrawer() dx = min(q.col for q in self) dy = min(q.row for q in self) for q in self: diagram.write(q.col - dx, q.row - dy, str(q)) for q1, q2 in zip(self, self[1:]): diagram.grid_line(q1.col - dx, q1.row - dy, q2.col - dx, q2.row - dy, True) return diagram.render(horizontal_spacing=2, vertical_spacing=1, use_unicode_characters=True)
def __str__(self): diagram = TextDiagramDrawer() dx = min(q.col for q in self) dy = min(q.row for q in self) for q in self: diagram.write(q.col - dx, q.row - dy, str(q)) for q1, q2 in zip(self, self[1:]): diagram.grid_line(q1.col - dx, q1.row - dy, q2.col - dx, q2.row - dy, True) return diagram.render(horizontal_spacing=2, vertical_spacing=1, use_unicode_characters=True)
def test_draw_entries_and_lines_with_emphasize(): d = TextDiagramDrawer() d.write(0, 0, '!') d.write(6, 2, 'span') d.grid_line(2, 3, 8, 3, True) d.grid_line(7, 1, 7, 4, True) print(d.render().strip()) assert d.render().strip() == """ ! ┃ ┃ span ┃ ┃ ━━━━━━━━━━━━━━━ ┃ """.strip()
def test_line_fails_when_not_aligned(): d = TextDiagramDrawer() with pytest.raises(ValueError): d.grid_line(1, 2, 3, 4)
def test_line_detects_vertical(): d = TextDiagramDrawer() with mock.patch.object(d, 'horizontal_line') as horizontal_line: d.grid_line(2, 1, 5, 1, True) horizontal_line.assert_called_once_with(1, 2, 5, True)
def test_line_detects_horizontal(): d = TextDiagramDrawer() with mock.patch.object(d, 'vertical_line') as vertical_line: d.grid_line(1, 2, 1, 5, True) vertical_line.assert_called_once_with(1, 2, 5, True)
def test_line_fails_when_not_aligned(): d = TextDiagramDrawer() with pytest.raises(ValueError): d.grid_line(1, 2, 3, 4)