Skip to content

Sorting, without examples

All labs

Write invariants instead of cases. `property(name, generator, fn)` runs your rule over a hundred generated inputs and, when one fails, shrinks it to the smallest input that still fails. Generators available: gen.int(min, max), gen.nat(max), gen.string(maxLength), gen.boolean(), gen.array(of, maxLength), gen.oneOf(...values) and gen.record({ … }).

goalKill every mutant using `property` rather than hand-written examples.

The module

export function sortNumbers(values) {
  const out = values.slice();
  for (let i = 1; i < out.length; i++) {
    const current = out[i];
    let j = i - 1;
    while (j >= 0 && out[j] > current) {
      out[j + 1] = out[j];
      j = j - 1;
    }
    out[j + 1] = current;
  }
  return out;
}

Your tests

Mutants

Run the suite to see the board.