Skip to content

Commit 86f4a5d

Browse files
committed
test: add accessor tests
--- 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 91ef457 commit 86f4a5d

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

lib/node_modules/@stdlib/stats/base/max-by/test/test.max_by.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,31 @@ tape( 'the function supports view offsets', function test( t ) {
330330
t.end();
331331
});
332332

333+
tape( 'the function supports view offsets (accessors)', function test( t ) {
334+
var x0;
335+
var x1;
336+
var v;
337+
338+
x0 = new Float64Array([
339+
2.0,
340+
1.0, // 0
341+
2.0,
342+
-2.0, // 1
343+
-2.0,
344+
2.0, // 2
345+
3.0,
346+
4.0, // 3
347+
6.0
348+
]);
349+
350+
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
351+
352+
v = maxBy( 4, toAccessorArray( x1 ), 2, accessor );
353+
t.strictEqual( v, 8.0, 'returns expected value' );
354+
355+
t.end();
356+
});
357+
333358
tape( 'the function supports providing a callback execution context', function test( t ) {
334359
var ctx;
335360
var x;
@@ -348,3 +373,22 @@ tape( 'the function supports providing a callback execution context', function t
348373
return v * 2.0;
349374
}
350375
});
376+
377+
tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
378+
var ctx;
379+
var x;
380+
381+
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
382+
ctx = {
383+
'count': 0
384+
};
385+
maxBy( x.length, toAccessorArray( x ), 1, accessor, ctx );
386+
387+
t.strictEqual( ctx.count, x.length, 'returns expected value' );
388+
t.end();
389+
390+
function accessor( v ) {
391+
this.count += 1; // eslint-disable-line no-invalid-this
392+
return v * 2.0;
393+
}
394+
});

lib/node_modules/@stdlib/stats/base/max-by/test/test.ndarray.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,25 @@ tape( 'the function supports an offset parameter', function test( t ) {
323323
t.end();
324324
});
325325

326+
tape( 'the function supports an offset parameter (accessors)', function test( t ) {
327+
var x;
328+
var v;
329+
330+
x = [
331+
1.0,
332+
-2.0, // 0
333+
3.0,
334+
4.0, // 1
335+
5.0,
336+
-6.0 // 2
337+
];
338+
339+
v = maxBy( 3, toAccessorArray( x ), 2, 1, accessor );
340+
t.strictEqual( v, 8.0, 'returns expected value' );
341+
342+
t.end();
343+
});
344+
326345
tape( 'the function supports providing a callback execution context', function test( t ) {
327346
var ctx;
328347
var x;
@@ -341,3 +360,22 @@ tape( 'the function supports providing a callback execution context', function t
341360
return v * 2.0;
342361
}
343362
});
363+
364+
tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
365+
var ctx;
366+
var x;
367+
368+
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
369+
ctx = {
370+
'count': 0
371+
};
372+
maxBy( x.length, toAccessorArray( x ), 1, 0, accessor, ctx );
373+
374+
t.strictEqual( ctx.count, x.length, 'returns expected value' );
375+
t.end();
376+
377+
function accessor( v ) {
378+
this.count += 1; // eslint-disable-line no-invalid-this
379+
return v * 2.0;
380+
}
381+
});

0 commit comments

Comments
 (0)