Skip to content

Commit

Permalink
Add tests for floating point transforms in FixedScaleOffset (#566)
Browse files Browse the repository at this point in the history
* Add tests for floating point transforms in FixedScaleOffset

* Fix pytest argument
  • Loading branch information
dstansby authored Nov 7, 2024
1 parent 6fb781b commit d8a219f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions numcodecs/tests/test_fixedscaleoffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ def test_encode_decode():
check_encode_decode(arr, codec, precision=precision)


def test_encode():
@pytest.mark.parametrize(
("offset", "scale", "expected"),
[
(1000, 10, [0, 6, 11, 17, 22, 28, 33, 39, 44, 50]),
(1002.5, 10, [-25, -19, -14, -8, -3, 3, 8, 14, 19, 25]),
(1000, 0.5, [0, 0, 1, 1, 1, 1, 2, 2, 2, 2]),
],
)
def test_encode(offset: float, scale: float, expected: list[int]):
dtype = '<f8'
astype = '|u1'
codec = FixedScaleOffset(scale=10, offset=1000, dtype=dtype, astype=astype)
arr = np.linspace(1000, 1001, 10, dtype=dtype)
expect = np.array([0, 1, 2, 3, 4, 6, 7, 8, 9, 10], dtype=astype)
astype = np.int16
codec = FixedScaleOffset(scale=scale, offset=offset, dtype=dtype, astype=astype)
arr = np.linspace(1000, 1005, 10, dtype=dtype)
expect = np.array(expected, dtype=astype)
actual = codec.encode(arr)
assert_array_equal(expect, actual)
assert np.dtype(astype) == actual.dtype
Expand Down

0 comments on commit d8a219f

Please sign in to comment.