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:
parent
bcf805b9c8
commit
7277867cc8
|
@ -296,7 +296,7 @@ export class PagerankGraph {
|
||||||
this._verifyGraphNotModified();
|
this._verifyGraphNotModified();
|
||||||
const score = this._scores.get(x);
|
const score = this._scores.get(x);
|
||||||
if (score == null) {
|
if (score == null) {
|
||||||
return null;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
return {address: x, score};
|
return {address: x, score};
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ export class PagerankGraph {
|
||||||
const weight = NullUtil.get(this._edgeWeights.get(edge.address));
|
const weight = NullUtil.get(this._edgeWeights.get(edge.address));
|
||||||
return {edge, weight};
|
return {edge, weight};
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,10 +80,10 @@ describe("core/pagerankGraph", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("node / nodes", () => {
|
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 g = nonEmptyGraph();
|
||||||
const pg = new PagerankGraph(g, defaultEvaluator);
|
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", () => {
|
it("nodes yields the same nodes as are in the graph", () => {
|
||||||
const g = advancedGraph().graph1();
|
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);
|
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", () => {
|
it("edge and edges both throw an error if underlying graph is modified", () => {
|
||||||
|
|
Loading…
Reference in New Issue