Skip to content

Commit

Permalink
Breaking fix for bug #51 DirectedGraph serialization API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRus committed Sep 21, 2016
1 parent 3430b4a commit 13401a0
Show file tree
Hide file tree
Showing 30 changed files with 145 additions and 120 deletions.
6 changes: 2 additions & 4 deletions 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"
},
Expand All @@ -25,8 +25,6 @@
"BFS",
"DFS",
"data modeling",
"semantics",
"semantic modeling",
"data",
"JSON",
"data semantics",
Expand Down
35 changes: 19 additions & 16 deletions 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.
Expand All @@ -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); }; };
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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_);
};
Expand Down
10 changes: 4 additions & 6 deletions 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.
Expand Down Expand Up @@ -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_) {
Expand Down
4 changes: 1 addition & 3 deletions 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.
Expand Down
8 changes: 3 additions & 5 deletions 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.
Expand All @@ -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 };
Expand Down
10 changes: 4 additions & 6 deletions 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.
Expand All @@ -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_) {
Expand Down
8 changes: 3 additions & 5 deletions 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.
Expand All @@ -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 = {
Expand Down
8 changes: 3 additions & 5 deletions 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.
Expand All @@ -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
Expand Down
@@ -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.
Expand All @@ -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 = {
Expand Down
6 changes: 2 additions & 4 deletions 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.
Expand All @@ -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_) {
Expand Down
4 changes: 1 addition & 3 deletions 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.
Expand Down
6 changes: 2 additions & 4 deletions 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.
Expand All @@ -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 };
Expand Down
14 changes: 7 additions & 7 deletions src/arc_core_graph.js
Expand Up @@ -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
Expand Down Expand Up @@ -51,29 +51,29 @@ 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
// to a caller-specified digraph except that the direction of the
// 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')

}
};
Expand Down
6 changes: 2 additions & 4 deletions 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.
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/test-runner-algorithm-common-request.js
Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion 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 = {
Expand Down
5 changes: 3 additions & 2 deletions test/fixture/test-runner-create-digraph.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 13401a0

Please sign in to comment.