def test_renormalize():
    operator = QubitOperator(((1, 'X'), (3, 'Y'), (8, 'Z')), 1)
    operator += QubitOperator(((2, 'Z'), (3, 'Y')), 1)
    operator.renormalize()
    for term in operator.terms:
        assert operator.terms[term] == pytest.approx(1 / numpy.sqrt(2.))
    assert operator.induced_norm(2) == pytest.approx(1.)
def test_renormalize_error():
    operator = QubitOperator()
    with pytest.raises(ZeroDivisionError):
        operator.renormalize()