From 7277867cc8d55e45eb7104a4f172eb94a27cd754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 14 Jun 2019 02:44:56 +0300 Subject: [PATCH] cleanup: PagerankGraph getters return undefined PagerankGraph's `node` and `edge` getters returned null for unavailable entries, rather than undefined. This is inconsistent with general JS behavior, and with the base Graph. I've now cleaned it up. Test plan: unit tests updated; `yarn test` passes. --- src/core/pagerankGraph.js | 4 ++-- src/core/pagerankGraph.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/pagerankGraph.js b/src/core/pagerankGraph.js index 1b6b1cb..5835dfa 100644 --- a/src/core/pagerankGraph.js +++ b/src/core/pagerankGraph.js @@ -296,7 +296,7 @@ export class PagerankGraph { this._verifyGraphNotModified(); const score = this._scores.get(x); if (score == null) { - return null; + return undefined; } else { return {address: x, score}; } @@ -334,7 +334,7 @@ export class PagerankGraph { const weight = NullUtil.get(this._edgeWeights.get(edge.address)); return {edge, weight}; } - return null; + return undefined; } /** diff --git a/src/core/pagerankGraph.test.js b/src/core/pagerankGraph.test.js index ee53b89..b840a6c 100644 --- a/src/core/pagerankGraph.test.js +++ b/src/core/pagerankGraph.test.js @@ -80,10 +80,10 @@ describe("core/pagerankGraph", () => { }); describe("node / nodes", () => { - it("node returns null for node not in the graph", () => { + it("node returns undefined for node not in the graph", () => { const g = nonEmptyGraph(); const pg = new PagerankGraph(g, defaultEvaluator); - expect(pg.node(NodeAddress.empty)).toEqual(null); + expect(pg.node(NodeAddress.empty)).toBe(undefined); }); it("nodes yields the same nodes as are in the graph", () => { const g = advancedGraph().graph1(); @@ -189,9 +189,9 @@ describe("core/pagerankGraph", () => { } }); - it("edge returns null for address not in the graph", () => { + it("edge returns undefined for address not in the graph", () => { const pg = new PagerankGraph(nonEmptyGraph(), defaultEvaluator); - expect(pg.edge(EdgeAddress.empty)).toEqual(null); + expect(pg.edge(EdgeAddress.empty)).toBe(undefined); }); it("edge and edges both throw an error if underlying graph is modified", () => {