From 13401a0c4d5c5b79779718d34c8beefeaf161d14 Mon Sep 17 00:00:00 2001 From: Chris Russell Date: Wed, 21 Sep 2016 13:17:50 -0700 Subject: [PATCH] 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); + }; +}; +