Skip to content

Commit

Permalink
added unit test for bool dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Oct 23, 2018
1 parent c2b03e5 commit 43de485
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ TAGS
MANIFEST

.tox

# Jetbrains IDE project files
/.idea
/*.iml

9 changes: 9 additions & 0 deletions tests/run/numpy_test.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ try:
...
ValueError: ndarray is not C...contiguous
>>> test_dtype('?', inc1_bool)
>>> test_dtype('b', inc1_byte)
>>> test_dtype('B', inc1_ubyte)
>>> test_dtype('h', inc1_short)
Expand Down Expand Up @@ -340,6 +341,7 @@ def test_f_contig(np.ndarray[int, ndim=2, mode='fortran'] arr):
print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])])

# Exhaustive dtype tests -- increments element [1] by 1 (or 1+1j) for all dtypes
def inc1_bool(np.ndarray[unsigned char] arr): arr[1] += 1
def inc1_byte(np.ndarray[char] arr): arr[1] += 1
def inc1_ubyte(np.ndarray[unsigned char] arr): arr[1] += 1
def inc1_short(np.ndarray[short] arr): arr[1] += 1
Expand Down Expand Up @@ -402,6 +404,13 @@ def test_dtype(dtype, inc1):
a = np.array([0, 10+10j], dtype=dtype)
inc1(a)
if a[1] != (11 + 11j): print u"failed!", a[1]
elif dtype == '?':
# bool ndarrays coerce all values to 0 or 1
a = np.array([0, 0], dtype=dtype)
inc1(a)
if a[1] != 1: print u"failed!"
inc1(a)
if a[1] != 1: print u"failed!"
else:
a = np.array([0, 10], dtype=dtype)
inc1(a)
Expand Down

0 comments on commit 43de485

Please sign in to comment.