From 3430b4adbe75b26f1481628d7bbcec191a2434b2 Mon Sep 17 00:00:00 2001 From: Chris Russell Date: Wed, 21 Sep 2016 13:04:54 -0700 Subject: [PATCH 1/4] Rename source files per ARC project conventions. --- src/{digraph.js => arc_core_digraph.js} | 0 ...gorithm-common-visit.js => arc_core_digraph_algoithm_visit.js} | 0 ...digraph-algorithm-bft.js => arc_core_digraph_algorithm_bft.js} | 0 ...ithm-common-colors.js => arc_core_digraph_algorithm_colors.js} | 0 ...hm-common-context.js => arc_core_digraph_algorithm_context.js} | 0 ...digraph-algorithm-dft.js => arc_core_digraph_algorithm_dft.js} | 0 ...hm-common-request.js => arc_core_digraph_algorithm_request.js} | 0 ...rithm-transpose.js => arc_core_digraph_algorithm_transpose.js} | 0 src/{digraph-json-export.js => arc_core_digraph_export.js} | 0 src/{digraph-json-import.js => arc_core_digraph_import.js} | 0 src/{digraph-in-parameters.js => arc_core_digraph_in_params.js} | 0 index.js => src/arc_core_graph.js | 0 src/{helper-functions.js => arc_core_graph_util.js} | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename src/{digraph.js => arc_core_digraph.js} (100%) rename src/{digraph-algorithm-common-visit.js => arc_core_digraph_algoithm_visit.js} (100%) rename src/{digraph-algorithm-bft.js => arc_core_digraph_algorithm_bft.js} (100%) rename src/{digraph-algorithm-common-colors.js => arc_core_digraph_algorithm_colors.js} (100%) rename src/{digraph-algorithm-common-context.js => arc_core_digraph_algorithm_context.js} (100%) rename src/{digraph-algorithm-dft.js => arc_core_digraph_algorithm_dft.js} (100%) rename src/{digraph-algorithm-common-request.js => arc_core_digraph_algorithm_request.js} (100%) rename src/{digraph-algorithm-transpose.js => arc_core_digraph_algorithm_transpose.js} (100%) rename src/{digraph-json-export.js => arc_core_digraph_export.js} (100%) rename src/{digraph-json-import.js => arc_core_digraph_import.js} (100%) rename src/{digraph-in-parameters.js => arc_core_digraph_in_params.js} (100%) rename index.js => src/arc_core_graph.js (100%) rename src/{helper-functions.js => arc_core_graph_util.js} (100%) diff --git a/src/digraph.js b/src/arc_core_digraph.js similarity index 100% rename from src/digraph.js rename to src/arc_core_digraph.js diff --git a/src/digraph-algorithm-common-visit.js b/src/arc_core_digraph_algoithm_visit.js similarity index 100% rename from src/digraph-algorithm-common-visit.js rename to src/arc_core_digraph_algoithm_visit.js diff --git a/src/digraph-algorithm-bft.js b/src/arc_core_digraph_algorithm_bft.js similarity index 100% rename from src/digraph-algorithm-bft.js rename to src/arc_core_digraph_algorithm_bft.js diff --git a/src/digraph-algorithm-common-colors.js b/src/arc_core_digraph_algorithm_colors.js similarity index 100% rename from src/digraph-algorithm-common-colors.js rename to src/arc_core_digraph_algorithm_colors.js diff --git a/src/digraph-algorithm-common-context.js b/src/arc_core_digraph_algorithm_context.js similarity index 100% rename from src/digraph-algorithm-common-context.js rename to src/arc_core_digraph_algorithm_context.js diff --git a/src/digraph-algorithm-dft.js b/src/arc_core_digraph_algorithm_dft.js similarity index 100% rename from src/digraph-algorithm-dft.js rename to src/arc_core_digraph_algorithm_dft.js diff --git a/src/digraph-algorithm-common-request.js b/src/arc_core_digraph_algorithm_request.js similarity index 100% rename from src/digraph-algorithm-common-request.js rename to src/arc_core_digraph_algorithm_request.js diff --git a/src/digraph-algorithm-transpose.js b/src/arc_core_digraph_algorithm_transpose.js similarity index 100% rename from src/digraph-algorithm-transpose.js rename to src/arc_core_digraph_algorithm_transpose.js diff --git a/src/digraph-json-export.js b/src/arc_core_digraph_export.js similarity index 100% rename from src/digraph-json-export.js rename to src/arc_core_digraph_export.js diff --git a/src/digraph-json-import.js b/src/arc_core_digraph_import.js similarity index 100% rename from src/digraph-json-import.js rename to src/arc_core_digraph_import.js diff --git a/src/digraph-in-parameters.js b/src/arc_core_digraph_in_params.js similarity index 100% rename from src/digraph-in-parameters.js rename to src/arc_core_digraph_in_params.js diff --git a/index.js b/src/arc_core_graph.js similarity index 100% rename from index.js rename to src/arc_core_graph.js diff --git a/src/helper-functions.js b/src/arc_core_graph_util.js similarity index 100% rename from src/helper-functions.js rename to src/arc_core_graph_util.js From 13401a0c4d5c5b79779718d34c8beefeaf161d14 Mon Sep 17 00:00:00 2001 From: Chris Russell Date: Wed, 21 Sep 2016 13:17:50 -0700 Subject: [PATCH 2/4] Breaking fix for bug #51 DirectedGraph serialization API. --- package.json | 6 ++-- src/arc_core_digraph.js | 35 ++++++++++--------- src/arc_core_digraph_algorithm_bft.js | 10 +++--- src/arc_core_digraph_algorithm_colors.js | 4 +-- src/arc_core_digraph_algorithm_context.js | 8 ++--- src/arc_core_digraph_algorithm_dft.js | 10 +++--- src/arc_core_digraph_algorithm_request.js | 8 ++--- src/arc_core_digraph_algorithm_transpose.js | 8 ++--- ...js => arc_core_digraph_algorithm_visit.js} | 6 ++-- src/arc_core_digraph_export.js | 6 ++-- src/arc_core_digraph_import.js | 4 +-- src/arc_core_digraph_in_params.js | 6 ++-- src/arc_core_graph.js | 14 ++++---- src/arc_core_graph_util.js | 6 ++-- .../test-runner-algorithm-common-request.js | 4 ++- .../test-runner-algorithm-common-visitor.js | 4 ++- test/fixture/test-runner-create-digraph.js | 5 +-- .../test-runner-digraph-algorithm-bft.js | 5 ++- .../test-runner-digraph-algorithm-dft.js | 4 ++- test/fixture/test-runner-digraph-in-params.js | 4 ++- test/module-under-test.js | 1 + test/test-digraph-algorithm-bft.js | 4 ++- test/test-digraph-algorithm-common-context.js | 5 +-- test/test-digraph-algorithm-common-request.js | 26 +++++++------- test/test-digraph-algorithm-common-visitor.js | 5 +-- test/test-digraph-algorithm-dft.js | 3 +- test/test-digraph-algorithm-transpose.js | 6 ++-- test/test-digraph-container.js | 29 ++++++++------- test/test-module-exports.js | 6 ++-- test/test-module-resolver.js | 23 ++++++++++++ 30 files changed, 145 insertions(+), 120 deletions(-) rename src/{arc_core_digraph_algoithm_visit.js => arc_core_digraph_algorithm_visit.js} (93%) create mode 100644 test/module-under-test.js create mode 100644 test/test-module-resolver.js diff --git a/package.json b/package.json index 6aaf521..252e83a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "jsgraph", - "version": "0.6.1", + "version": "0.7.0", "description": "Generic directed graph container, and visitor algorithms based on a port of the Boost C++ Graph Library API.", - "main": "index.js", + "main": "src/arc_core_graph.js", "scripts": { "test": "mocha -R spec ./test/test-jsgraph.js" }, @@ -25,8 +25,6 @@ "BFS", "DFS", "data modeling", - "semantics", - "semantic modeling", "data", "JSON", "data semantics", diff --git a/src/arc_core_digraph.js b/src/arc_core_digraph.js index a0bbcf1..e988970 100644 --- a/src/arc_core_digraph.js +++ b/src/arc_core_digraph.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -14,10 +12,10 @@ // http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/index.html // http://en.wikipedia.org/wiki/Directed_graph -var helperFunctions = require('./helper-functions'); -var digraphParams = require('./digraph-in-parameters'); -var digraphImport = require('./digraph-json-import'); -var digraphExport = require('./digraph-json-export'); +var helperFunctions = require('./arc_core_graph_util'); +var digraphParams = require('./arc_core_digraph_in_params'); +var digraphImport = require('./arc_core_digraph_import'); +var digraphExport = require('./arc_core_digraph_export'); (function() { var __bind = function(method, scope){ return function(){ return method.apply(scope, arguments); }; }; @@ -43,7 +41,7 @@ var digraphExport = require('./digraph-json-export'); this.inEdges = __bind(this.inEdges, this); this.outDegree = __bind(this.outDegree, this); this.outEdges = __bind(this.outEdges, this); - + // Edge-scope methods this.isEdge = __bind(this.isEdge, this); this.addEdge = __bind(this.addEdge, this); @@ -52,7 +50,7 @@ var digraphExport = require('./digraph-json-export'); this.setEdgeProperty = __bind(this.setEdgeProperty, this); this.hasEdgeProperty = __bind(this.hasEdgeProperty, this); this.clearEdgeProperty = __bind(this.clearEdgeProperty, this); - + // Digraph-scope methods this.verticesCount = __bind(this.verticesCount, this); this.getVertices = __bind(this.getVertices, this); @@ -62,8 +60,9 @@ var digraphExport = require('./digraph-json-export'); this.getRootVertices = __bind(this.getRootVertices, this); this.leafVerticesCount = __bind(this.leafVerticesCount, this); this.getLeafVertices = __bind(this.getLeafVertices, this); - this.toObject = __bind(this.toObject, this); this.toJSON = __bind(this.toJSON, this); + this.toObject = __bind(this.toObject, this); + this.stringify = __bind(this.stringify, this); this.fromObject = __bind(this.fromObject, this); this.fromJSON = __bind(this.fromJSON, this); @@ -96,7 +95,7 @@ var digraphExport = require('./digraph-json-export'); if (helperFunctions.JSType(string_) === '[object String]') { this._private.name = string_; response.result = true; - } else { + } else { response.error = "Invalid graph name specified. Expected '[object String]'."; } return response; @@ -111,7 +110,7 @@ var digraphExport = require('./digraph-json-export'); if (helperFunctions.JSType(string_) === '[object String]') { this._private.description = string_; response.result = true; - } else { + } else { response.error = "Invalid graph name specified. Expected '[object String]'."; } return response; @@ -127,7 +126,7 @@ var digraphExport = require('./digraph-json-export'); var vertex = this._private.vertexMap[vertexId_]; return (vertex !== null) && vertex && true || false; }; - + /* request = { u: vertex ID string @@ -512,18 +511,22 @@ var digraphExport = require('./digraph-json-export'); return leafVertices; }; - DirectedGraph.prototype.toObject = function () { + // toJSON and toObject are identical delegations to digraphExport.exportObject. + DirectedGraph.prototype.toJSON = function () { + return digraphExport.exportObject(this); + }; + DirectedGraph.prototype.toObject = function() { return digraphExport.exportObject(this); }; - DirectedGraph.prototype.toJSON = function(replacer_, space_) { + DirectedGraph.prototype.stringify = function(replacer_, space_) { return digraphExport.exportJSON(this, replacer_, space_); }; DirectedGraph.prototype.fromObject = function (object_) { return digraphImport(this, object_); }; - + DirectedGraph.prototype.fromJSON = function(json_) { return digraphImport(this, json_); }; diff --git a/src/arc_core_digraph_algorithm_bft.js b/src/arc_core_digraph_algorithm_bft.js index 5b25ea9..86d036c 100644 --- a/src/arc_core_digraph_algorithm_bft.js +++ b/src/arc_core_digraph_algorithm_bft.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-bft.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -55,9 +53,9 @@ */ var algorithmName = "BFT"; // constant string used in error messages -var colors = require('./digraph-algorithm-common-colors'); -var visitorCallback = require('./digraph-algorithm-common-visit'); -var normalizeRequest = require('./digraph-algorithm-common-request'); +var colors = require('./arc_core_digraph_algorithm_colors'); +var visitorCallback = require('./arc_core_digraph_algorithm_visit'); +var normalizeRequest = require('./arc_core_digraph_algorithm_request'); module.exports = function (request_) { diff --git a/src/arc_core_digraph_algorithm_colors.js b/src/arc_core_digraph_algorithm_colors.js index 6fbb59c..516e13c 100644 --- a/src/arc_core_digraph_algorithm_colors.js +++ b/src/arc_core_digraph_algorithm_colors.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-common-colors.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. diff --git a/src/arc_core_digraph_algorithm_context.js b/src/arc_core_digraph_algorithm_context.js index 4799077..4fb3726 100644 --- a/src/arc_core_digraph_algorithm_context.js +++ b/src/arc_core_digraph_algorithm_context.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-common-context.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -10,8 +8,8 @@ with in-memory data on Node.js and HTML. */ -var helperFunctions = require('./helper-functions'); -var colors = require('./digraph-algorithm-common-colors'); +var helperFunctions = require('./arc_core_graph_util'); +var colors = require('./arc_core_digraph_algorithm_colors'); module.exports = function (request_) { var response = { error: null, result: null }; diff --git a/src/arc_core_digraph_algorithm_dft.js b/src/arc_core_digraph_algorithm_dft.js index 7169c52..283168b 100644 --- a/src/arc_core_digraph_algorithm_dft.js +++ b/src/arc_core_digraph_algorithm_dft.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-dft.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -11,9 +9,9 @@ */ var algorithmName = "DFT"; // used in error messages -var colors = require('./digraph-algorithm-common-colors'); -var visitorCallback = require('./digraph-algorithm-common-visit'); -var normalizeRequest = require('./digraph-algorithm-common-request'); +var colors = require('./arc_core_digraph_algorithm_colors'); +var visitorCallback = require('./arc_core_digraph_algorithm_visit'); +var normalizeRequest = require('./arc_core_digraph_algorithm_request'); module.exports = function (request_) { diff --git a/src/arc_core_digraph_algorithm_request.js b/src/arc_core_digraph_algorithm_request.js index 8fd7ca2..7bf93f1 100644 --- a/src/arc_core_digraph_algorithm_request.js +++ b/src/arc_core_digraph_algorithm_request.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/arc/digraph-algorithm-common-request.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -10,8 +8,8 @@ with in-memory data on Node.js and HTML. */ -var helperFunctions = require('./helper-functions'); -var TRAVERSE_CONTEXT = require('./digraph-algorithm-common-context'); +var helperFunctions = require('./arc_core_graph_util'); +var TRAVERSE_CONTEXT = require('./arc_core_digraph_algorithm_context'); /* request = { diff --git a/src/arc_core_digraph_algorithm_transpose.js b/src/arc_core_digraph_algorithm_transpose.js index 74ba087..c56e0ce 100644 --- a/src/arc_core_digraph_algorithm_transpose.js +++ b/src/arc_core_digraph_algorithm_transpose.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-transpose.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -15,8 +13,8 @@ // More info on directed graph transposition: // http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/transpose_graph.html -var helperFunctions = require('../src/helper-functions'); -var DirectedGraph = require('../src/digraph').DirectedGraph; +var helperFunctions = require('./arc_core_graph_util'); +var DirectedGraph = require('./arc_core_digraph').DirectedGraph; /* request = DirectedGraph reference diff --git a/src/arc_core_digraph_algoithm_visit.js b/src/arc_core_digraph_algorithm_visit.js similarity index 93% rename from src/arc_core_digraph_algoithm_visit.js rename to src/arc_core_digraph_algorithm_visit.js index 10ffc39..cbeebd0 100644 --- a/src/arc_core_digraph_algoithm_visit.js +++ b/src/arc_core_digraph_algorithm_visit.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-algorithm-common-visit.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -12,7 +10,7 @@ // Wraps call to DirectedGraph algorithm visitor function callbacks. -var helperFunctions = require('./helper-functions'); +var helperFunctions = require('./arc_core_graph_util'); /* request = { diff --git a/src/arc_core_digraph_export.js b/src/arc_core_digraph_export.js index a497bb1..dfe3de8 100644 --- a/src/arc_core_digraph_export.js +++ b/src/arc_core_digraph_export.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-json-export.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -16,7 +14,7 @@ // constructor parameter to restore container state across // execution contexts. -var helperFunctions = require('./helper-functions'); +var helperFunctions = require('./arc_core_graph_util'); var DigraphDataExporter = module.exports = {}; DigraphDataExporter.exportObject = function (digraph_) { diff --git a/src/arc_core_digraph_import.js b/src/arc_core_digraph_import.js index 7bac07d..d03702c 100644 --- a/src/arc_core_digraph_import.js +++ b/src/arc_core_digraph_import.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-json-import.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. diff --git a/src/arc_core_digraph_in_params.js b/src/arc_core_digraph_in_params.js index f220747..23e73dd 100644 --- a/src/arc_core_digraph_in_params.js +++ b/src/arc_core_digraph_in_params.js @@ -1,7 +1,5 @@ /* - Encapsule/jsgraph/src/digraph-in-parameters.js - - Copyright (C) 2014-2015 Christopher D. Russell + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. @@ -10,7 +8,7 @@ with in-memory data on Node.js and HTML. */ -var helperFunctions = require('./helper-functions'); +var helperFunctions = require('./arc_core_graph_util'); var verifyVertexReadRequest = function(request_) { var response = { error: null, result: false }; diff --git a/src/arc_core_graph.js b/src/arc_core_graph.js index b71d522..bac0858 100644 --- a/src/arc_core_graph.js +++ b/src/arc_core_graph.js @@ -2,7 +2,7 @@ The MIT License (MIT) - Copyright (c) 2014-2015 Christopher D. Russell + Copyright (c) 2014-2016 Christopher D. Russell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -51,7 +51,7 @@ var jsgraph = module.exports = { // [1] see DirectedGraph.toJSON/toObject methods. // //// - create: require('./src/digraph').createDirectedGraph, + create: require('./arc_core_digraph').createDirectedGraph, // Directed graph transposition algorithm. // Creates a new DirectedGraph container object that's identical @@ -59,21 +59,21 @@ var jsgraph = module.exports = { // the edges are reverese in the result digraph. Note that if present, // vertex and edge properties in the source digraph are copied by // reference to the result digraph. - transpose: require('./src/digraph-algorithm-transpose'), + transpose: require('./arc_core_digraph_algorithm_transpose'), // Directed graph breadth-first traversal visitor algorithm. - breadthFirstTraverse: require('./src/digraph-algorithm-bft'), + breadthFirstTraverse: require('./arc_core_digraph_algorithm_bft'), // Directed graph depth-first traversal visitor algorithm. - depthFirstTraverse: require('./src/digraph-algorithm-dft'), + depthFirstTraverse: require('./arc_core_digraph_algorithm_dft'), // ADVANCED // Color constant hashtable (advanced). - colors: require('./src/digraph-algorithm-common-colors'), + colors: require('./arc_core_digraph_algorithm_colors'), // Directed graph traversal context factory (advanced). - createTraversalContext: require('./src/digraph-algorithm-common-context') + createTraversalContext: require('./arc_core_digraph_algorithm_context') } }; diff --git a/src/arc_core_graph_util.js b/src/arc_core_graph_util.js index 59a9084..14390a5 100644 --- a/src/arc_core_graph_util.js +++ b/src/arc_core_graph_util.js @@ -1,7 +1,5 @@ -/* - Encapsule/jsgraph/src/helper-functions.js - - Copyright (C) 2014-2015 Christopher D. Russell +/* + Copyright (C) 2014-2016 Christopher D. Russell This library is published under the MIT License and is part of the Encapsule Project System in Cloud (SiC) open service architecture. diff --git a/test/fixture/test-runner-algorithm-common-request.js b/test/fixture/test-runner-algorithm-common-request.js index 9611342..795e3eb 100644 --- a/test/fixture/test-runner-algorithm-common-request.js +++ b/test/fixture/test-runner-algorithm-common-request.js @@ -2,7 +2,9 @@ // var assert = require('chai').assert; -var normalizeAlgorithmRequest = require('../../src/digraph-algorithm-common-request'); + +var testModule = require('../module-under-test'); +var normalizeAlgorithmRequest = testModule('arc_core_digraph_algorithm_request'); /* request = { diff --git a/test/fixture/test-runner-algorithm-common-visitor.js b/test/fixture/test-runner-algorithm-common-visitor.js index 9af89e4..59592d8 100644 --- a/test/fixture/test-runner-algorithm-common-visitor.js +++ b/test/fixture/test-runner-algorithm-common-visitor.js @@ -1,7 +1,9 @@ // test-runner-algorithm-common-visitor.js var assert = require('chai').assert; -var callVisitorMethod = require('../../src/digraph-algorithm-common-visit'); + +var testModule = require('../module-under-test'); +var callVisitorMethod = testModule('arc_core_digraph_algorithm_visit'); /* request = { diff --git a/test/fixture/test-runner-create-digraph.js b/test/fixture/test-runner-create-digraph.js index 46c6086..aae5923 100644 --- a/test/fixture/test-runner-create-digraph.js +++ b/test/fixture/test-runner-create-digraph.js @@ -12,7 +12,8 @@ */ var assert = require('chai').assert; -var DirectedGraphContainer = require('../../src/digraph'); +var testModule = require('../module-under-test'); +var DirectedGraphContainer = testModule('arc_core_digraph'); var createDirectedGraph = DirectedGraphContainer.createDirectedGraph; var DirectedGraph = DirectedGraphContainer.DirectedGraph; assert.isDefined(createDirectedGraph); @@ -54,7 +55,7 @@ module.exports = function (testVector_) { it("the returned graph JSON should match expected control value.", function() { assert.instanceOf(response.result, DirectedGraph); - assert.equal(response.result.toJSON(), testVector_.expectedResults.result); + assert.equal(response.result.stringify(), testVector_.expectedResults.result); }); } else { diff --git a/test/fixture/test-runner-digraph-algorithm-bft.js b/test/fixture/test-runner-digraph-algorithm-bft.js index 2690cd9..ac6b3e1 100644 --- a/test/fixture/test-runner-digraph-algorithm-bft.js +++ b/test/fixture/test-runner-digraph-algorithm-bft.js @@ -2,7 +2,10 @@ // var assert = require('chai').assert; -var BFT = require('../../src/digraph-algorithm-bft'); + +var testModule = require('../module-under-test'); + +var BFT = testModule('arc_core_digraph_algorithm_bft'); var SearchPathRecorder = require('./bfv-results-recorder'); /* diff --git a/test/fixture/test-runner-digraph-algorithm-dft.js b/test/fixture/test-runner-digraph-algorithm-dft.js index e25531f..69fd999 100644 --- a/test/fixture/test-runner-digraph-algorithm-dft.js +++ b/test/fixture/test-runner-digraph-algorithm-dft.js @@ -2,7 +2,9 @@ // var assert = require('chai').assert; -var DFT = require('../../src/digraph-algorithm-dft'); + +var testModule = require('../module-under-test'); +var DFT = testModule('arc_core_digraph_algorithm_dft'); var SearchPathRecorder = require('./dfv-results-recorder'); /* diff --git a/test/fixture/test-runner-digraph-in-params.js b/test/fixture/test-runner-digraph-in-params.js index 28ae1d9..0fbaeb2 100644 --- a/test/fixture/test-runner-digraph-in-params.js +++ b/test/fixture/test-runner-digraph-in-params.js @@ -2,7 +2,9 @@ // var assert = require('chai').assert; -var digraphInParams = require('../../src/digraph-in-parameters'); + +var testModule = require('../module-under-test'); +var digraphInParams = testModule('arc_core_digraph_in_params'); /* request = { diff --git a/test/module-under-test.js b/test/module-under-test.js new file mode 100644 index 0000000..6542e1f --- /dev/null +++ b/test/module-under-test.js @@ -0,0 +1 @@ +module.exports = require('./test-module-resolver')('arccore'); diff --git a/test/test-digraph-algorithm-bft.js b/test/test-digraph-algorithm-bft.js index 470bc47..a7ab0b0 100644 --- a/test/test-digraph-algorithm-bft.js +++ b/test/test-digraph-algorithm-bft.js @@ -1,7 +1,9 @@ // test-digraph-algorithm-bft.js var assert = require('chai').assert; -var DirectedGraph = require('../src/digraph').DirectedGraph; + +var testModule = require('./module-under-test'); +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; var testBFT = require('./fixture/test-runner-digraph-algorithm-bft'); diff --git a/test/test-digraph-algorithm-common-context.js b/test/test-digraph-algorithm-common-context.js index fd318f4..3ec9363 100644 --- a/test/test-digraph-algorithm-common-context.js +++ b/test/test-digraph-algorithm-common-context.js @@ -4,8 +4,9 @@ var assert = require('chai').assert; // internal -var DirectedGraph = require('../src/digraph').DirectedGraph; -var createTraverseContext = require('../src/digraph-algorithm-common-context'); +var testModule = require('./module-under-test'); +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; +var createTraverseContext = testModule('arc_core_digraph_algorithm_context'); describe("Traverse context: missing request object.", function() { diff --git a/test/test-digraph-algorithm-common-request.js b/test/test-digraph-algorithm-common-request.js index 5d0c526..667a5f4 100644 --- a/test/test-digraph-algorithm-common-request.js +++ b/test/test-digraph-algorithm-common-request.js @@ -1,7 +1,8 @@ // test-digraph-algorithm-common-request.js -var DirectedGraph = require('../src/digraph').DirectedGraph; -var createTraverseContext = require('../src/digraph-algorithm-common-context'); +var testModule = require('./module-under-test'); +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; +var createTraverseContext = testModule('arc_core_digraph_algorithm_context'); var assert = require('chai').assert; var testTraverseRequestNormalizer = require('./fixture/test-runner-algorithm-common-request'); @@ -28,7 +29,7 @@ testTraverseRequestNormalizer({ var digraph = new DirectedGraph({ elist: [ {e:{u:"VARMIT",v:"RAT"}}, {e:{u:"VARMIT",v:"MOUSE"}},{e:{u:"VARMIT",v:"VOLE"}}] }); - + testTraverseRequestNormalizer({ testName: "Bad input: missing 'visitor'", validConfig: false, request: { digraph: digraph }, @@ -37,7 +38,7 @@ testTraverseRequestNormalizer({ json: '' } }); - + testTraverseRequestNormalizer({ testName: "Bad input: Bad options object type", validConfig: false, request: { digraph: digraph, visitor: nullVisitor, options: "Joe Smith" }, @@ -52,7 +53,7 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor }, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"startVector":["VARMIT"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"startVector":["VARMIT"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' } }); @@ -61,7 +62,7 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { signalStart: true }}, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"signalStart":true,"startVector":["VARMIT"],"allowEmptyStartVector":false,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"signalStart":true,"startVector":["VARMIT"],"allowEmptyStartVector":false,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' } }); @@ -70,7 +71,7 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { signalStart: false }}, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"signalStart":false,"startVector":["VARMIT"],"allowEmptyStartVector":false,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"signalStart":false,"startVector":["VARMIT"],"allowEmptyStartVector":false,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' } }); @@ -88,7 +89,7 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { startVector: "someVertexMayBeInvalid"}}, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"startVector":["someVertexMayBeInvalid"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"startVector":["someVertexMayBeInvalid"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' } }); @@ -97,11 +98,10 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { startVector: [ "someVertexMayBeInvalid", "apple", "orange", "RAT" ]}}, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"startVector":["someVertexMayBeInvalid","apple","orange","RAT"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"startVector":["someVertexMayBeInvalid","apple","orange","RAT"],"allowEmptyStartVector":false,"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}}}}' } }); - (function() { var contextResponse = createTraverseContext({ digraph: digraph }); assert.isNull(contextResponse.error); @@ -123,7 +123,7 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { traverseContext: traverseContext }} , expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"RAT\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"MOUSE\\"}},{\\"e\\":{\\"u\\":\\"VARMIT\\",\\"v\\":\\"VOLE\\"}}]}","visitor":{},"options":{"traverseContext":{"searchStatus":"TEST-VALUE","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}},"startVector":["VARMIT"],"allowEmptyStartVector":false,"signalStart":true}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"VARMIT","v":"RAT"}},{"e":{"u":"VARMIT","v":"MOUSE"}},{"e":{"u":"VARMIT","v":"VOLE"}}]},"visitor":{},"options":{"traverseContext":{"searchStatus":"TEST-VALUE","colorMap":{"VARMIT":0,"RAT":0,"MOUSE":0,"VOLE":0},"undiscoveredMap":{"VARMIT":true,"RAT":true,"MOUSE":true,"VOLE":true}},"startVector":["VARMIT"],"allowEmptyStartVector":false,"signalStart":true}}' } }); @@ -150,8 +150,8 @@ testTraverseRequestNormalizer({ request: { digraph: digraph, visitor: nullVisitor, options: { allowEmptyStartVector: true }}, expectedResults: { error: '', - json: '{"digraph":"{\\"name\\":\\"\\",\\"description\\":\\"\\",\\"vlist\\":[],\\"elist\\":[{\\"e\\":{\\"u\\":\\"A\\",\\"v\\":\\"B\\"}},{\\"e\\":{\\"u\\":\\"B\\",\\"v\\":\\"A\\"}}]}","visitor":{},"options":{"allowEmptyStartVector":true,"startVector":[],"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"A":0,"B":0},"undiscoveredMap":{"A":true,"B":true}}}}' + json: '{"digraph":{"name":"","description":"","vlist":[],"elist":[{"e":{"u":"A","v":"B"}},{"e":{"u":"B","v":"A"}}]},"visitor":{},"options":{"allowEmptyStartVector":true,"startVector":[],"signalStart":true,"traverseContext":{"searchStatus":"pending","colorMap":{"A":0,"B":0},"undiscoveredMap":{"A":true,"B":true}}}}' } }); - + })(); diff --git a/test/test-digraph-algorithm-common-visitor.js b/test/test-digraph-algorithm-common-visitor.js index 991d5c1..1b72f20 100644 --- a/test/test-digraph-algorithm-common-visitor.js +++ b/test/test-digraph-algorithm-common-visitor.js @@ -1,7 +1,8 @@ // test-digraph-algorothm-common-visitor.js -var DirectedGraph = require('../src/digraph').DirectedGraph; -var createTraverseContext = require('../src/digraph-algorithm-common-context'); +var testModule = require('./module-under-test'); +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; +var createTraverseContext = testModule('arc_core_digraph_algorithm_context'); var assert = require('chai').assert; var testAlgorithmVisitorCallback = require('./fixture/test-runner-algorithm-common-visitor'); diff --git a/test/test-digraph-algorithm-dft.js b/test/test-digraph-algorithm-dft.js index a214f7c..21e57b0 100644 --- a/test/test-digraph-algorithm-dft.js +++ b/test/test-digraph-algorithm-dft.js @@ -2,7 +2,8 @@ var assert = require('chai').assert; -var DirectedGraph = require('../src/digraph').DirectedGraph; +var testModule = require('./module-under-test'); +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; var testDFT = require('./fixture/test-runner-digraph-algorithm-dft'); diff --git a/test/test-digraph-algorithm-transpose.js b/test/test-digraph-algorithm-transpose.js index e80b437..e6e73ca 100644 --- a/test/test-digraph-algorithm-transpose.js +++ b/test/test-digraph-algorithm-transpose.js @@ -4,8 +4,10 @@ var expect = require('chai').expect; var should = require('chai').should; var uuid = require('node-uuid'); -var DirectedGraph = require('../src/digraph').DirectedGraph; -var transposeDigraph = require('../src/digraph-algorithm-transpose'); +var testModule = require('./module-under-test'); + +var DirectedGraph = testModule('arc_core_digraph').DirectedGraph; +var transposeDigraph = testModule('arc_core_digraph_algorithm_transpose'); describe("Directed graph tranposition test", function() { diff --git a/test/test-digraph-container.js b/test/test-digraph-container.js index cbde52a..91aa081 100644 --- a/test/test-digraph-container.js +++ b/test/test-digraph-container.js @@ -2,7 +2,10 @@ var assert = require('chai').assert; var uuid = require('node-uuid'); -var DirectedGraphContainer = require('../src/digraph'); + +var testModule = require('./module-under-test'); + +var DirectedGraphContainer = testModule('arc_core_digraph'); var DirectedGraph = DirectedGraphContainer.DirectedGraph; describe("DirectedGraph container object tests", function() { @@ -38,7 +41,7 @@ describe("DirectedGraph container object tests", function() { var copy = new DirectedGraph(); var vertices = ["foo", "bar", "baz"]; var json = null; - + before(function(){ vertices.forEach(function(u){ digraph.addVertex({ u: u, p: { k: u }}); @@ -52,11 +55,11 @@ describe("DirectedGraph container object tests", function() { it("graph export JSON should match expected control string", function() { var expectedJSON = '{"name":"","description":"","vlist":[{"u":"foo","p":{"k":"foo"}},{"u":"bar","p":{"k":"bar"}},{"u":"baz","p":{"k":"baz"}}],"elist":[{"e":{"u":"foo","v":"bar"}},{"e":{"u":"foo","v":"baz"}},{"e":{"u":"bar","v":"foo"}},{"e":{"u":"bar","v":"baz"}},{"e":{"u":"baz","v":"foo"}},{"e":{"u":"baz","v":"bar"}}]}'; - assert.equal(digraph.toJSON(), expectedJSON); + assert.equal(digraph.stringify(), expectedJSON); }); - it("graph should export properly structured JSON string", function(){ - json = digraph.toJSON(); + it("graph should export structured JSON string", function(){ + json = digraph.stringify(); assert.isString(json); var parsed = JSON.parse(json); assert.isObject(parsed); @@ -66,25 +69,25 @@ describe("DirectedGraph container object tests", function() { it("graph export to object and JSON should be identical", function() { var testObjectJSON = JSON.stringify(digraph.toObject()); - var testJSON = digraph.toJSON(); + var testJSON = digraph.stringify(); assert.equal(testObjectJSON, testJSON); }); it("graph constructed from export object should be identical to original", function() { var testGraph = new DirectedGraph(digraph.toObject()); - assert.equal(testGraph.toJSON(), digraph.toJSON()); + assert.deepEqual(testGraph.toJSON(), digraph.toJSON()); }); it("empty graph filled using fromObject should be identical to original", function() { var testGraph = new DirectedGraph(); testGraph.fromObject(digraph.toObject()); - assert.equal(testGraph.toJSON(), digraph.toJSON()); + assert.deepEqual(testGraph.toJSON(), digraph.toJSON()); }); it("empty graph filled using fromJSON should be identical to original", function() { var testGraph = new DirectedGraph(); testGraph.fromJSON(digraph.toJSON()); - assert.equal(testGraph.toJSON(), digraph.toJSON()); + assert.deepEqual(testGraph.toJSON(), digraph.toJSON()); }); describe("Re-create the directed graph container from the JSON.", function() { @@ -96,7 +99,7 @@ describe("DirectedGraph container object tests", function() { assert.doesNotThrow(constructCopy); }); it("graph should re-create identical graph from import", function(){ - assert.equal(copy.toJSON(), json); + assert.deepEqual(copy.stringify(), json); }); }); @@ -105,7 +108,7 @@ describe("DirectedGraph container object tests", function() { var testGraph = null; var expectedJSON = '{"name":"test","description":"test","vlist":[{"u":"strawberry","p":"has a property"},{"u":"not-mentioned-no-property"}],"elist":[{"e":{"u":"apple","v":"orange"}},{"e":{"u":"bannana","v":"apple"}},{"e":{"u":"pineapple","v":"orange"}},{"e":{"u":"strawberry","v":"blueberry"},"p":"link"}]}'; var actualJSON = null; - + before(function() { var digraph = new DirectedGraph({ name: 'test', @@ -126,7 +129,7 @@ describe("DirectedGraph container object tests", function() { { e: { u: 'pineapple', v: 'orange' }} ] }); - actualJSON = digraph.toJSON(); + actualJSON = digraph.stringify(); }); it("Exported JSON should match expected JSON value.", function() { @@ -388,7 +391,7 @@ describe("DirectedGraph container object tests", function() { it ("vertex out-edge array should have length zero", function() { assert.lengthOf(digraph.outEdges("apple"), 0); }); - + }); }); diff --git a/test/test-module-exports.js b/test/test-module-exports.js index 13cb343..a53b9e4 100644 --- a/test/test-module-exports.js +++ b/test/test-module-exports.js @@ -2,9 +2,9 @@ var chai = require('chai'); var assert = chai.assert; -var jsgraph = require('../index'); - -var DirectedGraph = require('../src/digraph'); +var testModule = require('./module-under-test'); +var jsgraph = testModule('arc_core_graph'); +var DirectedGraph = testModule('arc_core_digraph'); describe("Module export tests", function() { diff --git a/test/test-module-resolver.js b/test/test-module-resolver.js new file mode 100644 index 0000000..3ff0758 --- /dev/null +++ b/test/test-module-resolver.js @@ -0,0 +1,23 @@ +// test-module-resolver.js +// +// A little trick to decouple Mocha tests from the location +// of the modules they're testing. +// + +var PATH = require('path'); + +// packageName_ is the npm package name used to publish ARCspace/arc* +// repositories on github and npmjs.org. Note that these names are used +// here to select a subdirectory in the ./BUILD tree to use as the basis +// for further manual selecton of the target require. + +module.exports = function(packageName_) { + + basedir = "../src/"; + return function(submoduleName_) { + var submodulePath = PATH.join(basedir, submoduleName_); + console.log("> loading module under test '" + submodulePath + "'..."); + return require(submodulePath); + }; +}; + From 688535c4177f911ee1a0be4d1fffd09fa81acf41 Mon Sep 17 00:00:00 2001 From: Chris Russell Date: Wed, 21 Sep 2016 15:57:42 -0700 Subject: [PATCH 3/4] Documentation updates for issue #50. Copyright date update. --- LICENSE | 2 +- README.md | 97 +++++++++++++++++++++--- docs/algorithm-bft.md | 2 +- docs/algorithm-dft.md | 2 +- docs/algorithm-traversal.md | 2 +- docs/example-dft.md | 2 +- docs/object-DirectedGraph.md | 133 ++++++++++++++++++++------------- docs/object-JSON.md | 2 +- docs/transform-transpose.md | 2 +- examples/bft-vertex-ranking.js | 4 +- 10 files changed, 177 insertions(+), 71 deletions(-) diff --git a/LICENSE b/LICENSE index a07f7be..412073c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2015 Christopher D. Russell +Copyright (c) 2014-2016 Christopher D. Russell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 5cd8b29..4c399d3 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -# Encapsule/jsgraph +![Encapsule.io](https://encapsule.io/images/blue-burst-encapsule.io-logo-251x64.png "Encapsule.io") -[![Join the chat at https://gitter.im/Encapsule/jsgraph](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Encapsule/jsgraph?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +# Encapsule/jsgraph -## About jsgraph +![Begin at the beginning...](./docs/begin-at-the-beginning.jpg) _"... At the other end of the spectrum is, for example, graph theory, where the basic object, a graph, can be immediately comprehended. One will not get anywhere in graph theory by sitting in an armchair and trying to understand graphs better. Neither is it particularly necessary to read much of the literature before tackling a problem: it is of course helpful to be aware of some of the most important techniques, but the interesting problems tend to be open precisely because the established techniques cannot easily be applied."_ - [W.T. Gowers](https://en.wikipedia.org/wiki/Timothy_Gowers) -### Status +[![Build Status](https://travis-ci.org/Encapsule/jsgraph.svg?branch=master)](https://travis-ci.org/Encapsule/jsgraph) [![Join the chat at https://gitter.im/Encapsule/jsgraph](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Encapsule/jsgraph?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/Encapsule/jsgraph.svg?branch=master)](https://travis-ci.org/Encapsule/jsgraph) +See also: [Mathematical Graph Theory](https://en.wikipedia.org/wiki/Graph_theory) -Ich danke Ihnen sehr [Travis CI](https://travis-ci.org/Encapsule/jsgraph.svg?branch=master) +## About jsgraph ### Summary @@ -30,7 +30,7 @@ The library provides and normalizes the following operations independent of grap ### Audience -jsgraph is a framework for building next-generation frameworks on Node.js and HTML 5. +jsgraph is a framework for building next-generation frameworks on Node.js and HTML 5 applications: - Use instead of in-memory object hierarchies linked by reference: - Serializable to JSON (even when cyclic). @@ -49,6 +49,72 @@ If you're considering using jsgraph in a commerical product, please get in touch ### Programming +#### API Overview + +[DirectedGraph](./docs/object-DirectedGraph.md) container class methods: + +- constructor +- getGraphName +- setGraphName +- getGraphDescription +- setGraphDescription +- isVertex +- addVertex +- removeVertex +- getVertexProperty +- setVertexProperty +- hasVertexProperty +- clearVertexProperty +- inDegree +- inEdges +- outDegree +- outEdges +- isEdge +- addEdge +- removeEdge +- getEdgeProperty +- setEdgeProperty +- hasEdgeProperty +- clearEdgeProperty +- verticesCount +- getVertices +- edgesCount +- getEdges +- rootVerticesCount +- getRootVertices +- leafVerticesCount +- getLeafVertices +- toJSON / toObject (alias) +- stringify +- fromObject +- fromJSON + +Included algorithms: + +- [Tranposition](./docs/algorithm-transpose.md) (flips the direction of edges) +- [Breadth-first visit and search](./docs/algorithm-bft.md) w/visitor pattern callbacks: + - initializeVertex + - startVertex + - discoverVertex + - examineVertex + - examineEdge + - nonTreeEdge + - grayTarget + - blackTarget + - finishVertex +- [Depth-first visit and search](./docs/algorithm-dft.md) w/visitor pattern callbacks: + - initializeVertex + - startVertex + - discoverVertex + - examineEdge + - treeEdge + - backEdge + - forwardOrCrossEdge + - finishVertex + - finishEdge + +#### API Detail + - [Object Reference: DirectedGraph container](./docs/object-DirectedGraph.md) - [Object Reference: DirectedGraph export object](./docs/object-JSON.md) - [Transform Reference: jsgraph.directed.transpose](./docs/transform-transpose.md) @@ -61,7 +127,7 @@ If you're considering using jsgraph in a commerical product, please get in touch In your project, install via npm. $ npm install jsgraph --save - jsgraph@0.6.xx node_modules/jsgraph + jsgraph@0.7.xx node_modules/jsgraph ### Sources @@ -86,7 +152,7 @@ See also: [Encapsule/jsgraph on GitHub](https://github.com/Encapsule/jsgraph) ## Example -The following short example constructs a `DirectedGraph` container using a v0.6 jsgraph digraph data object, and derives a simple rank assignment algorithm from jsgraph's bundled `breadthFirstTraverse` algorithm. Note that the BFT visitor interface callback functions leverage the `DirectedGraph` API to get/set the data property value of each visited vertex to its rank. +The following short example constructs a `DirectedGraph` container using a v0.7 jsgraph digraph data object, and derives a simple rank assignment algorithm from jsgraph's bundled `breadthFirstTraverse` algorithm. Note that the BFT visitor interface callback functions leverage the `DirectedGraph` API to get/set the data property value of each visited vertex to its rank. ```javascript // Encapsule/jsgraph/examples/bft-vertex-ranking.js var jsgraph = require('jsgraph'); @@ -127,7 +193,7 @@ if (response.error) { throw new Error(response.error); } console.log("DirectedGraph: '" + -digraph.toJSON(undefined,4) + "'"); +digraph.stringify(undefined,4) + "'"); console.log("BFT traversal: '" + JSON.stringify(response.result,undefined,4) + "'"); ``` @@ -188,6 +254,15 @@ BFT traversal: '{ ## Release +**v0.7 is a breaking API change and documentation release** + +- Added new method `DirectedGraph.stringify` +- Changed method semantics of `DirectedGraph.toJSON` to return a serializable object instead of a JSON-encoded string. +- Alias method `DirectedGraph.toObject` to call `DirectedGraph.toJSON`. The `toObject` method is now deprecated and will be removed in a future release. +- Updated documentation: + - Per above breaking changes to the `DirectedGraph` serialization API. + - Added additional information on set/get of `DirectedGraph` name and description properties. + **v0.6 is a bug fix release that's API-compatible with v0.5** - DFT algorithm bug fixes impacting order and identity of client visitor callbacks. @@ -349,7 +424,7 @@ A depth-first traversal concludes when all reacable vertices have been visited,
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/algorithm-bft.md b/docs/algorithm-bft.md index 4562fcf..700d4fb 100644 --- a/docs/algorithm-bft.md +++ b/docs/algorithm-bft.md @@ -44,5 +44,5 @@ finishVertex | { u: string, g: DirectedGraph } | invoked on a vertex after all o
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/algorithm-dft.md b/docs/algorithm-dft.md index 6663f99..2088b1c 100644 --- a/docs/algorithm-dft.md +++ b/docs/algorithm-dft.md @@ -44,5 +44,5 @@ finishEdge | { e: { u: string, v: string }, g: DirectedGraph } | invoked on ea
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/algorithm-traversal.md b/docs/algorithm-traversal.md index 0443b22..c3d08c6 100644 --- a/docs/algorithm-traversal.md +++ b/docs/algorithm-traversal.md @@ -120,5 +120,5 @@ if (!response.error) {
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/example-dft.md b/docs/example-dft.md index e62f3af..76ae4c8 100644 --- a/docs/example-dft.md +++ b/docs/example-dft.md @@ -122,5 +122,5 @@ A simple JavaScript/jsgraph implementation of Depth-first search (DFS) example f
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/object-DirectedGraph.md b/docs/object-DirectedGraph.md index ac463f0..0d33908 100644 --- a/docs/object-DirectedGraph.md +++ b/docs/object-DirectedGraph.md @@ -15,15 +15,11 @@ Many very important and common data structures are simply specific cases of dire - Have more productive dicussions with your co-workers. - Accommodate changing requirements by design, not reaction. - - - - -## Construction +## Construction **See also: [Object reference: JSON I/O](./object-JSON.md)** -jsgraph's directed graph container, `DirectedGraph`, is constructed by calling the `jsgraph.directed.create` factory function export. +jsgraph's directed graph container, `DirectedGraph`, is constructed by calling the `jsgraph.directed.create` factory function export. ```javascript var jsgraph = require('jsgraph'); @@ -31,7 +27,7 @@ var response = jsgraph.directed.create(/*optional init data*/); if (!response.error) { // container is ready for use var digraph = response.result; - console.log("digraph JSON = '" + digraph.toJSON() + "'"); + console.log("digraph JSON = '" + digraph.stringify() + "'"); } else { // container constructor failed console.error(response.error); @@ -45,7 +41,7 @@ If the `DirectedGraph` container is successfully constructed, `jsgraph.directed. However, if you call `jsgraph.directed.create` and pass a parameter the constructor cannot parse, the response object will contain an error string as follows and the response.result property will be null. '{ error: "Some error string explaining what went wrong.", result: null }` - + **Note:** Not all jsgraph functions and methods return error/result response objects. Many are implemented instead to return reasonable default values when bad input is received. However, in cases where an error/result response is indicated in the documentation, it is essential that you check and handle all errors reported by jsgraph as all are significant. @@ -109,12 +105,12 @@ var edgeWriteRequest = { p: { notes: "some data to associate with the edge from 'Hello' to 'World'" } }; ``` - + # DirectedGraph vertex methods -## DirectedGraph.isVertex +## DirectedGraph.isVertex ```javascript digraph.isVertex(string); @@ -137,7 +133,7 @@ If you pass the ID of a non-existent vertex, or bad input the response will be f -## DirectedGraph.addVertex +## DirectedGraph.addVertex ```javascript var response = digraph.addVertex({ u: string, p: data}); @@ -171,7 +167,7 @@ The `setVertexProperty` method is a convenience alias for the `addVertex` and th -## DirectedGraph.removeVertex +## DirectedGraph.removeVertex ```javascript digraph.removeVertex(string); @@ -198,7 +194,7 @@ If you pass bad input, or the vertex doesn't exist in the container the call ret -## DirectedGraph.getVertexProperty +## DirectedGraph.getVertexProperty ```javascript var response = digraph.getVertexProperty(string); @@ -220,7 +216,7 @@ Returns a reference to data associated with the vertex in the container. If no a -## DirectedGraph.setVertexProperty +## DirectedGraph.setVertexProperty `setVertexProperty` is an alias for method `addVertex`. @@ -228,7 +224,7 @@ Returns a reference to data associated with the vertex in the container. If no a -## DirectedGraph.hasVertexProperty +## DirectedGraph.hasVertexProperty ```javascript var response = digraph.hasVertexProperty(string); @@ -250,7 +246,7 @@ Returns true if the vertex has associated property data. Otherwise, false. -## DirectedGraph.clearVertexProperty +## DirectedGraph.clearVertexProperty ```javascript var response = digraph.clearVertexProperty(string); @@ -273,7 +269,7 @@ Returns true to indicate that regardless of initial conditions, the vertex now h -## DirectedGraph.inDegree +## DirectedGraph.inDegree ```javascript var response = digraph.inDegree(string); @@ -295,7 +291,7 @@ Integer indicating the in-degree of the specific vertex. -## DirectedGraph.inEdges +## DirectedGraph.inEdges ```javascript var response = digraph.inEdges(string); @@ -325,7 +321,7 @@ response = [ -## DirectedGraph.outDegree +## DirectedGraph.outDegree ```javascript var response = digraph.outDegree(string); @@ -346,7 +342,7 @@ Integer indicating the out-degree of the specific vertex. -## DirectedGraph.outEdges +## DirectedGraph.outEdges ```javascript var response = digraph.outEdges(string); @@ -373,7 +369,7 @@ Array of edge descriptor objects specifying the source and sink vertex ID's of e # DirectedGraph edge methods -## DirectedGraph.addEdge +## DirectedGraph.addEdge ```javascript var response = digraph.addEdge({ e: { u: string, v: string }, p: data }); @@ -407,11 +403,11 @@ The `setEdgeProperty` method is a convenience alias for `addEdge` and their beha -## DirectedGraph.isEdge +## DirectedGraph.isEdge -```javascript +```javascript var response = digraph.isEdge({ u: string, v: string }); -``` +``` **Request** @@ -429,7 +425,7 @@ Return true if the edge is part of the graph. Otherwise, false. -## DirectedGraph.removeEdge +## DirectedGraph.removeEdge ```javascript var response = digraph.removeEdge({ u: string, v: string }); @@ -454,7 +450,7 @@ Removing an edge has no impact on the edges vertices or their associated propert -## DirectedGraph.getEdgeProperty +## DirectedGraph.getEdgeProperty ```javascript var response = digraph.getEdgePropertyObject({ u: string, v: string }); @@ -477,7 +473,7 @@ Returns a reference to the property data associated with the specified edge in t -## DirectedGraph.setEdgeProperty +## DirectedGraph.setEdgeProperty `setEdgeProperty` is an alias for `addEdge`. @@ -485,7 +481,7 @@ Returns a reference to the property data associated with the specified edge in t -## DirectedGraph.hasEdgeProperty +## DirectedGraph.hasEdgeProperty ```javascript var response = digraph.hasEdgeProperty({ u: string, v: string }); @@ -506,7 +502,7 @@ Returns true if the specified edge has associated property data. Otherwise false -## DirectedGraph.clearEdgeProperty +## DirectedGraph.clearEdgeProperty ```javascript var response = digraph.clearEdgeProperty({ u: string, v: string }); @@ -529,9 +525,43 @@ Returns true to indicate that regardless of initial conditions there is no prope # DirectedGraph container methods +## DirectedGraph.setGraphName + +```javascript +var name = digraph.getGraphName(); +``` + +**Response** +Returns a string. + +## DirectedGraph.getGraphName + +```javascript +digraph.setGraphName("Washington State Roadways"); +``` +**Response** +None -## DirectedGraph.verticesCount +## DirectedGraph.setGraphDescription + +```javascript +var description = digraph.getGraphDescription(); +``` + +**Response** +Returns a string + +## DirectedGraph.getGraphDescription + +```javascript +digraph.setGraphDescription("This is a graph of all roadways in Washington State"); +``` + +**Response** +None + +## DirectedGraph.verticesCount ```javascript var response = digraph.verticesCount(); @@ -546,7 +576,7 @@ Integer indicating the number of vertices in this graph. -## DirectedGraph.getVertices +## DirectedGraph.getVertices ```javascript vertices = digraph.getVertices(); @@ -554,14 +584,14 @@ vertices = digraph.getVertices(); **Response** -Returns an array of string vertex identifiers. +Returns an array of string vertex identifiers. -## DirectedGraph.edgesCount +## DirectedGraph.edgesCount ```javascript var response = digraph.edgesCount(); @@ -576,7 +606,7 @@ Integer indicating the number of edges in this graph. -## DirectedGraph.getEdges +## DirectedGraph.getEdges ```javascript var response = digraph.getEdges(); @@ -590,7 +620,7 @@ Returns an array of edge descriptor objects with `u` and `v` properties set to t -## DirectedGraph.rootVerticesCount +## DirectedGraph.rootVerticesCount ```javascript var response = digraph.rootVerticesCount(); @@ -602,7 +632,7 @@ Integer count of the number of vertices with in-degree equal to zero (0). -## jsgraph.DirectedGraph.getRootVertices +## DirectedGraph.getRootVertices ```javascript var response = digraph.getRootVertices(); @@ -616,7 +646,7 @@ Returns an array of identifier strings indicating the set of root vertices in th -### DirectedGraph.leafVerticesCount +### DirectedGraph.leafVerticesCount ```javascript var response = digraph.leafVerticesCount(); @@ -629,7 +659,7 @@ Integer count of the number of vertices with out-degree equal to zero (0). -## Directedgraph.getLeafVertices +## Directedgraph.getLeafVertices ```javascript var response = digraph.getLeafVertices(); @@ -641,7 +671,11 @@ Returns an array of identifier strings indicating the set of leaf vertices in th -### DirectedGraph.toObject +## DirectedGraph.toObject + +_Method `toObject` is a deprecated alias for `toJSON` that will be removed from a future release of jsgraph. + +## DirectedGraph.toJSON **See also: [Object Reference: data I/O](./docs/object-JSON.md)** @@ -659,24 +693,27 @@ Returns a serialized data object that contains the contents of the directed grap The object returned may be passed to the `DirectedGraph` constructor, or to method `fromObject`. -### DirectedGraph.toJSON + + +## DirectedGraph.stringify **See also: [Object Reference: data I/O](./docs/object-JSON.md)** ```javscript -var response = digraph.toJSON(replacer,space); +var response = digraph.stringify(replacer,space); ``` **Response** -Returns a `DirectedGraph`'s serialized data object converted to JSON. +Returns a a serialized DirectedGraph as a JSON-encoded string. **Remarks:** -The JSON string returned may be passed to the `DirectedGraph` constructor, or to method `fromJSON`. +Use this method when you want to directly serialize a `DirectedGraph` container instance. + -### DirectedGraph.fromObject +## DirectedGraph.fromObject **See also: [Object Reference: data I/O](./docs/object-JSON.md)** @@ -701,16 +738,12 @@ JavaScript object with the following properties: -### DirectedGraph.fromJSON +## DirectedGraph.fromJSON Identical to `fromObject` except that the request is a JSON string instead of a datg object. - - - -
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/object-JSON.md b/docs/object-JSON.md index 7375909..9a87671 100644 --- a/docs/object-JSON.md +++ b/docs/object-JSON.md @@ -84,5 +84,5 @@ var edgeWriteRequest = {
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/docs/transform-transpose.md b/docs/transform-transpose.md index e250085..30d1fee 100644 --- a/docs/transform-transpose.md +++ b/docs/transform-transpose.md @@ -21,5 +21,5 @@ JavaScript object with the following properties:
-Copyright © 2014-2015 [Christopher D. Russell](https://github.com/ChrisRus) +Copyright © 2014-2016 [Christopher D. Russell](https://github.com/ChrisRus) diff --git a/examples/bft-vertex-ranking.js b/examples/bft-vertex-ranking.js index b146179..a0c59d1 100644 --- a/examples/bft-vertex-ranking.js +++ b/examples/bft-vertex-ranking.js @@ -38,10 +38,8 @@ if (response.error) { throw new Error(response.error); } -console.log("DirectedGraph: '" + digraph.toJSON(undefined, 4) + "'"); +console.log("DirectedGraph: '" + digraph.stringify(undefined, 4) + "'"); console.log("BFT traversal: '" + JSON.stringify(response.result,undefined,4) + "'"); - - From db4106d03bf51dbf04ee655ec6fc54225c7b811a Mon Sep 17 00:00:00 2001 From: Chris Russell Date: Wed, 21 Sep 2016 16:08:33 -0700 Subject: [PATCH 4/4] Update README.md for v0.7 release. --- README.md | 73 +++---------------------------------------------------- 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 4c399d3..e13737e 100644 --- a/README.md +++ b/README.md @@ -49,72 +49,6 @@ If you're considering using jsgraph in a commerical product, please get in touch ### Programming -#### API Overview - -[DirectedGraph](./docs/object-DirectedGraph.md) container class methods: - -- constructor -- getGraphName -- setGraphName -- getGraphDescription -- setGraphDescription -- isVertex -- addVertex -- removeVertex -- getVertexProperty -- setVertexProperty -- hasVertexProperty -- clearVertexProperty -- inDegree -- inEdges -- outDegree -- outEdges -- isEdge -- addEdge -- removeEdge -- getEdgeProperty -- setEdgeProperty -- hasEdgeProperty -- clearEdgeProperty -- verticesCount -- getVertices -- edgesCount -- getEdges -- rootVerticesCount -- getRootVertices -- leafVerticesCount -- getLeafVertices -- toJSON / toObject (alias) -- stringify -- fromObject -- fromJSON - -Included algorithms: - -- [Tranposition](./docs/algorithm-transpose.md) (flips the direction of edges) -- [Breadth-first visit and search](./docs/algorithm-bft.md) w/visitor pattern callbacks: - - initializeVertex - - startVertex - - discoverVertex - - examineVertex - - examineEdge - - nonTreeEdge - - grayTarget - - blackTarget - - finishVertex -- [Depth-first visit and search](./docs/algorithm-dft.md) w/visitor pattern callbacks: - - initializeVertex - - startVertex - - discoverVertex - - examineEdge - - treeEdge - - backEdge - - forwardOrCrossEdge - - finishVertex - - finishEdge - -#### API Detail - - [Object Reference: DirectedGraph container](./docs/object-DirectedGraph.md) - [Object Reference: DirectedGraph export object](./docs/object-JSON.md) - [Transform Reference: jsgraph.directed.transpose](./docs/transform-transpose.md) @@ -312,7 +246,7 @@ if (response.error) { console.log(response.error); } else { digraph = response.result; - console.log(digraph.toJSON()); + console.log(digraph.stringify()); } ``` @@ -362,8 +296,9 @@ The `DirectedGraph` container object created by this process models "a graph" ge - `getRootVertices()` - retrieve an array of ID strings for all vertices that have in-degree zero - `leafVerticesCount()` - obtain count of vertices with out-degree zero - `getLeafVertices()` - retrieve an array of ID strings for all vertices that have out-degree zero -- `toObject()` - serialize the DirectedGraph container to a JavaScript data object -- `toJSON(replacer, space)` - serialize the DirectedGraph container to a JSON string +- `toObject()` - serialize the DirectedGraph container to a JavaScript data object (same as toJSON) **deprecated in v0.7** +- `toJSON()` - serialize the DirectedGraph container to a JavaScript data object (same as toObject) +- `stringify(replacer, space)` - serialize the DirectedGraph container to a JSON string - `fromObject(dataObject)` - import a jsgraph-format JavaScript data object into the container (addative) - `fromJSON(jsonString)` - import jsgraph-format JSON string into the container (addative)