diff options
Diffstat (limited to 'numpy/lib/tests/test_packbits.py')
-rw-r--r-- | numpy/lib/tests/test_packbits.py | 22 |
1 files changed, 22 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..5551de794 --- /dev/null +++ b/numpy/lib/tests/test_packbits.py @@ -0,0 +1,22 @@ +import numpy as np + +from numpy.testing import assert_array_equal, assert_equal + + +def test_packbits(): + # Copied from the docstring. + a = np.array([[[1, 0, 1], [0, 1, 0]], + [[1, 1, 0], [0, 0, 1]]]) + b = np.packbits(a, axis=-1) + assert_equal(b.dtype, np.uint8) + assert_array_equal(b, np.array([[[160], [64]], [[192], [32]]])) + + +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]])) |