abovefoldAlgorithm: add basic tests

This commit is contained in:
Alex Gleason 2022-09-13 11:44:21 -05:00
parent 0bf6dad97f
commit 4ff9918fe0
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,18 @@
import { abovefoldAlgorithm } from '../abovefold';
const DATA = Object.freeze(['a', 'b', 'c', 'd']);
test('abovefoldAlgorithm', () => {
const result = Array(50).fill('').map((_, i) => {
return abovefoldAlgorithm(DATA, i, { seed: '!', range: [2, 6], pageSize: 20 });
});
// console.log(result);
expect(result[0]).toBe(undefined);
expect(result[4]).toBe('a');
expect(result[5]).toBe(undefined);
expect(result[24]).toBe('b');
expect(result[30]).toBe(undefined);
expect(result[42]).toBe('c');
expect(result[43]).toBe(undefined);
});

View file

@ -3,7 +3,7 @@
*/
type PickAlgorithm = <D = any>(
/** Elligible candidates to pick. */
items: D[],
items: readonly D[],
/** Current iteration by which an item may be chosen. */
iteration: number,
/** Implementation-specific opts. */