From 354cd5ce07834d8e57c409ca8fd8ffccf134223c Mon Sep 17 00:00:00 2001 From: j50n Date: Mon, 27 Dec 2021 13:35:38 -0700 Subject: [PATCH] rename api --- README.md | 6 +++--- dijkstra.example.test.ts | 2 +- dijkstra.test.ts | 4 ++-- dijkstra.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6cce709..c782459 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ A pretty good implementation of Dijkstra's shortest-path algorithm for Deno. -This implementation is able to process large in-memory graphs. It will -perform reasonably well even when the number of edges is in the millions. +This implementation is able to process large in-memory graphs. It will perform +reasonably well even when the number of edges is in the millions. This code was adapted from Typescript/Deno from [A Walkthrough of Dijkstra's Algorithm (In JavaScript!)](https://medium.com/@adriennetjohnson/a-walkthrough-of-dijkstras-algorithm-in-javascript-e94b74192026) @@ -46,7 +46,7 @@ assertEquals( ); assertEquals( - cafes.calculateFor(FULLSTACK).weights[CAFEGRUMPY], + cafes.calculateFor(FULLSTACK).weightOfPathTo(CAFEGRUMPY), 14, ); ``` diff --git a/dijkstra.example.test.ts b/dijkstra.example.test.ts index fc2befc..7437ca6 100644 --- a/dijkstra.example.test.ts +++ b/dijkstra.example.test.ts @@ -31,7 +31,7 @@ Deno.test("demonstrate finding shortest path", () => { Deno.test("demonstrate finding the weight of the shortest path", () => { assertEquals( - cafes.calculateFor(FULLSTACK).totalWeight(CAFEGRUMPY), + cafes.calculateFor(FULLSTACK).weightOfPathTo(CAFEGRUMPY), 14, "weight of the shortest path", ); diff --git a/dijkstra.test.ts b/dijkstra.test.ts index 0db2647..a8c3cd3 100644 --- a/dijkstra.test.ts +++ b/dijkstra.test.ts @@ -18,7 +18,7 @@ Deno.test("some paths are valid, others are not", () => { const shortestPath = solver.calculateFor(0); assertThrows(() => shortestPath.shortestPathTo(1), Error); assertEquals(shortestPath.shortestPathTo(2), [0, 2]); - assertEquals(shortestPath.totalWeight(2), 42); + assertEquals(shortestPath.weightOfPathTo(2), 42); }); Deno.test("finds shortest path between two nodes", () => { @@ -27,5 +27,5 @@ Deno.test("finds shortest path between two nodes", () => { const shortestPath = solver.calculateFor(0); assertEquals(shortestPath.shortestPathTo(1), [0, 1]); - assertEquals(shortestPath.totalWeight(1), 1); + assertEquals(shortestPath.weightOfPathTo(1), 1); }); diff --git a/dijkstra.ts b/dijkstra.ts index c7cd107..cef90bd 100644 --- a/dijkstra.ts +++ b/dijkstra.ts @@ -224,7 +224,7 @@ export class ShortestPaths { * Total weight of the path from the start node to the given end node. * @param endNode The end node. */ - totalWeight(endNode: number): number { + weightOfPathTo(endNode: number): number { if (endNode < 0 || endNode >= this.nodes) { throw new RangeError( `end-node must be in range 0 to ${this.nodes - 1}: ${endNode}`,