abovefoldAlgorithm: add basic tests
This commit is contained in:
parent
0bf6dad97f
commit
4ff9918fe0
2 changed files with 19 additions and 1 deletions
|
@ -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);
|
||||||
|
});
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
type PickAlgorithm = <D = any>(
|
type PickAlgorithm = <D = any>(
|
||||||
/** Elligible candidates to pick. */
|
/** Elligible candidates to pick. */
|
||||||
items: D[],
|
items: readonly D[],
|
||||||
/** Current iteration by which an item may be chosen. */
|
/** Current iteration by which an item may be chosen. */
|
||||||
iteration: number,
|
iteration: number,
|
||||||
/** Implementation-specific opts. */
|
/** Implementation-specific opts. */
|
||||||
|
|
Loading…
Reference in a new issue