Skip to content

Commit 0bc95eb

Browse files
committed
intial tests for isLeaf
1 parent 8c372ee commit 0bc95eb

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/graph-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,37 @@ describe("Graph", function() {
514514
});
515515
});
516516

517+
describe("isLeaf", function() {
518+
it("returns false for connected node in undirected graph", function() {
519+
g = new Graph({directed: false});
520+
g.setNode("a");
521+
g.setNode("b");
522+
g.setEdge("a", "b");
523+
expect(g.isLeaf("b")).to.be.false;
524+
});
525+
it("returns true for an unconnected node in undirected graph", function() {
526+
g = new Graph({directed: false});
527+
g.setNode("a");
528+
expect(g.isLeaf("a")).to.be.true;
529+
});
530+
it("returns true for unconnected node in directed graph", function() {
531+
g.setNode("a");
532+
expect(g.isLeaf("a")).to.be.true;
533+
});
534+
it("returns false for predecessor node in directed graph", function() {
535+
g.setNode("a");
536+
g.setNode("b");
537+
g.setEdge("a", "b");
538+
expect(g.isLeaf("a")).to.be.false;
539+
});
540+
it("returns true for successor node in directed graph", function() {
541+
g.setNode("a");
542+
g.setNode("b");
543+
g.setEdge("a", "b");
544+
expect(g.isLeaf("b")).to.be.true;
545+
});
546+
});
547+
517548
describe("neighbors", function() {
518549
it("returns undefined for a node that is not in the graph", function() {
519550
expect(g.neighbors("a")).to.be.undefined;

0 commit comments

Comments
 (0)