Beispiel #1
0
def assert_has_qcircuit_diagram(actual: cirq.Circuit, desired: str,
                                **kwargs) -> None:
    """Determines if a given circuit has the desired qcircuit diagram.

    Args:
        actual: The circuit that was actually computed by some process.
        desired: The desired qcircuit diagram as a string. Newlines at the
            beginning and whitespace at the end are ignored.
        **kwargs: Keyword arguments to be passed to
            circuit_to_latex_using_qcircuit.
    """
    actual_diagram = ccq.circuit_to_latex_using_qcircuit(
        actual, **kwargs).lstrip('\n').rstrip()
    desired_diagram = desired.lstrip("\n").rstrip()
    assert actual_diagram == desired_diagram, (
        "Circuit's qcircuit diagram differs from the desired diagram.\n"
        '\n'
        'Diagram of actual circuit:\n'
        '{}\n'
        '\n'
        'Desired qcircuit diagram:\n'
        '{}\n'
        '\n'
        'Highlighted differences:\n'
        '{}\n'.format(
            actual_diagram,
            desired_diagram,
            ct.highlight_text_differences(actual_diagram, desired_diagram),
        ))
Beispiel #2
0
def assert_has_rendering(actual: TextDiagramDrawer, desired: str,
                         **kwargs) -> None:
    """Determines if a given diagram has the desired rendering.

    Args:
        actual: The text diagram.
        desired: The desired rendering as a string.
        **kwargs: Keyword arguments to be passed to actual.render.
    """
    actual_diagram = actual.render(**kwargs)
    desired_diagram = desired
    assert actual_diagram == desired_diagram, (
        "Diagram's rendering differs from the desired rendering.\n"
        '\n'
        'Actual rendering:\n'
        '{}\n'
        '\n'
        'Desired rendering:\n'
        '{}\n'
        '\n'
        'Highlighted differences:\n'
        '{}\n'.format(
            actual_diagram,
            desired_diagram,
            ct.highlight_text_differences(actual_diagram, desired_diagram),
        ))