summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_packbits.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-12-02 12:00:39 -0500
committerCharles Harris <charlesr.harris@gmail.com>2014-12-02 12:00:39 -0500
commita6b0917f180999293fdebbce4ae1728b4e3f45ff (patch)
treef3728e29b090f898bab4bd9ca43ec009d2baa982 /numpy/lib/tests/test_packbits.py
parente31dcad0aca659acd89ca90ae5030731d0eccf91 (diff)
parent24effb6b7a075e23d85ea0b60ed8a607fe218c14 (diff)
downloadnumpy-a6b0917f180999293fdebbce4ae1728b4e3f45ff.tar.gz
Merge pull request #5319 from larsmans/c-fixes
MAINT: refactor packbits/unpackbits
Diffstat (limited to 'numpy/lib/tests/test_packbits.py')
-rw-r--r--numpy/lib/tests/test_packbits.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_packbits.py b/numpy/lib/tests/test_packbits.py
new file mode 100644
index 000000000..186e8960d
--- /dev/null
+++ b/numpy/lib/tests/test_packbits.py
@@ -0,0 +1,26 @@
+import numpy as np
+
+from numpy.testing import assert_array_equal, assert_equal, assert_raises
+
+
+def test_packbits():
+ # Copied from the docstring.
+ a = [[[1, 0, 1], [0, 1, 0]],
+ [[1, 1, 0], [0, 0, 1]]]
+ for dtype in [np.bool, np.uint8, np.int]:
+ arr = np.array(a, dtype=dtype)
+ b = np.packbits(arr, axis=-1)
+ assert_equal(b.dtype, np.uint8)
+ assert_array_equal(b, np.array([[[160], [64]], [[192], [32]]]))
+
+ assert_raises(TypeError, np.packbits, np.array(a, dtype=float))
+
+
+def test_unpackbits():
+ # Copied from the docstring.
+ a = np.array([[2], [7], [23]], dtype=np.uint8)
+ b = np.unpackbits(a, axis=1)
+ assert_equal(b.dtype, np.uint8)
+ assert_array_equal(b, np.array([[0, 0, 0, 0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 0, 1, 1, 1],
+ [0, 0, 0, 1, 0, 1, 1, 1]]))