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.
This commit is contained in:
Dandelion Mané 2019-06-14 02:44:56 +03:00
parent bcf805b9c8
commit 7277867cc8
2 changed files with 6 additions and 6 deletions

View File

@ -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;
}
/**

View File

@ -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", () => {