From 8502f542b36d0cbb1f3af532300df149f9ca773a Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Sun, 19 Jun 2016 16:09:44 +0100 Subject: [PATCH] Add packed recarray tests --- example/example20.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/example/example20.py b/example/example20.py index d1bc94238..0e42c68d6 100644 --- a/example/example20.py +++ b/example/example20.py @@ -2,23 +2,24 @@ from __future__ import print_function import numpy as np -from example import create_rec_simple +from example import create_rec_simple, create_rec_packed def check_eq(arr, data, dtype): np.testing.assert_equal(arr, np.array(data, dtype=dtype)) -dtype = np.dtype({'names': ['x', 'y', 'z'], - 'formats': ['?', 'u4', 'f4'], - 'offsets': [0, 4, 8]}) -base_dtype = np.dtype([('x', '?'), ('y', 'u4'), ('z', 'f4')]) +simple_dtype = np.dtype({'names': ['x', 'y', 'z'], + 'formats': ['?', 'u4', 'f4'], + 'offsets': [0, 4, 8]}) +packed_dtype = np.dtype([('x', '?'), ('y', 'u4'), ('z', 'f4')]) -arr = create_rec_simple(3) -assert arr.dtype == dtype -check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], dtype) -check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], base_dtype) +for func, dtype in [(create_rec_simple, simple_dtype), (create_rec_packed, packed_dtype)]: + arr = func(3) + assert arr.dtype == dtype + check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], simple_dtype) + check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], packed_dtype) -arr = create_rec_simple(0) -assert arr.dtype == dtype -check_eq(arr, [], dtype) -check_eq(arr, [], base_dtype) + arr = func(0) + assert arr.dtype == dtype + check_eq(arr, [], simple_dtype) + check_eq(arr, [], packed_dtype)