Skip to content

Commit 0b4a61c

Browse files
committed
Added tests for endianness [skip ci]
1 parent 88bef31 commit 0b4a61c

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

tests/test_half_vector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def test_list_list(self) -> None:
3030

3131
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3232
def test_ndarray(self) -> None:
33-
arr = np.array([1, 2, 3])
33+
arr = np.array([1, 2, 3], dtype=np.float16)
3434
assert HalfVector(arr).to_list() == [1, 2, 3]
3535
assert HalfVector(arr).to_numpy() is not arr
3636
assert HalfVector(arr).to_numpy().dtype == np.float16
3737
# non-contiguous
3838
assert HalfVector(np.flip(arr)).to_list() == [3, 2, 1]
3939
assert HalfVector(np.flip(arr)).to_binary() == HalfVector([3, 2, 1]).to_binary()
40+
# big endian
41+
assert HalfVector(arr.astype('>f2')).to_list() == [1, 2, 3]
42+
assert HalfVector(arr.astype('>f2')).to_binary() == HalfVector([1, 2, 3]).to_binary()
4043

4144
def test_int(self) -> None:
4245
with pytest.raises(ValueError) as error:

tests/test_vector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def test_list_list(self) -> None:
3030

3131
@pytest.mark.skipif(not NUMPY_AVAILABLE, reason='NumPy required')
3232
def test_ndarray(self) -> None:
33-
arr = np.array([1, 2, 3])
33+
arr = np.array([1, 2, 3], dtype=np.float32)
3434
assert Vector(arr).to_list() == [1, 2, 3]
3535
assert Vector(arr).to_numpy() is not arr
3636
assert Vector(arr).to_numpy().dtype == np.float32
3737
# non-contiguous
3838
assert Vector(np.flip(arr)).to_list() == [3, 2, 1]
3939
assert Vector(np.flip(arr)).to_binary() == Vector([3, 2, 1]).to_binary()
40+
# big endian
41+
assert Vector(arr.astype('>f4')).to_list() == [1, 2, 3]
42+
assert Vector(arr.astype('>f4')).to_binary() == Vector([1, 2, 3]).to_binary()
4043

4144
def test_int(self) -> None:
4245
with pytest.raises(ValueError) as error:

0 commit comments

Comments
 (0)