def assert_controlled_and_controlled_by_identical(
    gate: ops.Gate,
    *,
    num_controls: Sequence[int] = (2, 1, 3, 10),
    control_values: Sequence[Sequence[int | Collection[int]] | None] | None = None,
) -> None:
    """Checks that gate.on().controlled_by() == gate.controlled().on()"""
    if control_values is not None:
        if len(num_controls) != len(control_values):
            raise ValueError("len(num_controls) != len(control_values)")
    for i, num_control in enumerate(num_controls):
        control_value = control_values[i] if control_values else None
        if control_value is not None and len(control_value) != num_control:
            raise ValueError(f"len(control_values[{i}]) != num_controls[{i}]")
        _assert_gate_consistent(gate, num_control, control_value)
Checks that gate.on().controlled_by() == gate.controlled().on()
cirq-core/cirq/testing/consistent_controlled_gate_op.py