Skip to content

Empty, one, many

collectionsAll subjects

Two helpers that every codebase grows eventually. Between them, the empty collection and the single-element collection catch a startling share of real defects — which is a claim your suite is about to be measured against.

The module under test

1
export function chunk(items, size) {
2
if (size < 1) {
3
return [];
4
}
5
const out = [];
6
for (let i = 0; i < items.length; i += size) {
7
out.push(items.slice(i, i + size));
8
}
9
return out;
10
}
11
12
export function uniqueBy(items, key) {
13
const seen = new Set();
14
const out = [];
15
for (const item of items) {
16
const id = key(item);
17
if (seen.has(id)) {
18
continue;
19
}
20
seen.add(id);
21
out.push(item);
22
}
23
return out;
24
}
25

Your tests

Mutants

Mutation score
Survived
0
Killed
0 / 0
Line coverage
Tests
0
Assertion width
Cycle
    survivedkilledtimed outequivalentnot run