Skip to content

Commit

Permalink
executor fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jun 17, 2019
1 parent 124671c commit 47a9c7d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/moon/test/executor/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ let eventResult;
window.requestAnimationFrame = (fn) => fn();
document.body.appendChild(root);

function shuffle(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}

return arr;
}

function handler(event, data, children) {
eventResult = { event, data, children };
}
Expand Down Expand Up @@ -168,3 +177,13 @@ for (let i of [2, 3, 5]) {
});
}
}

// Fuzz
for (let i of Array.from({ length: 100 })) {
const before = shuffle(Array.from({ length: Math.floor(Math.random() * 100) }).map(x => Math.floor(Math.random() * 25)));
const after = shuffle(Array.from({ length: Math.floor(Math.random() * 100) }).map(x => Math.floor(Math.random() * 25)));

test(`fuzz [${before.toString()}] -> [${after.toString()}]`, () => {
assertExecute(before, after);
});
}

0 comments on commit 47a9c7d

Please sign in to comment.