blob: 0e42c68d6cd688fe33d7630bf44c439f11e24841 [file] [log] [blame]
Ivan Smirnovbb4015d2016-06-19 15:50:31 +01001#!/usr/bin/env python
2from __future__ import print_function
3
4import numpy as np
Ivan Smirnov8502f542016-06-19 16:09:44 +01005from example import create_rec_simple, create_rec_packed
Ivan Smirnovbb4015d2016-06-19 15:50:31 +01006
7
8def check_eq(arr, data, dtype):
9 np.testing.assert_equal(arr, np.array(data, dtype=dtype))
10
Ivan Smirnov8502f542016-06-19 16:09:44 +010011simple_dtype = np.dtype({'names': ['x', 'y', 'z'],
12 'formats': ['?', 'u4', 'f4'],
13 'offsets': [0, 4, 8]})
14packed_dtype = np.dtype([('x', '?'), ('y', 'u4'), ('z', 'f4')])
Ivan Smirnovbb4015d2016-06-19 15:50:31 +010015
Ivan Smirnov8502f542016-06-19 16:09:44 +010016for func, dtype in [(create_rec_simple, simple_dtype), (create_rec_packed, packed_dtype)]:
17 arr = func(3)
18 assert arr.dtype == dtype
19 check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], simple_dtype)
20 check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], packed_dtype)
Ivan Smirnov2e1565e2016-06-19 16:05:23 +010021
Ivan Smirnov8502f542016-06-19 16:09:44 +010022 arr = func(0)
23 assert arr.dtype == dtype
24 check_eq(arr, [], simple_dtype)
25 check_eq(arr, [], packed_dtype)