Skip to content

Commit

Permalink
tests for complex scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
chillenb committed Nov 17, 2024
1 parent edd549b commit f9ab80f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
15 changes: 15 additions & 0 deletions tests/test_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9ab80f

Please sign in to comment.