Skip to content

Commit

Permalink
updated tests based on student feedback. Changed BFS to return an arr…
Browse files Browse the repository at this point in the history
…ay instead of a string
  • Loading branch information
JoeKarlsson committed Nov 16, 2016
1 parent eb9f50e commit 236e0af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 50,7 @@ The basic operations provided by a graph data structure include:

1. Define a `Node` class that has a `name {{string}}`, `value{{*}}`, and `neighbors{{array}}`
1. `Node.addNeighbors([x {{node}}, y {{node}}, z {{node}} ...])`: adds an array of nodes x, y, z to `node`. Return an array with all of the nodes neighbors.
1. `Node.neighbors(x {{node}})`: lists all vertices such that there is an edge from the vertices x to y.
1. `Node.toString()`: returns the name of the node as a String.
1. `Node.getNeighbors(x {{node}})`: lists all vertices such that there is an edge from the vertices x to y.
1. [Optional] `Node.removeNode(x {{node}})`: removes the vertex x, if it is there.

Using these example methods, you should be able to make the graph above like the following:
Expand All @@ -74,7 73,7 @@ The basic operations provided by a Depth-first Search usually include:


## Breadth-first Search Methods
1. `BFS(start)`: Starting at the node `start` traverse the graph breadth-first and return an array of the path that is traversed as. For example, in the graph above, `BFS(A)` should return `A,B,C,D,E,F`.
1. `BFS(start)`: Starting at the node `start` traverse the graph breadth-first and return an array of the path that is traversed as. For example, in the graph above, `BFS(A)` should return `[A,B,C,D,E,F]`.

## Getting Started
1. Fork this repository and clone it from your personal GitHub Account
Expand Down
12 changes: 6 additions & 6 deletions test/graph-traversal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 117,11 @@ describe('Breadth First Search', () => {
expect(BFS).to.be.a('function');
});
it('should return the traversal path from the starting point all the way to the end', () => {
expect(BFS(A).toString()).to.equal("A,B,C,D,E,F");
expect(BFS(B).toString()).to.equal("B,D,E");
expect(BFS(C).toString()).to.equal("C,F");
expect(BFS(D).toString()).to.equal("D");
expect(BFS(E).toString()).to.equal("E");
expect(BFS(F).toString()).to.equal("F");
expect(BFS(A)).to.equal("[A,B,C,D,E,F]");
expect(BFS(B)).to.equal("[B,D,E]");
expect(BFS(C)).to.equal("[C,F]");
expect(BFS(D)).to.equal("[D]");
expect(BFS(E)).to.equal("[E]");
expect(BFS(F)).to.equal("[F]");
});
});

0 comments on commit 236e0af

Please sign in to comment.