diff --git a/tests/test_decoder.py b/tests/test_decoder.py index 84ef1d7..248e915 100644 --- a/tests/test_decoder.py +++ b/tests/test_decoder.py @@ -538,6 +538,33 @@ def test_bigfloat(impl): decoded = impl.loads(unhexlify("c5822003")) assert decoded == Decimal("1.5") +@pytest.mark.parametrize( + "payload, expected", + [ + ("d9a7f882f90000f90000", 0.0j), + ("d9a7f882fb0000000000000000fb0000000000000000", 0.0j), + ("d9a7f882f98000f98000", -0.0j), + ("d9a7f882f90000f93c00", 1.0j), + ("d9a7f882fb0000000000000000fb3ff199999999999a", 1.1j), + ("d9a7f882f93e00f93e00", 1.5+1.5j), + ("d9a7f882f97bfff97bff", 65504.0+65504.0j), + ("d9a7f882fa47c35000fa47c35000", 100000.0+100000.0j), + ("fa7f7fffff", 3.4028234663852886e38), + ("d9a7f882f90000fb7e37e43c8800759c", 1.0e300j), + ("d9a7f882f90000f90001", 5.960464477539063e-8j), + ("d9a7f882f90000f90400", 0.00006103515625j), + ("d9a7f882f90000f9c400", -4.0j), + ("d9a7f882f90000fbc010666666666666", -4.1j), + ("d9a7f882f90000f97c00", complex(0.0, float("inf"))), + ("d9a7f882f97c00f90000", complex(float("inf"), 0.0)), + ("d9a7f882f90000f9fc00", complex(0.0, float("-inf"))), + ("d9a7f882f90000fa7f800000", complex(0.0, float("inf"))), + ("d9a7f882f90000faff800000", complex(0.0, float("-inf"))), + ], +) +def test_complex(impl, payload, expected): + decoded = impl.loads(unhexlify(payload)) + assert decoded == expected def test_rational(impl): decoded = impl.loads(unhexlify("d81e820205")) diff --git a/tests/test_encoder.py b/tests/test_encoder.py index f2ef248..715c81e 100644 --- a/tests/test_encoder.py +++ b/tests/test_encoder.py @@ -324,6 +324,21 @@ def test_decimal(impl, value, expected): assert impl.dumps(value) == expected +@pytest.mark.parametrize( + "value, expected", + [ + (3.1 + 2.1j, "d9a7f882fb4008cccccccccccdfb4000cccccccccccd"), + (1.0e300j, "d9a7f882fb0000000000000000fb7e37e43c8800759c"), + (0.0j, "d9a7f882fb0000000000000000fb0000000000000000"), + (complex(float("inf"), float("inf")), "d9a7f882f97c00f97c00"), + (complex(float("inf"), 0.0), "d9a7f882f97c00fb0000000000000000"), + (complex(float("nan"), float("inf")), "d9a7f882f97e00f97c00"), + ], +) +def test_complex(impl, value, expected): + expected = unhexlify(expected) + assert impl.dumps(value) == expected + def test_rational(impl): expected = unhexlify("d81e820205") assert impl.dumps(Fraction(2, 5)) == expected