Skip to content

Commit

Permalink
✨ feat: Check that the data is invariant.
Browse files Browse the repository at this point in the history
Fixes #15.
  • Loading branch information
make-github-pseudonymous-again committed Sep 20, 2020
1 parent d3c25b6 commit 45cd142
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/mock.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {copy} from '@aureooms/js-array';

export function mock(compare, a, i, j) {
const x = Array.prototype.slice.call(a, i, j);

x.sort(compare);

while (j-- > i) {
a[j] = x[j - i];
}
copy(x, 0, j - i, a, i);
}
24 changes: 18 additions & 6 deletions src/test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import {issorted} from '@aureooms/js-sort';
import {iota} from '@aureooms/js-array';
import {shuffle} from '@aureooms/js-random';
import {increasing, decreasing} from '@aureooms/js-compare';
import {exhaust, list, map, product, chain} from '@aureooms/js-itertools';
import {
sorted,
range,
exhaust,
list,
map,
product,
chain
} from '@aureooms/js-itertools';
import functools from '@aureooms/js-functools';

const set = (A) => sorted(increasing, A);

const macro = (t, sortname, method, Ctor, n, compare) => {
// SETUP ARRAY
const a = new Ctor(n);
iota(a, 0, n, 0);
const data = set(range(n));
const a = Ctor.from(data);

// SORT ARRAY
shuffle(a, 0, n);
method(compare, a, 0, n);

// TEST PREDICATE
t.is(issorted(compare, a, 0, n), n, 'check sorted');
t.is(a.length, n, 'check length a');
t.is(n, a.length, 'check length');
t.is(undefined, a[-1], 'check left boundary');
t.is(undefined, a[n], 'check right boundary');
t.is(n, issorted(compare, a, 0, n), 'check sorted');
t.deepEqual(data, set(a), 'check data');
};

macro.title = (title, sortname, _, Ctor, n, compare) =>
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2002,9 +2002,9 @@ camelcase@^5.0.0, camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001131:
version "1.0.30001131"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001131.tgz#afad8a28fc2b7a0d3ae9407e71085a0ead905d54"
integrity sha512-4QYi6Mal4MMfQMSqGIRPGbKIbZygeN83QsWq1ixpUwvtfgAZot5BrCKzGygvZaV+CnELdTwD0S4cqUNozq7/Cw==
version "1.0.30001133"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001133.tgz#ec564c5495311299eb05245e252d589a84acd95e"
integrity sha512-s3XAUFaC/ntDb1O3lcw9K8MPeOW7KO3z9+GzAoBxfz1B0VdacXPMKgFUtG4KIsgmnbexmi013s9miVu4h+qMHw==

caseless@~0.12.0:
version "0.12.0"
Expand Down Expand Up @@ -2585,11 +2585,11 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
ms "2.0.0"

debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
version "4.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==
dependencies:
ms "^2.1.1"
ms "2.1.2"

decamelize-keys@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -5709,7 +5709,7 @@ ms@2.0.0:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

ms@^2.1.1, ms@^2.1.2:
ms@2.1.2, ms@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
Expand Down

0 comments on commit 45cd142

Please sign in to comment.