Пример #1
0
    def test_i_parse_random_string_array(self):
        '''    Verify random word arrays are parsed correctly
        '''
        ##
        # RND

        # 3 dims
        for wlen in range(10):
            arr, shape = genRndByteArr(wlen, [7, 3], wlen > 5)
            P = c3d.Param('STRING_TEST',
                          self.dtypes,
                          bytes_per_element=-1,
                          dimensions=shape,
                          bytes=arr.T.tobytes())
            arr_out = P.string_array

            assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
                (str(arr_out.shape), str(arr.T.shape))
            for i in np.ndindex(arr_out.shape):
                assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                    "Mismatch in 'string_array' converted value at index %s" % str(i)

        # 4 dims
        for wlen in range(10):
            arr, shape = genRndByteArr(wlen, [7, 5, 3], wlen > 5)
            P = c3d.Param('STRING_TEST',
                          self.dtypes,
                          bytes_per_element=-1,
                          dimensions=shape,
                          bytes=arr.T.tobytes())
            arr_out = P.string_array

            assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
                (str(arr_out.shape), str(arr.T.shape))
            for i in np.ndindex(arr_out.shape):
                assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                    "Mismatch in 'string_array' converted value at index %s" % str(i)

        # 5 dims
        for wlen in range(10):
            arr, shape = genRndByteArr(wlen, [7, 6, 5, 3], wlen > 5)
            P = c3d.Param('STRING_TEST',
                          self.dtypes,
                          bytes_per_element=-1,
                          dimensions=shape,
                          bytes=arr.T.tobytes())
            arr_out = P.string_array

            assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
                (str(arr_out.shape), str(arr.T.shape))
            for i in np.ndindex(arr_out.shape):
                assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                    "Mismatch in 'string_array' converted value at index %s" % str(i)
Пример #2
0
    def test_h_parse_string_array(self):
        '''    Verify repeated word arrays are parsed correctly
        '''
        word = b'ANCLE'

        # 3 dims
        arr, shape = genByteWordArr(word, [7, 3])
        P = c3d.Param('STRING_TEST',
                      self.dtypes,
                      bytes_per_element=-1,
                      dimensions=shape,
                      bytes=arr.T.tobytes())
        arr_out = P.string_array

        assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
            (str(arr_out.shape), str(arr.T.shape))
        for i in np.ndindex(arr_out.shape):
            assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                "Mismatch in 'string_array' converted value at index %s" % str(i)

        # 4 dims
        arr, shape = genByteWordArr(word, [5, 4, 3])
        P = c3d.Param('STRING_TEST',
                      self.dtypes,
                      bytes_per_element=-1,
                      dimensions=shape,
                      bytes=arr.T.tobytes())
        arr_out = P.string_array

        assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
            (str(arr_out.shape), str(arr.T.shape))
        for i in np.ndindex(arr_out.shape):
            assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                "Mismatch in 'string_array' converted value at index %s" % str(i)

        # 5 dims
        arr, shape = genByteWordArr(word, [6, 5, 4, 3])
        P = c3d.Param('STRING_TEST',
                      self.dtypes,
                      bytes_per_element=-1,
                      dimensions=shape,
                      bytes=arr.T.tobytes())
        arr_out = P.string_array

        assert arr.T.shape == arr_out.shape, "Mismatch in 'string_array' converted shape. Was %s, expected %s" %\
            (str(arr_out.shape), str(arr.T.shape))
        for i in np.ndindex(arr_out.shape):
            assert self.dtypes.decode_string(arr[i[::-1]]) == arr_out[i],\
                "Mismatch in 'string_array' converted value at index %s" % str(i)
Пример #3
0
    def test_g_parse_byte_array(self):
        '''    Verify byte arrays are parsed correctly
        '''
        word = b'WRIST'

        # 1 dims
        arr = np.array(word).repeat(3).repeat(3).repeat(3)
        P = c3d.Param('BYTE_TEST',
                      self.dtypes,
                      bytes_per_element=1,
                      dimensions=arr.shape,
                      bytes=arr.T.tobytes())
        arr_out = P.bytes_array
        assert arr.shape[
            1:] == arr_out.shape, "Mismatch in 'bytes_array' converted shape"
        assert np.all(arr.tobytes() == arr_out
                      ), 'Mismatch in reading single dimensional byte array'

        # 4 dims
        arr, shape = genByteWordArr(word, [5, 4, 3])
        P = c3d.Param('BYTE_TEST',
                      self.dtypes,
                      bytes_per_element=1,
                      dimensions=shape,
                      bytes=arr.T.tobytes())
        arr_out = P.bytes_array

        assert arr.T.shape == arr_out.shape, "Mismatch in 'bytes_array' converted shape. Was %s, expected %s" %\
            (str(arr_out.shape), str(arr.T.shape))
        for i in np.ndindex(arr_out.shape):
            assert np.all(
                arr[i[::-1]] == arr_out[i]
            ), "Mismatch in 'bytes_array' converted value at index %s" % str(i)

        # 5 dims
        arr, shape = genByteWordArr(word, [6, 5, 4, 3])
        P = c3d.Param('BYTE_TEST',
                      self.dtypes,
                      bytes_per_element=1,
                      dimensions=shape,
                      bytes=arr.T.tobytes())
        arr_out = P.bytes_array

        assert arr.T.shape == arr_out.shape, "Mismatch in 'bytes_array' converted shape. Was %s, expected %s" %\
            (str(arr_out.shape), str(arr.T.shape))
        for i in np.ndindex(arr_out.shape):
            assert np.all(
                arr[i[::-1]] == arr_out[i]
            ), "Mismatch in 'bytes_array' converted value at index %s" % str(i)
