File: unit

package info (click to toggle)
libvbz-hdf-plugin 1.0.2-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,384 kB
  • sloc: cpp: 28,289; python: 392; ansic: 40; sh: 21; makefile: 19; xml: 16
file content (123 lines) | stat: -rwxr-xr-x 2,906 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3

import numpy as np
from unittest import TestCase, main
from vbz import compress, decompress, compression_options
from numpy.testing import assert_array_equal


class Tests:
    vbz_version = None

    """ Base test functions for all 3 encoding/decoding functions """
    def test_decode(self):
        """ S1: simple decode """
        options = None
        if self.vbz_version:
            zigzag = np.issubdtype(self.data.dtype, np.signedinteger)
            options = compression_options(zigzag, self.data.dtype.itemsize, 1, self.vbz_version)

        res = compress(self.data, options)
        rec = decompress(res, self.dtype, options)
        assert_array_equal(self.data, rec)


class BasicTest(Tests):
    """ Base test for encoding and decoding with small simple test case """
    def setUp(self):
        self.data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=self.dtype)

class RandTest(Tests):
    """ Base test encoding and decoding with large random array """
    def setUp(self):
        self.data = np.random.randint(self.rmin, self.rmax, size=self.size, dtype=self.dtype)

# Default configuration test (default options)
class BasicTestInt8(BasicTest, TestCase):
    dtype = np.int8

class BasicTestUInt8(BasicTest, TestCase):
    dtype = np.uint8


class BasicTestInt16(BasicTest, TestCase):
    dtype = np.int16

class BasicTestUInt16(BasicTest, TestCase):
    dtype = np.uint16


class BasicTestInt32(BasicTest, TestCase):
    dtype = np.int32

class BasicTestUInt32(BasicTest, TestCase):
    dtype = np.uint32


# Using v1 (half support test)
class BasicV1TestInt8(BasicTestInt8):
    vbz_version = 1

class BasicV1TestUInt8(BasicTestUInt8):
    vbz_version = 1

class BasicV1TestInt16(BasicTestInt16):
    vbz_version = 1

class BasicV1TestUInt16(BasicTestUInt16):
    vbz_version = 1

# Default configuration test (default options)
class RandTestInt8(RandTest, TestCase):
    dtype = np.int8
    rmin = -2**7
    rmax = 2**7 -1
    size = 200000

class RandTestUInt8(RandTest, TestCase):
    dtype = np.uint8
    rmin = 0
    rmax = 2**7 -1
    size = 200000


class RandTestInt16(RandTest, TestCase):
    dtype = np.int16
    rmin = -2**15
    rmax = 2**15 -1
    size = 200000

class RandTestUInt16(RandTest, TestCase):
    dtype = np.uint16
    rmin = 0
    rmax = 2**15 - 1
    size = 200000


class RandTestInt32(RandTest, TestCase):
    dtype = np.int32
    rmin = -2**31
    rmax = 2**31 - 1
    size = 200000

class RandTestIntU32(RandTest, TestCase):
    dtype = np.uint32
    rmin = 0
    rmax = 2**31 - 1
    size = 200000

# Random tests Using v1 (half support test)
class RandV1TestInt8(RandTestInt8):
    vbz_version = 1

class RandV1TestUInt8(RandTestUInt8):
    vbz_version = 1

class RandV1TestInt16(RandTestUInt16):
    vbz_version = 1

class RandV1TestUInt16(RandTestUInt16):
    vbz_version = 1

if __name__ == '__main__':
    main()