def assert_url_to_circuit_returns(
    json_text: str,
    circuit: cirq.Circuit | None = None,
    *,
    unitary: np.ndarray | None = None,
    diagram: str | None = None,
    output_amplitudes_from_quirk: list[dict[str, float]] | None = None,
    maps: dict[int, int] | None = None,
):
    """Assert that `quirk_url_to_circuit` functions correctly.

    Args:
        json_text: The part of the quirk URL after "#circuit=".
        circuit: The optional expected circuit. If specified and not
            equal to the parsed circuit, an assertion fails.
        unitary: The optional expected unitary of the circuit. If specified
            and the parsed circuit has a different unitary, an assertion fails.
        diagram: The optional expected circuit diagram. If specified and the
            parsed circuit has a different diagram, an assertion fails.
        output_amplitudes_from_quirk: Optional data copied from Quirk's "export
            simulation data" function, for comparison to Cirq's simulator
            results. If specified and the output from the simulation differs
            from this data (after accounting for differences in endian-ness),
            an assertion fails.
        maps: Optional dictionary of test computational basis input states and
            the output computational basis state that they should be mapped to.
            If any state is mapped to the wrong thing, an assertion fails. Note
            that the states are specified using Quirk's little endian
            convention, meaning that the last bit of a binary literal will refer
            to the last qubit's value instead of vice versa.
    """
    parsed = quirk_url_to_circuit(f'https://algassert.com/quirk#circuit={json_text}')

    if diagram is not None:
        cirq.testing.assert_has_diagram(parsed, diagram)

    if circuit is not None:
        cirq.testing.assert_same_circuits(parsed, circuit)

    if unitary is not None:
        np.testing.assert_allclose(cirq.unitary(parsed), unitary, atol=1e-8)

    if output_amplitudes_from_quirk is not None:
        expected = np.array(
            [float(e['r']) + 1j * float(e['i']) for e in output_amplitudes_from_quirk]
        )

        np.testing.assert_allclose(
            cirq.final_state_vector(
                parsed,
                # Match Quirk's endian-ness for comparison purposes.
                qubit_order=sorted(parsed.all_qubits(), reverse=True),
            ),
            expected,
            atol=1e-8,
        )

    if maps:
        cirq.testing.assert_equivalent_computational_basis_map(maps, parsed)
Assert that `quirk_url_to_circuit` functions correctly.

    Args:
        json_text: The part of the quirk URL after "#circuit=".
        circuit: The optional expected circuit. If specified and not
            equal to the parsed circuit, an assertion fails.
        unitary: The optional expected unitary of the circuit. If specified
            and the parsed circuit has a different unitary, an assertion fails.
        diagram: The optional expected circuit diagram. If specified and the
            parsed circuit has a different diagram, an assertion fails.
        output_amplitudes_from_quirk: Optional data copied from Quirk's "export
            simulation data" function, for comparison to Cirq's simulator
            results. If specified and the output from the simulation differs
            from this data (after accounting for differences in endian-ness),
            an assertion fails.
        maps: Optional dictionary of test computational basis input states and
            the output computational basis state that they should be mapped to.
            If any state is mapped to the wrong thing, an assertion fails. Note
            that the states are specified using Quirk's little endian
            convention, meaning that the last bit of a binary literal will refer
            to the last qubit's value instead of vice versa.
    
cirq-core/cirq/interop/quirk/cells/testing.py