diff --git a/lib/node/index.d.ts b/lib/node/index.d.ts index be64d0e..601efff 100644 --- a/lib/node/index.d.ts +++ b/lib/node/index.d.ts @@ -1 +1,10 @@ +/** + * @module graph + * + * A small library of graph algorithms. + * + * @copyright (c) 2017 David Mesquita-Morris + * + * Licensed under the MIT and GPL v3 licences + */ export { Tree } from "./tree"; diff --git a/lib/node/index.js b/lib/node/index.js index fb1d705..366bbfd 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -1,4 +1,14 @@ "use strict"; +/** + * @module graph + * + * A small library of graph algorithms. + * + * @copyright (c) 2017 David Mesquita-Morris + * + * Licensed under the MIT and GPL v3 licences + */ Object.defineProperty(exports, "__esModule", { value: true }); +// pull in the tree algorithms var tree_1 = require("./tree"); exports.Tree = tree_1.Tree; diff --git a/package.json b/package.json index bd035e4..4c2eb4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@steelbreeze/graph", - "version": "1.0.1", + "version": "1.0.2", "description": "Graph libraries for TypeScript and JavaScript", "main": "./lib/node/index.js", "typings": "./lib/node/index.d.ts", diff --git a/src/index.ts b/src/index.ts index cb2dd31..134bbf0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,12 @@ +/** + * @module graph + * + * A small library of graph algorithms. + * + * @copyright (c) 2017 David Mesquita-Morris + * + * Licensed under the MIT and GPL v3 licences + */ + +// pull in the tree algorithms export { Tree } from "./tree"; \ No newline at end of file diff --git a/test/tree.js b/test/tree.js index 60da496..a7cf174 100644 --- a/test/tree.js +++ b/test/tree.js @@ -29,12 +29,12 @@ describe("test/tree.js", function () { }); it("Common ancestor", function () { -// assert.equal(root, tree.lowestCommonAncestor(root, root)); -// assert.equal(root, tree.lowestCommonAncestor(root, left)); -// assert.equal(root, tree.lowestCommonAncestor(root, right)); -// assert.equal(root, tree.lowestCommonAncestor(root, rightLeft)); -// assert.equal(root, tree.lowestCommonAncestor(root, rightRight)); -// assert.equal(undefined, tree.lowestCommonAncestor(root, other)); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(root))); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(left))); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(right))); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(rightLeft))); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(rightRight))); + assert.equal(-1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(root), graph.Tree.ancestors(other))); assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(left), graph.Tree.ancestors(root))); assert.equal(1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(left), graph.Tree.ancestors(left))); @@ -57,12 +57,12 @@ describe("test/tree.js", function () { assert.equal(1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightLeft), graph.Tree.ancestors(rightRight))); assert.equal(-1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightLeft), graph.Tree.ancestors(other))); -// assert.equal(root, tree.lowestCommonAncestor(rightRight, root)); -// assert.equal(root, tree.lowestCommonAncestor(rightRight, left)); -// assert.equal(right, tree.lowestCommonAncestor(rightRight, right)); -// assert.equal(right, tree.lowestCommonAncestor(rightRight, rightLeft)); -// assert.equal(rightRight, tree.lowestCommonAncestor(rightRight, rightRight)); -// assert.equal(undefined, tree.lowestCommonAncestor(rightRight, other)); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(root))); + assert.equal(0, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(left))); + assert.equal(1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(right))); + assert.equal(1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(rightLeft))); + assert.equal(2, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(rightRight))); + assert.equal(-1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(rightRight), graph.Tree.ancestors(other))); assert.equal(-1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(other), graph.Tree.ancestors(root))); assert.equal(-1, graph.Tree.lowestCommonAncestorIndex(graph.Tree.ancestors(other), graph.Tree.ancestors(left)));