Skip to content

Commit 48f6e8b

Browse files
committed
test: add test case
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent e6a090b commit 48f6e8b

File tree

1 file changed

+143
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/flatten-by/test

1 file changed

+143
-0
lines changed

lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ tape( 'the function throws an error if provided an invalid `order` option', func
191191
}
192192
});
193193

194+
tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) {
195+
var values;
196+
var i;
197+
198+
values = [
199+
'5',
200+
5,
201+
NaN,
202+
true,
203+
false,
204+
null,
205+
void 0
206+
];
207+
for ( i = 0; i < values.length; i++ ) {
208+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
209+
}
210+
t.end();
211+
212+
function badValue( value ) {
213+
return function badValue() {
214+
flattenBy( zeros( [ 2, 2, 2 ] ), {}, value );
215+
};
216+
}
217+
});
218+
194219
tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (row-major, contiguous)', function test( t ) {
195220
var expected;
196221
var xbuf;
@@ -291,6 +316,65 @@ tape( 'the function supports specifying the callback execution context (row-majo
291316
}
292317
});
293318

319+
tape( 'the function supports specifying the callback execution context (row-major, contiguous, options)', function test( t ) {
320+
var expected;
321+
var xbuf;
322+
var opts;
323+
var ord;
324+
var ctx;
325+
var sh;
326+
var st;
327+
var dt;
328+
var o;
329+
var x;
330+
var y;
331+
332+
dt = 'float64';
333+
ord = 'row-major';
334+
sh = [ 2, 2, 2 ];
335+
st = shape2strides( sh, ord );
336+
o = strides2offset( sh, st );
337+
338+
/*
339+
* [
340+
* [
341+
* [ 1.0, 2.0 ],
342+
* [ 3.0, 4.0 ]
343+
* ],
344+
* [
345+
* [ 5.0, 6.0 ],
346+
* [ 7.0, 8.0 ]
347+
* ]
348+
* ]
349+
*/
350+
xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
351+
x = new ndarray( dt, xbuf, sh, st, o, ord );
352+
ctx = {
353+
'count': 1
354+
};
355+
opts = {
356+
'depth': 2
357+
};
358+
359+
y = flattenBy( x, opts, clbk, ctx );
360+
expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
361+
362+
t.notEqual( y, x, 'returns expected value' );
363+
t.notEqual( getData( y ), xbuf, 'returns expected value' );
364+
t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' );
365+
t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' );
366+
t.strictEqual( getDType( y ), dt, 'returns expected value' );
367+
t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' );
368+
t.strictEqual( ctx.count, 9, 'returns expected value' );
369+
370+
t.end();
371+
372+
function clbk( v ) {
373+
this.count += 1; // eslint-disable-line no-invalid-this
374+
return v;
375+
}
376+
});
377+
294378
tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (row-major, non-contiguous)', function test( t ) {
295379
var expected;
296380
var xbuf;
@@ -436,6 +520,65 @@ tape( 'the function supports specifying the callback execution context (column-m
436520
}
437521
});
438522

523+
tape( 'the function supports specifying the callback execution context (column-major, contiguous, options)', function test( t ) {
524+
var expected;
525+
var xbuf;
526+
var opts;
527+
var ord;
528+
var ctx;
529+
var sh;
530+
var st;
531+
var dt;
532+
var o;
533+
var x;
534+
var y;
535+
536+
dt = 'float64';
537+
ord = 'column-major';
538+
sh = [ 2, 2, 2 ];
539+
st = shape2strides( sh, ord );
540+
o = strides2offset( sh, st );
541+
542+
/*
543+
* [
544+
* [
545+
* [ 1.0, 2.0 ],
546+
* [ 3.0, 4.0 ]
547+
* ],
548+
* [
549+
* [ 5.0, 6.0 ],
550+
* [ 7.0, 8.0 ]
551+
* ]
552+
* ]
553+
*/
554+
xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
555+
x = new ndarray( dt, xbuf, sh, st, o, ord );
556+
ctx = {
557+
'count': 1
558+
};
559+
opts = {
560+
'depth': 2
561+
};
562+
563+
y = flattenBy( x, opts, clbk, ctx );
564+
expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] );
565+
566+
t.notEqual( y, x, 'returns expected value' );
567+
t.notEqual( getData( y ), xbuf, 'returns expected value' );
568+
t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' );
569+
t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' );
570+
t.strictEqual( getDType( y ), dt, 'returns expected value' );
571+
t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' );
572+
t.strictEqual( ctx.count, 9, 'returns expected value' );
573+
574+
t.end();
575+
576+
function clbk( v ) {
577+
this.count += 1; // eslint-disable-line no-invalid-this
578+
return v;
579+
}
580+
});
581+
439582
tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (column-major, non-contiguous)', function test( t ) {
440583
var expected;
441584
var xbuf;

0 commit comments

Comments
 (0)