Skip to content

Commit fcd9c66

Browse files
committed
Auto-generated commit
1 parent dcbb721 commit fcd9c66

File tree

3 files changed

+129
-12
lines changed

3 files changed

+129
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ A total of 24 issues were closed in this release:
558558

559559
<details>
560560

561+
- [`3cb98f3`](https://github.com/stdlib-js/stdlib/commit/3cb98f3aa714b97cb714d45688421e9ac416d31c) - **test:** add tests for full branch coverage _(by Athan Reines)_
562+
- [`71a48b0`](https://github.com/stdlib-js/stdlib/commit/71a48b0b0ad86ba66a8109852f3b305e8caa06a0) - **refactor:** guard against `null` and `undefined` input values _(by Athan Reines)_
561563
- [`3ab207e`](https://github.com/stdlib-js/stdlib/commit/3ab207e1606e1b763451994fcf50dfcfc8e7f135) - **test:** update require path _(by Athan Reines)_
562564
- [`9088669`](https://github.com/stdlib-js/stdlib/commit/9088669147241ff682f034b0a2c1382d53650936) - **test:** provide missing argument _(by Athan Reines)_
563565
- [`3304071`](https://github.com/stdlib-js/stdlib/commit/33040719d3718582bd866243ced74fb7f5b67a7c) - **test:** provide missing argument _(by Athan Reines)_

base/dtype-alignment/lib/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ function dtypeAlignment( dtype ) {
6161
if ( TABLE === void 0 ) {
6262
TABLE = table();
6363
}
64-
v = dtype.alignment;
65-
if ( isPositiveInteger( v ) ) {
66-
return v;
64+
if ( dtype ) {
65+
v = dtype.alignment;
66+
if ( isPositiveInteger( v ) ) {
67+
return v;
68+
}
69+
return TABLE[ resolve( dtype ) ] || null;
6770
}
68-
return TABLE[ resolve( dtype ) ] || null;
71+
return null;
6972
}
7073

7174

base/dtype-alignment/test/test.js

Lines changed: 120 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var DataType = require( './../../../dtype-ctor' );
25+
var structFactory = require( '@stdlib/dstructs/struct' );
2426
var dtypeAlignment = require( './../lib' );
2527

2628

@@ -37,8 +39,6 @@ var DTYPES = [
3739
'uint16',
3840
'int32',
3941
'uint32',
40-
'int64',
41-
'uint64',
4242
'binary',
4343
'generic',
4444
'complex32',
@@ -73,8 +73,6 @@ tape( 'the function returns an object mapping data type strings to alignments if
7373
2,
7474
4,
7575
4,
76-
8,
77-
8,
7876
1,
7977
null,
8078
2,
@@ -91,7 +89,7 @@ tape( 'the function returns an object mapping data type strings to alignments if
9189
t.end();
9290
});
9391

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 ) {
9593
var expected;
9694
var out;
9795
var i;
@@ -107,8 +105,36 @@ tape( 'the function returns the alignment for an underlying array data type', fu
107105
2,
108106
4,
109107
4,
108+
1,
109+
null,
110+
2,
111+
4,
110112
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 = [
111128
8,
129+
4,
130+
2,
131+
1,
132+
1,
133+
1,
134+
2,
135+
2,
136+
4,
137+
4,
112138
1,
113139
null,
114140
2,
@@ -117,14 +143,100 @@ tape( 'the function returns the alignment for an underlying array data type', fu
117143
1
118144
];
119145
for ( i = 0; i < DTYPES.length; i++ ) {
120-
out = dtypeAlignment( DTYPES[ i ] );
146+
out = dtypeAlignment( new DataType( DTYPES[ i ] ) );
121147
t.strictEqual( out, expected[ i ], 'returns '+expected[i]+' when provided '+DTYPES[i] );
122148
}
123149
t.end();
124150
});
125151

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+
126228
tape( 'the function returns `null` if provided an unknown/unsupported data type', function test( t ) {
127-
var out = dtypeAlignment( 'foobar' );
128-
t.strictEqual( out, null, 'returns expected value' );
229+
var values;
230+
var out;
231+
var i;
232+
233+
values = [
234+
'foobar',
235+
null
236+
];
237+
for ( i = 0; i < values.length; i++ ) {
238+
out = dtypeAlignment( values[ i ] );
239+
t.strictEqual( out, null, 'returns expected value when provided '+values[ i ] );
240+
}
129241
t.end();
130242
});

0 commit comments

Comments
 (0)