Add a test helper function for converged graphs (#1093)
Really minor refactor, adds a `convergedPagerankGraph` helper method which provides a converged pagerank graph. :) Test plan: `yarn test` suffices.
This commit is contained in:
parent
4adbec03c2
commit
c353efff36
|
@ -17,10 +17,15 @@ describe("core/pagerankGraph", () => {
|
|||
const nonEmptyGraph = () =>
|
||||
new Graph().addNode(NodeAddress.fromParts(["hi"]));
|
||||
|
||||
function examplePagerankGraph() {
|
||||
function examplePagerankGraph(): PagerankGraph {
|
||||
const g = advancedGraph().graph1();
|
||||
return new PagerankGraph(g, defaultEvaluator);
|
||||
}
|
||||
async function convergedPagerankGraph(): Promise<PagerankGraph> {
|
||||
const pg = examplePagerankGraph();
|
||||
await pg.runPagerank({maxIterations: 100, convergenceThreshold: 1e-4});
|
||||
return pg;
|
||||
}
|
||||
|
||||
it("cannot construct PagerankGraph with empty Graph", () => {
|
||||
const eg1 = new Graph();
|
||||
|
@ -50,9 +55,7 @@ describe("core/pagerankGraph", () => {
|
|||
expect(new Set(graphNodes)).toEqual(new Set(pgNodes));
|
||||
});
|
||||
it("node and nodes both return consistent scores", async () => {
|
||||
const g = advancedGraph().graph1();
|
||||
const pg = new PagerankGraph(g, defaultEvaluator);
|
||||
await pg.runPagerank({maxIterations: 1, convergenceThreshold: 0.001});
|
||||
const pg = await convergedPagerankGraph();
|
||||
for (const {node, score} of pg.nodes()) {
|
||||
expect(score).toEqual(NullUtil.get(pg.node(node)).score);
|
||||
}
|
||||
|
@ -289,15 +292,13 @@ describe("core/pagerankGraph", () => {
|
|||
|
||||
describe("to/from JSON", () => {
|
||||
it("to->fro is identity", async () => {
|
||||
const pg = examplePagerankGraph();
|
||||
await pg.runPagerank({maxIterations: 1, convergenceThreshold: 0.01});
|
||||
const pg = await convergedPagerankGraph();
|
||||
const pgJSON = pg.toJSON();
|
||||
const pg_ = PagerankGraph.fromJSON(pgJSON);
|
||||
expect(pg.equals(pg_)).toBe(true);
|
||||
});
|
||||
it("fro->to is identity", async () => {
|
||||
const pg = examplePagerankGraph();
|
||||
await pg.runPagerank({maxIterations: 1, convergenceThreshold: 0.01});
|
||||
const pg = await convergedPagerankGraph();
|
||||
const pgJSON = pg.toJSON();
|
||||
const pg_ = PagerankGraph.fromJSON(pgJSON);
|
||||
const pgJSON_ = pg_.toJSON();
|
||||
|
|
Loading…
Reference in New Issue