Skip to content

Commit 6fda0bd

Browse files
authored
test: update callback tests
Signed-off-by: Athan <[email protected]>
1 parent 7a0df50 commit 6fda0bd

File tree

1 file changed

+45
-3
lines changed
  • lib/node_modules/@stdlib/stats/array/max-by/test

1 file changed

+45
-3
lines changed

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,39 +202,81 @@ tape( 'the function calculates the maximum value of an array (array-like object)
202202
});
203203

204204
tape( 'the function supports providing a callback execution context', function test( t ) {
205+
var expected;
206+
var indices;
207+
var values;
208+
var arrays;
205209
var ctx;
206210
var x;
207211

208212
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
209213
ctx = {
210214
'count': 0
211215
};
216+
indices = [];
217+
values = [];
218+
arrays = [];
212219
maxBy( x, accessor, ctx );
213220

214221
t.strictEqual( ctx.count, x.length, 'returns expected value' );
222+
223+
expected = [ 0, 1, 2, 3, 4 ];
224+
t.deepEqual( indices, expected, 'returns expected value' );
225+
226+
expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
227+
t.deepEqual( values, expected, 'returns expected value' );
228+
229+
expected = [ x, x, x, x, x ];
230+
t.deepEqual( arrays, expected, 'returns expected value' );
231+
215232
t.end();
216233

217-
function accessor( v ) {
234+
function accessor( v, idx, arr ) {
218235
this.count += 1; // eslint-disable-line no-invalid-this
236+
indices.push( idx );
237+
values.push( v );
238+
arrays.push( arr );
219239
return v * 2.0;
220240
}
221241
});
222242

223243
tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
244+
var expected;
245+
var indices;
246+
var values;
247+
var arrays;
224248
var ctx;
249+
var ax;
225250
var x;
226251

227252
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
253+
ax = toAccessorArray( x );
228254
ctx = {
229255
'count': 0
230256
};
231-
maxBy( toAccessorArray( x ), accessor, ctx );
257+
indices = [];
258+
values = [];
259+
arrays = [];
260+
maxBy( ax, accessor, ctx );
232261

233262
t.strictEqual( ctx.count, x.length, 'returns expected value' );
263+
264+
expected = [ 0, 1, 2, 3, 4 ];
265+
t.deepEqual( indices, expected, 'returns expected value' );
266+
267+
expected = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
268+
t.deepEqual( values, expected, 'returns expected value' );
269+
270+
expected = [ ax, ax, ax, ax, ax ];
271+
t.deepEqual( arrays, expected, 'returns expected value' );
272+
234273
t.end();
235274

236-
function accessor( v ) {
275+
function accessor( v, idx, arr ) {
237276
this.count += 1; // eslint-disable-line no-invalid-this
277+
indices.push( idx );
278+
values.push( v );
279+
arrays.push( arr );
238280
return v * 2.0;
239281
}
240282
});

0 commit comments

Comments
 (0)