From 47a9c7d8575686ec970bb9e4810b659e66b76a90 Mon Sep 17 00:00:00 2001 From: Kabir Shah Date: Mon, 17 Jun 2019 14:49:32 -0700 Subject: [PATCH] executor fuzz tests --- packages/moon/test/executor/executor.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/moon/test/executor/executor.test.js b/packages/moon/test/executor/executor.test.js index 71633a5c..2037cb80 100644 --- a/packages/moon/test/executor/executor.test.js +++ b/packages/moon/test/executor/executor.test.js @@ -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 }; } @@ -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); + }); +}