@pytest.mark.parametrize('qubit_order', ([0, 1], [1, 0]))
def test_merge_operations_deterministic_order(qubit_order):
    q = cirq.LineQubit.range(2)
    c_orig = cirq.Circuit(cirq.identity_each(*q), cirq.H.on_each((q[i] for i in qubit_order)))
    cirq.testing.assert_has_diagram(c_orig, '\n0: ───I───H───\n      │\n1: ───I───H───')
    c_new = cirq.merge_operations(c_orig, (lambda op1, op2: (op2 if isinstance(op1.gate, cirq.IdentityGate) else None)))
    cirq.testing.assert_has_diagram(c_new, '\n0: ───H───────\n\n1: ───────H───')
@pytest.mark.parametrize('qubit_order', ([0, 1], [1, 0]))
def test_merge_operations_deterministic_order(qubit_order):
    q = cirq.LineQubit.range(2)
    c_orig = cirq.Circuit(cirq.identity_each(*q), cirq.H.on_each((q[i] for i in qubit_order)))
    cirq.testing.assert_has_diagram(c_orig, '\n0: ───I───H───\n      │\n1: ───I───H───')
    c_new = cirq.merge_operations(c_orig, (lambda op1, op2: (op2 if isinstance(op1.gate, cirq.IdentityGate) else None)))
    cirq.testing.assert_has_diagram(c_new, '\n0: ───H───────\n\n1: ───────H───')