File size: 1,167 Bytes
64c992d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import os
import sys
import numpy as np
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import fixed_point as F # noqa: E402
def test_decode_int32_with_missing_marker():
values = np.array([10000, -2147483648, 25000], dtype=np.int32)
out = F.decode_fixed_point(values)
assert out[0] == 1.0
assert np.isnan(out[1])
assert out[2] == 2.5
def test_decode_int64_also_works():
# leveling_effect's existing test feeds int64, not just int32 -- the shared decoder must accept
# any integer dtype, not just int32.
values = np.array([10000, -2147483648, 25000], dtype=np.int64)
out = F.decode_fixed_point(values)
assert out[0] == 1.0
assert np.isnan(out[1])
assert out[2] == 2.5
def test_float_input_passes_through():
values = np.array([1.0, 2.5, float("nan")])
out = F.decode_fixed_point(values)
assert out[0] == 1.0
assert out[1] == 2.5
assert np.isnan(out[2])
def test_custom_scale_and_marker():
values = np.array([100, -1], dtype=np.int32)
out = F.decode_fixed_point(values, scale=100.0, missing_marker=-1)
assert out[0] == 1.0
assert np.isnan(out[1])
|