Skip to content

Commit

Permalink
Improve test coverage for gmpy2_mpc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Oct 24, 2023
1 parent 8f212ce commit 4bedc99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/gmpy2_mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,3 @@ static PyTypeObject MPC_Type =
GMPy_MPC_NewInit, /* tp_new */
0, /* tp_free */
};


21 changes: 21 additions & 0 deletions test/test_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,24 @@ def test_mpc_divmod():
@example(complex(-2))
def test_mpc_hash(c):
assert hash(mpc(c)) == hash(c)


def test_mpc_exc():
gmpy2.set_context(gmpy2.ieee(32))

ctx = gmpy2.get_context()
ctx.trap_overflow = True
ctx.trap_underflow = True

c = mpc(0.1 + 0.1j)

pytest.raises(gmpy2.UnderflowResultError, lambda: c**201)
pytest.raises(gmpy2.OverflowResultError, lambda: c**-201)

ctx.trap_inexact = True

pytest.raises(gmpy2.InexactResultError, lambda: mpc('0.1'))

ctx.trap_invalid = True

pytest.raises(gmpy2.InvalidOperationError, lambda: mpc(mpfr('nan')))

0 comments on commit 4bedc99

Please sign in to comment.