Skip to content

Commit f6883db

Browse files
committed
test: use Expect cases for integer ceiling division
Assisted-by: Codex:GPT-6
1 parent a2fd657 commit f6883db

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

‎tests/test_common.py‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pytest
99

10+
from tests.conftest import Expect
1011
from zarr.core.common import (
1112
ANY_ACCESS_MODE,
1213
AccessModeLiteral,
@@ -35,27 +36,40 @@ def test_ceildiv(a: float, b: float, expected: int) -> None:
3536

3637

3738
@pytest.mark.parametrize(
38-
("a", "b", "expected"),
39+
"case",
3940
[
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+
),
5265
],
66+
ids=lambda case: case.id,
5367
)
54-
def test_ceildiv_int(a: int, b: int, expected: int) -> None:
68+
def test_ceildiv_int(case: Expect[tuple[int, int], int]) -> None:
5569
from zarr.core.common import ceildiv_int
5670

57-
result = ceildiv_int(a, b)
58-
assert result == expected
71+
result = ceildiv_int(*case.input)
72+
assert result == case.output
5973
assert isinstance(result, int)
6074

6175

0 commit comments

Comments
 (0)