Пример #4
0
 def test_b_param_int8(self):
     '''    Verify a single 8 bit integer value is parsed correctly
     '''
     for i in range(ParameterValueTest.TEST_ITERATIONS):
         value = np.int8(self.rnd.uniform(*ParameterValueTest.RANGE_8_BIT))
         bytes = struct.pack('<b', value)
         P = c3d.Param('INT8_TEST',
                       self.dtypes,
                       bytes_per_element=1,
                       dimensions=[1],
                       bytes=bytes)
         value_out = P.int8_value
         assert value == value_out, 'Parameter int8 was not read correctly. Was %f, expected %f' %\
             (value_out, value)
Пример #5
0
 def test_b_param_uint32(self):
     '''    Verify a single 32 bit unsigned integer value is parsed correctly
     '''
     for i in range(ParameterValueTest.TEST_ITERATIONS):
         value = np.uint32(
             self.rnd.uniform(*ParameterValueTest.RANGE_32_UNSIGNED_BIT))
         bytes = struct.pack('<I', value)
         P = c3d.Param('UINT32_TEST',
                       self.dtypes,
                       bytes_per_element=4,
                       dimensions=[1],
                       bytes=bytes)
         value_out = P.int32_value
         assert value == value_out, 'Parameter uint32 was not read correctly. Was %f, expected %f' %\
             (value_out, value)
Пример #6
0
 def test_a_param_float32(self):
     '''    Verify a single 32 bit floating point value is parsed correctly
     '''
     for i in range(ParameterValueTest.TEST_ITERATIONS):
         value = np.float32(
             self.rnd.uniform(*ParameterValueTest.RANGE_32_BIT))
         bytes = struct.pack('<f', value)
         P = c3d.Param('FLOAT_TEST',
                       self.dtypes,
                       bytes_per_element=4,
                       dimensions=[1],
                       bytes=bytes)
         value_out = P.float_value
         assert value == value_out, 'Parameter float was not read correctly. Was %f, expected %f' %\
             (value_out, value)
Пример #7
0
    def test_f_parse_uint8_array(self):
        '''    Verify array of 8 bit unsigned integer values are parsed correctly
        '''
        flt_range = (0, 255)

        for shape in ParameterArrayTest.SHAPES:
            arr = self.rnd.uniform(flt_range[0], flt_range[1],
                                   size=shape).astype(np.uint8)
            P = c3d.Param('UINT8_TEST',
                          self.dtypes,
                          bytes_per_element=1,
                          dimensions=arr.shape,
                          bytes=arr.T.tobytes())
            arr_out = P.uint8_array
            assert arr.T.shape == arr_out.shape, "Mismatch in 'uint32_array' converted shape"
            assert np.all(
                arr.T == arr_out), 'Value mismatch when reading uint32 array'
Пример #8
0
    def test_d_parse_int16_array(self):
        '''    Verify array of 16 bit integer values are parsed correctly
        '''
        flt_range = (-1e4, 1e4)

        for shape in ParameterArrayTest.SHAPES:
            arr = self.rnd.uniform(flt_range[0], flt_range[1],
                                   size=shape).astype(np.int16)
            P = c3d.Param('INT16_TEST',
                          self.dtypes,
                          bytes_per_element=2,
                          dimensions=arr.shape,
                          bytes=arr.T.tobytes())
            arr_out = P.int16_array
            assert arr.T.shape == arr_out.shape, "Mismatch in 'int32_array' converted shape"
            assert np.all(
                arr.T == arr_out), 'Value mismatch when reading int32 array'
Пример #9
0
    def test_a_parse_float32_array(self):
        '''    Verify array of 32 bit floating point values are parsed correctly
        '''
        flt_range = (-1e6, 1e6)

        for shape in ParameterArrayTest.SHAPES:
            arr = self.rnd.uniform(flt_range[0], flt_range[1],
                                   size=shape).astype(np.float32)
            P = c3d.Param('FLOAT_TEST',
                          self.dtypes,
                          bytes_per_element=4,
                          dimensions=arr.shape,
                          bytes=arr.T.tobytes())
            arr_out = P.float_array
            assert arr.T.shape == arr_out.shape, "Mismatch in 'float_array' converted shape"
            assert np.all(
                arr.T == arr_out), 'Value mismatch when reading float array'