Commit 43de4852 authored by telamonian's avatar telamonian

added unit test for bool dtype

parent c2b03e5a
...@@ -36,3 +36,8 @@ TAGS ...@@ -36,3 +36,8 @@ TAGS
MANIFEST MANIFEST
.tox .tox
# Jetbrains IDE project files
/.idea
/*.iml
...@@ -134,6 +134,7 @@ try: ...@@ -134,6 +134,7 @@ try:
... ...
ValueError: ndarray is not C...contiguous ValueError: ndarray is not C...contiguous
>>> test_dtype('?', inc1_bool)
>>> test_dtype('b', inc1_byte) >>> test_dtype('b', inc1_byte)
>>> test_dtype('B', inc1_ubyte) >>> test_dtype('B', inc1_ubyte)
>>> test_dtype('h', inc1_short) >>> test_dtype('h', inc1_short)
...@@ -340,6 +341,7 @@ def test_f_contig(np.ndarray[int, ndim=2, mode='fortran'] arr): ...@@ -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])]) 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 # 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_byte(np.ndarray[char] arr): arr[1] += 1
def inc1_ubyte(np.ndarray[unsigned 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 def inc1_short(np.ndarray[short] arr): arr[1] += 1
...@@ -402,6 +404,13 @@ def test_dtype(dtype, inc1): ...@@ -402,6 +404,13 @@ def test_dtype(dtype, inc1):
a = np.array([0, 10+10j], dtype=dtype) a = np.array([0, 10+10j], dtype=dtype)
inc1(a) inc1(a)
if a[1] != (11 + 11j): print u"failed!", a[1] 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: else:
a = np.array([0, 10], dtype=dtype) a = np.array([0, 10], dtype=dtype)
inc1(a) inc1(a)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment