|
7 | 7 | import numpy as np |
8 | 8 | import pytest |
9 | 9 |
|
| 10 | +from tests.conftest import Expect |
10 | 11 | from zarr.core.common import ( |
11 | 12 | ANY_ACCESS_MODE, |
12 | 13 | AccessModeLiteral, |
@@ -35,27 +36,40 @@ def test_ceildiv(a: float, b: float, expected: int) -> None: |
35 | 36 |
|
36 | 37 |
|
37 | 38 | @pytest.mark.parametrize( |
38 | | - ("a", "b", "expected"), |
| 39 | + "case", |
39 | 40 | [ |
40 | | - (0, 3, 0), |
41 | | - (7, 3, 3), |
42 | | - (9, 3, 3), |
43 | | - (-7, 3, -2), |
44 | | - (7, -3, -2), |
45 | | - (-7, -3, 3), |
46 | | - (2**62 - 1, 1, 2**62 - 1), |
47 | | - (2**62 + 1, 2, 2**61 + 1), |
48 | | - (2**60 + 3, 1, 2**60 + 3), |
49 | | - (np.int64(2**62 - 1), np.int64(1), 2**62 - 1), |
50 | | - (np.int64(-(2**63)), np.int64(-1), 2**63), |
51 | | - (np.uint64(2**64 - 1), np.uint64(2), 2**63), |
| 41 | + Expect(input=(0, 3), output=0, id="zero"), |
| 42 | + Expect(input=(7, 3), output=3, id="round-up"), |
| 43 | + Expect(input=(9, 3), output=3, id="exact"), |
| 44 | + Expect(input=(-7, 3), output=-2, id="negative-numerator"), |
| 45 | + Expect(input=(7, -3), output=-2, id="negative-divisor"), |
| 46 | + Expect(input=(-7, -3), output=3, id="both-negative"), |
| 47 | + Expect(input=(2**62 - 1, 1), output=2**62 - 1, id="large-exact"), |
| 48 | + Expect(input=(2**62 + 1, 2), output=2**61 + 1, id="large-round-up"), |
| 49 | + Expect(input=(2**60 + 3, 1), output=2**60 + 3, id="large-low-bits"), |
| 50 | + Expect( |
| 51 | + input=(np.int64(2**62 - 1), np.int64(1)), |
| 52 | + output=2**62 - 1, |
| 53 | + id="numpy-signed", |
| 54 | + ), |
| 55 | + Expect( |
| 56 | + input=(np.int64(-(2**63)), np.int64(-1)), |
| 57 | + output=2**63, |
| 58 | + id="numpy-signed-minimum", |
| 59 | + ), |
| 60 | + Expect( |
| 61 | + input=(np.uint64(2**64 - 1), np.uint64(2)), |
| 62 | + output=2**63, |
| 63 | + id="numpy-unsigned-maximum", |
| 64 | + ), |
52 | 65 | ], |
| 66 | + ids=lambda case: case.id, |
53 | 67 | ) |
54 | | -def test_ceildiv_int(a: int, b: int, expected: int) -> None: |
| 68 | +def test_ceildiv_int(case: Expect[tuple[int, int], int]) -> None: |
55 | 69 | from zarr.core.common import ceildiv_int |
56 | 70 |
|
57 | | - result = ceildiv_int(a, b) |
58 | | - assert result == expected |
| 71 | + result = ceildiv_int(*case.input) |
| 72 | + assert result == case.output |
59 | 73 | assert isinstance(result, int) |
60 | 74 |
|
61 | 75 |
|
|
0 commit comments