Skip to content

Commit 7a0df50

Browse files
authored
test: add test
Signed-off-by: Athan <[email protected]>
1 parent 69df539 commit 7a0df50

File tree

1 file changed

+19
-0
lines changed
  • lib/node_modules/@stdlib/stats/array/max-by/test

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ tape( 'the function supports providing a callback execution context', function t
220220
}
221221
});
222222

223+
tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
224+
var ctx;
225+
var x;
226+
227+
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
228+
ctx = {
229+
'count': 0
230+
};
231+
maxBy( toAccessorArray( x ), accessor, ctx );
232+
233+
t.strictEqual( ctx.count, x.length, 'returns expected value' );
234+
t.end();
235+
236+
function accessor( v ) {
237+
this.count += 1; // eslint-disable-line no-invalid-this
238+
return v * 2.0;
239+
}
240+
});
241+
223242
tape( 'if provided an empty array, the function returns `NaN`', function test( t ) {
224243
var v = maxBy( [], accessor );
225244
t.strictEqual( isnan( v ), true, 'returns expected value' );

0 commit comments

Comments
 (0)