Skip to content

Commit

Permalink
added behaviour metric to tests and refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 1, 2021
1 parent 81dd2fb commit 8125966
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 145 deletions.
3 changes: 3 additions & 0 deletions examples/sleeping.js
Expand Up @@ -61,12 +61,15 @@ Example.sleeping = function() {

Composite.add(world, stack);

/*
// sleep events
for (var i = 0; i < stack.bodies.length; i++) {
Events.on(stack.bodies[i], 'sleepStart sleepEnd', function(event) {
var body = this;
console.log('body id', body.id, 'sleeping:', body.isSleeping);
});
}
*/

// add mouse control
var mouse = Mouse.create(render.canvas),
Expand Down
56 changes: 51 additions & 5 deletions test/Examples.spec.js
Expand Up @@ -32,21 +32,67 @@ const examples = Object.keys(Example).filter(key => {
});

const captureExamples = async useDev => {
const worker = new Worker(require.resolve('./ExampleWorker'), {
const multiThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
enableWorkerThreads: true
});

const overlapRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
name,
useDev,
updates: 1,
stableSort: true,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));

const behaviourRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
name,
useDev,
updates: 2,
stableSort: true,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));

const similarityRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
name,
useDev,
updates: 2,
stableSort: false,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));

await multiThreadWorker.end();

const singleThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
enableWorkerThreads: true,
numWorkers: 1
});

const result = await Promise.all(examples.map(name => worker.runExample({
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
name,
useDev,
totalUpdates: 120,
updates: 150,
stableSort: false,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));

await worker.end();
await singleThreadWorker.end();

const capture = {};

for (const completeRun of completeRuns) {
const behaviourRun = behaviourRuns.find(({ name }) => name === completeRun.name);
const similarityRun = similarityRuns.find(({ name }) => name === completeRun.name);
const overlapRun = overlapRuns.find(({ name }) => name === completeRun.name);

capture[overlapRun.name] = {
...completeRun,
behaviourExtrinsic: behaviourRun.extrinsic,
similarityExtrinsic: similarityRun.extrinsic,
overlap: overlapRun.overlap
};
}

return result.reduce((out, capture) => (out[capture.name] = capture, out), {});
return capture;
};

const capturesDev = captureExamples(true);
Expand Down

0 comments on commit 8125966

Please sign in to comment.