21
21
// MODULES //
22
22
23
23
var tape = require ( 'tape' ) ;
24
+ var DataType = require ( '@stdlib/ndarray/dtype-ctor' ) ;
25
+ var structFactory = require ( '@stdlib/dstructs/struct' ) ;
24
26
var dtypeAlignment = require ( './../lib' ) ;
25
27
26
28
@@ -37,8 +39,6 @@ var DTYPES = [
37
39
'uint16' ,
38
40
'int32' ,
39
41
'uint32' ,
40
- 'int64' ,
41
- 'uint64' ,
42
42
'binary' ,
43
43
'generic' ,
44
44
'complex32' ,
@@ -73,8 +73,6 @@ tape( 'the function returns an object mapping data type strings to alignments if
73
73
2 ,
74
74
4 ,
75
75
4 ,
76
- 8 ,
77
- 8 ,
78
76
1 ,
79
77
null ,
80
78
2 ,
@@ -91,7 +89,7 @@ tape( 'the function returns an object mapping data type strings to alignments if
91
89
t . end ( ) ;
92
90
} ) ;
93
91
94
- tape ( 'the function returns the alignment for an underlying array data type' , function test ( t ) {
92
+ tape ( 'the function returns the alignment for an underlying array data type (string) ' , function test ( t ) {
95
93
var expected ;
96
94
var out ;
97
95
var i ;
@@ -107,8 +105,36 @@ tape( 'the function returns the alignment for an underlying array data type', fu
107
105
2 ,
108
106
4 ,
109
107
4 ,
108
+ 1 ,
109
+ null ,
110
+ 2 ,
111
+ 4 ,
110
112
8 ,
113
+ 1
114
+ ] ;
115
+ for ( i = 0 ; i < DTYPES . length ; i ++ ) {
116
+ out = dtypeAlignment ( DTYPES [ i ] ) ;
117
+ t . strictEqual ( out , expected [ i ] , 'returns ' + expected [ i ] + ' when provided ' + DTYPES [ i ] ) ;
118
+ }
119
+ t . end ( ) ;
120
+ } ) ;
121
+
122
+ tape ( 'the function returns the alignment for an underlying array data type (data type, string)' , function test ( t ) {
123
+ var expected ;
124
+ var out ;
125
+ var i ;
126
+
127
+ expected = [
111
128
8 ,
129
+ 4 ,
130
+ 2 ,
131
+ 1 ,
132
+ 1 ,
133
+ 1 ,
134
+ 2 ,
135
+ 2 ,
136
+ 4 ,
137
+ 4 ,
112
138
1 ,
113
139
null ,
114
140
2 ,
@@ -117,12 +143,88 @@ tape( 'the function returns the alignment for an underlying array data type', fu
117
143
1
118
144
] ;
119
145
for ( i = 0 ; i < DTYPES . length ; i ++ ) {
120
- out = dtypeAlignment ( DTYPES [ i ] ) ;
146
+ out = dtypeAlignment ( new DataType ( DTYPES [ i ] ) ) ;
121
147
t . strictEqual ( out , expected [ i ] , 'returns ' + expected [ i ] + ' when provided ' + DTYPES [ i ] ) ;
122
148
}
123
149
t . end ( ) ;
124
150
} ) ;
125
151
152
+ tape ( 'the function returns the alignment for an underlying array data type (struct)' , function test ( t ) {
153
+ var expected ;
154
+ var schemas ;
155
+ var values ;
156
+ var out ;
157
+ var i ;
158
+
159
+ schemas = [
160
+ [
161
+ {
162
+ 'name' : 'foo' ,
163
+ 'type' : 'float64'
164
+ }
165
+ ] ,
166
+ [
167
+ {
168
+ 'name' : 'foo' ,
169
+ 'type' : 'float32'
170
+ }
171
+ ]
172
+ ] ;
173
+
174
+ values = [
175
+ structFactory ( schemas [ 0 ] ) ,
176
+ structFactory ( schemas [ 1 ] )
177
+ ] ;
178
+
179
+ expected = [
180
+ 8 ,
181
+ 4
182
+ ] ;
183
+ for ( i = 0 ; i < values . length ; i ++ ) {
184
+ out = dtypeAlignment ( values [ i ] ) ;
185
+ t . strictEqual ( out , expected [ i ] , 'returns ' + expected [ i ] + ' when provided ' + values [ i ] . layout ) ;
186
+ }
187
+ t . end ( ) ;
188
+ } ) ;
189
+
190
+ tape ( 'the function returns the alignment for an underlying array data type (data type, struct)' , function test ( t ) {
191
+ var expected ;
192
+ var schemas ;
193
+ var values ;
194
+ var out ;
195
+ var i ;
196
+
197
+ schemas = [
198
+ [
199
+ {
200
+ 'name' : 'foo' ,
201
+ 'type' : 'float64'
202
+ }
203
+ ] ,
204
+ [
205
+ {
206
+ 'name' : 'foo' ,
207
+ 'type' : 'float32'
208
+ }
209
+ ]
210
+ ] ;
211
+
212
+ values = [
213
+ new DataType ( structFactory ( schemas [ 0 ] ) ) ,
214
+ new DataType ( structFactory ( schemas [ 1 ] ) )
215
+ ] ;
216
+
217
+ expected = [
218
+ 8 ,
219
+ 4
220
+ ] ;
221
+ for ( i = 0 ; i < values . length ; i ++ ) {
222
+ out = dtypeAlignment ( values [ i ] ) ;
223
+ t . strictEqual ( out , expected [ i ] , 'returns ' + expected [ i ] + ' when provided ' + values [ i ] . layout ) ;
224
+ }
225
+ t . end ( ) ;
226
+ } ) ;
227
+
126
228
tape ( 'the function returns `null` if provided an unknown/unsupported data type' , function test ( t ) {
127
229
var values ;
128
230
var out ;
0 commit comments