Skip to content

Commit 8125966

Browse files
committed
added behaviour metric to tests and refactor tests
1 parent 81dd2fb commit 8125966

3 files changed

Lines changed: 216 additions & 145 deletions

File tree

examples/sleeping.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ Example.sleeping = function() {
6161

6262
Composite.add(world, stack);
6363

64+
/*
65+
// sleep events
6466
for (var i = 0; i < stack.bodies.length; i++) {
6567
Events.on(stack.bodies[i], 'sleepStart sleepEnd', function(event) {
6668
var body = this;
6769
console.log('body id', body.id, 'sleeping:', body.isSleeping);
6870
});
6971
}
72+
*/
7073

7174
// add mouse control
7275
var mouse = Mouse.create(render.canvas),

test/Examples.spec.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,67 @@ const examples = Object.keys(Example).filter(key => {
3232
});
3333

3434
const captureExamples = async useDev => {
35-
const worker = new Worker(require.resolve('./ExampleWorker'), {
35+
const multiThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
36+
enableWorkerThreads: true
37+
});
38+
39+
const overlapRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
40+
name,
41+
useDev,
42+
updates: 1,
43+
stableSort: true,
44+
jitter: excludeJitter.includes(name) ? 0 : 1e-10
45+
})));
46+
47+
const behaviourRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
48+
name,
49+
useDev,
50+
updates: 2,
51+
stableSort: true,
52+
jitter: excludeJitter.includes(name) ? 0 : 1e-10
53+
})));
54+
55+
const similarityRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
56+
name,
57+
useDev,
58+
updates: 2,
59+
stableSort: false,
60+
jitter: excludeJitter.includes(name) ? 0 : 1e-10
61+
})));
62+
63+
await multiThreadWorker.end();
64+
65+
const singleThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
3666
enableWorkerThreads: true,
3767
numWorkers: 1
3868
});
3969

40-
const result = await Promise.all(examples.map(name => worker.runExample({
70+
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
4171
name,
4272
useDev,
43-
totalUpdates: 120,
73+
updates: 150,
74+
stableSort: false,
4475
jitter: excludeJitter.includes(name) ? 0 : 1e-10
4576
})));
4677

47-
await worker.end();
78+
await singleThreadWorker.end();
79+
80+
const capture = {};
81+
82+
for (const completeRun of completeRuns) {
83+
const behaviourRun = behaviourRuns.find(({ name }) => name === completeRun.name);
84+
const similarityRun = similarityRuns.find(({ name }) => name === completeRun.name);
85+
const overlapRun = overlapRuns.find(({ name }) => name === completeRun.name);
86+
87+
capture[overlapRun.name] = {
88+
...completeRun,
89+
behaviourExtrinsic: behaviourRun.extrinsic,
90+
similarityExtrinsic: similarityRun.extrinsic,
91+
overlap: overlapRun.overlap
92+
};
93+
}
4894

49-
return result.reduce((out, capture) => (out[capture.name] = capture, out), {});
95+
return capture;
5096
};
5197

5298
const capturesDev = captureExamples(true);

0 commit comments

Comments
 (0)