|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from __future__ import absolute_import, print_function, division |
| 3 | +import itertools |
| 4 | + |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +from nose.tools import assert_raises |
| 8 | + |
| 9 | + |
| 10 | +from numcodecs.checksum32 import CRC32, Adler32 |
| 11 | +from numcodecs.tests.common import check_encode_decode, check_config, \ |
| 12 | + check_repr |
| 13 | + |
| 14 | + |
| 15 | +# mix of dtypes: integer, float, bool, string |
| 16 | +# mix of shapes: 1D, 2D, 3D |
| 17 | +# mix of orders: C, F |
| 18 | +arrays = [ |
| 19 | + np.arange(1000, dtype='i4'), |
| 20 | + np.linspace(1000, 1001, 1000, dtype='f8'), |
| 21 | + np.random.normal(loc=1000, scale=1, size=(100, 10)), |
| 22 | + np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'), |
| 23 | + np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10) |
| 24 | +] |
| 25 | + |
| 26 | +codecs = [CRC32(), Adler32()] |
| 27 | + |
| 28 | + |
| 29 | +def test_encode_decode(): |
| 30 | + for codec, arr in itertools.product(codecs, arrays): |
| 31 | + check_encode_decode(arr, codec) |
| 32 | + |
| 33 | + |
| 34 | +def test_errors(): |
| 35 | + for codec, arr in itertools.product(codecs, arrays): |
| 36 | + enc = codec.encode(arr) |
| 37 | + with assert_raises(RuntimeError): |
| 38 | + codec.decode(enc[:-1]) |
| 39 | + |
| 40 | + |
| 41 | +def test_config(): |
| 42 | + for codec in codecs: |
| 43 | + check_config(codec) |
| 44 | + |
| 45 | + |
| 46 | +def test_repr(): |
| 47 | + check_repr("CRC32()") |
| 48 | + check_repr("Adler32()") |
0 commit comments