forked from milomg/js-reactivity-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframeworks.test.ts
More file actions
64 lines (55 loc) · 1.83 KB
/
frameworks.test.ts
File metadata and controls
64 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { makeGraph, runGraph } from "./benches/reactively/dependencyGraph";
import { expect, test } from "vitest";
import { FrameworkInfo, TestConfig } from "./util/frameworkTypes";
import { frameworkInfo } from "./frameworksList";
frameworkInfo.forEach((frameworkInfo) => frameworkTests(frameworkInfo));
function makeConfig(): TestConfig {
return {
width: 3,
totalLayers: 3,
staticFraction: 1,
nSources: 2,
readFraction: 1,
expected: {},
iterations: 1,
};
}
/** some basic tests to validate the reactive framework
* wrapper works and can run performance tests.
*/
function frameworkTests({ framework, testPullCounts }: FrameworkInfo) {
const name = framework.name;
test(`${name} | simple dependency executes`, () => {
const s = framework.signal(2);
const c = framework.computed(() => s.read() * 2);
expect(c.read()).toEqual(4);
});
test(`${name} | static graph`, () => {
const config = makeConfig();
const { graph, counter } = makeGraph(framework, 1, config);
const sum = runGraph(graph, 2, framework);
expect(sum).toEqual(16);
expect(counter.count).toEqual(11);
});
test(`${name} | static graph, read 2/3 of leaves`, () => {
const config = makeConfig();
config.readFraction = 2 / 3;
config.iterations = 10;
const { counter, graph } = makeGraph(framework, 2 / 3, config);
const sum = runGraph(graph, 10, framework);
expect(sum).toEqual(72);
if (testPullCounts) {
expect(counter.count).toEqual(41);
}
});
test(`${name} | dynamic graph`, () => {
const config = makeConfig();
config.staticFraction = 0.5;
config.width = 4;
config.totalLayers = 2;
const { graph, counter } = makeGraph(framework, 1, config);
const sum = runGraph(graph, 10, framework);
expect(sum).toEqual(72);
expect(counter.count).toEqual(22);
});
}