@buggyorg/graphtools
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.rewrite = exports.walk = undefined; | ||
exports.utils = exports.rewrite = exports.walk = undefined; | ||
@@ -17,5 +17,10 @@ var _walk = require('./walk'); | ||
var _utils = require('./utils'); | ||
var utils = _interopRequireWildcard(_utils); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
exports.walk = walk; | ||
exports.rewrite = rewrite; | ||
exports.rewrite = rewrite; | ||
exports.utils = utils; |
@@ -6,2 +6,5 @@ 'use strict'; | ||
}); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.prefixMapping = prefixMapping; | ||
@@ -11,2 +14,5 @@ exports.prefixingFunction = prefixingFunction; | ||
exports.edgeConnectors = edgeConnectors; | ||
exports.linkToEdges = linkToEdges; | ||
exports.linkToPorts = linkToPorts; | ||
exports.rewriteNonConformEdges = rewriteNonConformEdges; | ||
exports.apply = apply; | ||
@@ -60,4 +66,131 @@ | ||
} | ||
/* | ||
function connectHierarchyEdges (graph, edgeHierarchy) { | ||
var eh = edgeHierarchy | ||
var name = eh[1][0].node | ||
var last = eh[1].length - 1 | ||
var linkId = `[${eh[0].v}@${eh[2].outPort}→${eh[0].w}@${eh[2].inPort}` | ||
var start = {v: eh[0].v, w: name, value: {outPort: graph.edge(eh[0]).outPort, inPort: linkId, inType: 'out'}} | ||
var lastEh = eh[1][last] | ||
var end = {v: lastEh.node, w: eh[0].w, value: {outPort: linkId, outType: 'in', inPort: graph.edge(eh[0]).inPort}} | ||
var pairs = _.zip(eh[1], _.tail(eh[1])).slice(0, -1) | ||
return _.concat([start], | ||
_.map(pairs, (p) => ({v: p[0].node, w: p[1].node, value: {outPort: linkId, outType: p[0].type, inPort: linkId, inType: p[1].type}})), | ||
[end]) | ||
} | ||
*/ | ||
function linkEdge(_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var h1 = _ref2[0]; | ||
var h2 = _ref2[1]; | ||
return { v: h1.node, w: h2.node, value: { outPort: h1.port, outType: h1.type, inPort: h2.port, inType: h2.type } }; | ||
} | ||
function convertLinkViaHierarchy(graph, link, hierarchy, name) { | ||
if (hierarchy.length === 0) { | ||
return { edges: [link], ports: [] }; | ||
} else { | ||
var extraPorts = _lodash2.default.map(hierarchy, function (e) { | ||
return _lodash2.default.assign(e, { port: name }); | ||
}); | ||
var edgeHierarchy = _lodash2.default.concat([{ node: link.v, port: link.value.outPort }], extraPorts, [{ node: link.w, port: link.value.inPort }]); | ||
var edges = _lodash2.default.zip(edgeHierarchy, _lodash2.default.tail(edgeHierarchy)).slice(0, -1).map(linkEdge); | ||
return { edges: edges, ports: extraPorts }; | ||
} | ||
} | ||
function linkEdgePortConvert(graph, link) { | ||
var hierarchy = (0, _utils.rawHierarchyConnection)(graph, link); | ||
var name = (0, _utils.linkName)(link); | ||
return convertLinkViaHierarchy(graph, link, hierarchy, name); | ||
} | ||
/** | ||
* A link is a connection between two nodes that do not necessarily have the same parent | ||
* A edge is a connection between two nodes that share a common parent | ||
* This function returns a list of edges for a link (length >= 1) | ||
*/ | ||
function linkToEdges(graph, link) { | ||
return linkEdgePortConvert(graph, link).edges; | ||
} | ||
function linkToPorts(graph, link) { | ||
return linkEdgePortConvert(graph, link).ports; | ||
} | ||
function convertNonConformEdgeList(graph, links) { | ||
var edgePortLinks = _lodash2.default.map(links, function (e) { | ||
return linkEdgePortConvert(graph, e); | ||
}); | ||
return edgePortLinks; | ||
} | ||
/* | ||
function addConformityLink (graph, node, port) { | ||
var nodeVal = graph.node(node) | ||
if (!isConformityPort(port)) return | ||
return { | ||
v: node, | ||
value: _.merge({}, nodeVal, {links: _.concat(nodeVal.links || [], [port])}), | ||
parent: graph.parent(node) | ||
} | ||
} | ||
/** | ||
* Add links to nodes that are on the edges to allow calling | ||
*/ /* | ||
function addConformityLinks (graph, edges) { | ||
var nonConfEdges = _.filter(edges, (e) => isConformityEdge) | ||
var nodes = _(nonConfEdges) | ||
.map((e) => { | ||
return _([[e.v, e.value.outPort], [e.w, e.value.inPort]]) | ||
.map((v) => { | ||
var node = addConformityLink(graph, v[0], v[1]) | ||
return (node) ? [v[1], node] : null | ||
}) | ||
.compact() | ||
.value() | ||
}) | ||
.flatten() | ||
.uniqBy((n) => { | ||
return n[0] + n[1].v | ||
}) | ||
.map((n) => n[1]) | ||
.flatten() | ||
.value() | ||
console.log(nodes) | ||
return nodes | ||
} | ||
*/ | ||
function linksCPorts(linkList) { | ||
var links = (0, _lodash2.default)(linkList).map('ports').flatten().groupBy('node').map(function (g) { | ||
return _lodash2.default.merge({}, _lodash2.default.omit(g[0], 'port'), { links: _lodash2.default.uniqBy(g, function (e) { | ||
return g.port; | ||
}) }); | ||
}).keyBy('node').value(); | ||
return links; | ||
} | ||
function rewriteNonConformEdges(graph, edges) { | ||
var editGraph = (0, _utils.edit)(graph); | ||
var linkEdges = convertNonConformEdgeList(graph, edges); | ||
/* var newNodes = addConformityLinks(graph, linkEdges) | ||
console.log(JSON.stringify(linkEdges, null, 2)) | ||
console.log(newNodes)*/ | ||
var newEdges = (0, _lodash2.default)(linkEdges).map('edges').flatten().value(); | ||
var nodes = linksCPorts(linkEdges); | ||
editGraph.edges = _lodash2.default.concat(editGraph.edges, newEdges); | ||
editGraph.nodes = _lodash2.default.map(editGraph.nodes, function (n) { | ||
if (_lodash2.default.has(nodes, n.v)) { | ||
return _lodash2.default.assign(n, { value: { links: nodes[n.v].links } }); | ||
} else { | ||
return n; | ||
} | ||
}); | ||
return (0, _utils.finalize)(editGraph); | ||
} | ||
/** | ||
* applys a lambda function with one input stream and one output stream | ||
@@ -64,0 +197,0 @@ * on an input stream |
@@ -10,4 +10,12 @@ 'use strict'; | ||
exports.prefixName = prefixName; | ||
exports.isNPG = isNPG; | ||
exports.isNG = isNG; | ||
exports.prefixNode = prefixNode; | ||
exports.addParent = addParent; | ||
exports.hierarchy = hierarchy; | ||
exports.rawHierarchyConnection = rawHierarchyConnection; | ||
exports.linkName = linkName; | ||
exports.hierarchyConnection = hierarchyConnection; | ||
exports.isConformityPort = isConformityPort; | ||
exports.isConformityEdge = isConformityEdge; | ||
@@ -44,2 +52,13 @@ var _graphlib = require('graphlib'); | ||
function isNPG(graph) { | ||
return !isNG(graph); | ||
} | ||
function isNG(graph) { | ||
// TODO: improve! | ||
return !_lodash2.default.find(graph.nodes(), function (n) { | ||
return n.indexOf('_PORT_') !== -1; | ||
}); | ||
} | ||
function prefixNode(prefix, node) { | ||
@@ -51,2 +70,45 @@ return _lodash2.default.merge({}, node, { v: prefixName(prefix, node.v) }); | ||
return _lodash2.default.merge({}, node, { parent: parent }); | ||
} | ||
function hierarchy(graph, node) { | ||
var h = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
return node ? hierarchy(graph, graph.parent(node), _lodash2.default.concat([node], h)) : h; | ||
} | ||
function rawHierarchyConnection(graph, edge) { | ||
var hFrom = hierarchy(graph, edge.v).slice(0, -1).map(function (f) { | ||
return { node: f, type: 'out' }; | ||
}); | ||
var hTo = hierarchy(graph, edge.w).slice(0, -1).map(function (t) { | ||
return { node: t, type: 'in' }; | ||
}); | ||
var hCon = _lodash2.default.dropWhile(_lodash2.default.zip(hFrom, hTo), function (z) { | ||
return z[0] && z[1] && z[0].node === z[1].node; | ||
}); | ||
var unzipH = _lodash2.default.unzip(hCon); | ||
return _lodash2.default.concat(_lodash2.default.compact(_lodash2.default.flatten([_lodash2.default.reverse(unzipH[0]), unzipH[1]]))); | ||
} | ||
function linkName(link) { | ||
var value = link.value; | ||
return '[' + link.v + '@' + value.outPort + '→' + link.w + '@' + value.inPort + ']'; | ||
} | ||
function hierarchyConnection(graph, edge) { | ||
var hFrom = hierarchy(graph, edge.v).slice(0, -1); | ||
var hTo = hierarchy(graph, edge.w).slice(0, -1); | ||
var hCon = _lodash2.default.dropWhile(_lodash2.default.zip(hFrom, hTo), function (f) { | ||
return f[0] === f[1]; | ||
}); | ||
var unzipH = _lodash2.default.unzip(hCon); | ||
return _lodash2.default.concat(_lodash2.default.compact(_lodash2.default.flatten([_lodash2.default.reverse(unzipH[0]), unzipH[1]]))); | ||
} | ||
function isConformityPort(p) { | ||
return p.indexOf('[') === 0 && p.indexOf(']') === p.length - 1; | ||
} | ||
function isConformityEdge(e) { | ||
return isConformityPort(e.value.inPort) || isConformityPort(e.value.outPort); | ||
} |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.predecessor = exports.successor = undefined; | ||
exports.predecessorOutPort = exports.predecessor = exports.successorInPort = exports.successor = undefined; | ||
exports.walk = walk; | ||
@@ -29,2 +29,12 @@ exports.walkBack = walkBack; | ||
var successorInPort = exports.successorInPort = function successorInPort(graph, node, port) { | ||
return (0, _lodash2.default)(graph.nodeEdges(node)).filter(function (e) { | ||
return e.v === node; | ||
}).filter(function (e) { | ||
return graph.edge(e).outPort === port; | ||
}).map(function (e) { | ||
return { node: e.w, port: graph.edge(e).inPort }; | ||
}).value(); | ||
}; | ||
var predecessor = exports.predecessor = function predecessor(graph, node, port) { | ||
@@ -40,2 +50,12 @@ return (0, _lodash2.default)(graph.nodeEdges(node)).filter(function (e) { | ||
var predecessorOutPort = exports.predecessorOutPort = function predecessorOutPort(graph, node, port) { | ||
return (0, _lodash2.default)(graph.nodeEdges(node)).filter(function (e) { | ||
return e.w === node; | ||
}).filter(function (e) { | ||
return graph.edge(e).inPort === port; | ||
}).map(function (e) { | ||
return { node: e.v, port: graph.edge(e).outPort }; | ||
}).value(); | ||
}; | ||
function walk(graph, node, path) { | ||
@@ -42,0 +62,0 @@ return generalWalk(graph, node, path, successor); |
{ | ||
"name": "@buggyorg/graphtools", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Tools for processing buggy graphs.", | ||
"main": "lib/api.js", | ||
"scripts": { | ||
"test": "node node_modules/standard/bin/cmd.js src/**/*.js && babel src -d lib && node_modules/mocha/bin/mocha --compilers js:babel-register" | ||
"test": "node node_modules/standard/bin/cmd.js src/**/*.js && babel src -d lib && node_modules/mocha/bin/mocha --compilers js:babel-register", | ||
"build": "babel src -d lib", | ||
"prepublish": "babel src -d lib" | ||
}, | ||
@@ -9,0 +11,0 @@ "keywords": [ |
import * as walk from './walk' | ||
import * as rewrite from './rewrites' | ||
import * as utils from './utils' | ||
export {walk as walk, rewrite as rewrite} | ||
export {walk as walk, rewrite as rewrite, utils as utils} |
import {edit, finalize, prefixNode, addParent} from './utils' | ||
import {edit, finalize, prefixNode, addParent, rawHierarchyConnection, linkName} from './utils' | ||
import _ from 'lodash' | ||
@@ -43,4 +43,128 @@ | ||
} | ||
/* | ||
function connectHierarchyEdges (graph, edgeHierarchy) { | ||
var eh = edgeHierarchy | ||
var name = eh[1][0].node | ||
var last = eh[1].length - 1 | ||
var linkId = `[${eh[0].v}@${eh[2].outPort}→${eh[0].w}@${eh[2].inPort}` | ||
var start = {v: eh[0].v, w: name, value: {outPort: graph.edge(eh[0]).outPort, inPort: linkId, inType: 'out'}} | ||
var lastEh = eh[1][last] | ||
var end = {v: lastEh.node, w: eh[0].w, value: {outPort: linkId, outType: 'in', inPort: graph.edge(eh[0]).inPort}} | ||
var pairs = _.zip(eh[1], _.tail(eh[1])).slice(0, -1) | ||
return _.concat([start], | ||
_.map(pairs, (p) => ({v: p[0].node, w: p[1].node, value: {outPort: linkId, outType: p[0].type, inPort: linkId, inType: p[1].type}})), | ||
[end]) | ||
} | ||
*/ | ||
function linkEdge ([h1, h2]) { | ||
return {v: h1.node, w: h2.node, value: {outPort: h1.port, outType: h1.type, inPort: h2.port, inType: h2.type}} | ||
} | ||
function convertLinkViaHierarchy (graph, link, hierarchy, name) { | ||
if (hierarchy.length === 0) { | ||
return {edges: [link], ports: []} | ||
} else { | ||
var extraPorts = _.map(hierarchy, (e) => _.assign(e, {port: name})) | ||
var edgeHierarchy = _.concat([{node: link.v, port: link.value.outPort}], | ||
extraPorts, | ||
[{node: link.w, port: link.value.inPort}]) | ||
var edges = _.zip(edgeHierarchy, _.tail(edgeHierarchy)) | ||
.slice(0, -1) | ||
.map(linkEdge) | ||
return {edges: edges, ports: extraPorts} | ||
} | ||
} | ||
function linkEdgePortConvert (graph, link) { | ||
var hierarchy = rawHierarchyConnection(graph, link) | ||
var name = linkName(link) | ||
return convertLinkViaHierarchy(graph, link, hierarchy, name) | ||
} | ||
/** | ||
* A link is a connection between two nodes that do not necessarily have the same parent | ||
* A edge is a connection between two nodes that share a common parent | ||
* This function returns a list of edges for a link (length >= 1) | ||
*/ | ||
export function linkToEdges (graph, link) { | ||
return linkEdgePortConvert(graph, link).edges | ||
} | ||
export function linkToPorts (graph, link) { | ||
return linkEdgePortConvert(graph, link).ports | ||
} | ||
function convertNonConformEdgeList (graph, links) { | ||
var edgePortLinks = _.map(links, (e) => linkEdgePortConvert(graph, e)) | ||
return edgePortLinks | ||
} | ||
/* | ||
function addConformityLink (graph, node, port) { | ||
var nodeVal = graph.node(node) | ||
if (!isConformityPort(port)) return | ||
return { | ||
v: node, | ||
value: _.merge({}, nodeVal, {links: _.concat(nodeVal.links || [], [port])}), | ||
parent: graph.parent(node) | ||
} | ||
} | ||
/** | ||
* Add links to nodes that are on the edges to allow calling | ||
*//* | ||
function addConformityLinks (graph, edges) { | ||
var nonConfEdges = _.filter(edges, (e) => isConformityEdge) | ||
var nodes = _(nonConfEdges) | ||
.map((e) => { | ||
return _([[e.v, e.value.outPort], [e.w, e.value.inPort]]) | ||
.map((v) => { | ||
var node = addConformityLink(graph, v[0], v[1]) | ||
return (node) ? [v[1], node] : null | ||
}) | ||
.compact() | ||
.value() | ||
}) | ||
.flatten() | ||
.uniqBy((n) => { | ||
return n[0] + n[1].v | ||
}) | ||
.map((n) => n[1]) | ||
.flatten() | ||
.value() | ||
console.log(nodes) | ||
return nodes | ||
} | ||
*/ | ||
function linksCPorts (linkList) { | ||
var links = _(linkList) | ||
.map('ports') | ||
.flatten() | ||
.groupBy('node') | ||
.map((g) => _.merge({}, _.omit(g[0], 'port'), {links: _.uniqBy(g, (e) => g.port)})) | ||
.keyBy('node') | ||
.value() | ||
return links | ||
} | ||
export function rewriteNonConformEdges (graph, edges) { | ||
var editGraph = edit(graph) | ||
var linkEdges = convertNonConformEdgeList(graph, edges) | ||
/* var newNodes = addConformityLinks(graph, linkEdges) | ||
console.log(JSON.stringify(linkEdges, null, 2)) | ||
console.log(newNodes)*/ | ||
var newEdges = _(linkEdges).map('edges').flatten().value() | ||
var nodes = linksCPorts(linkEdges) | ||
editGraph.edges = _.concat(editGraph.edges, newEdges) | ||
editGraph.nodes = _.map(editGraph.nodes, (n) => { | ||
if (_.has(nodes, n.v)) { | ||
return _.assign(n, {value: {links: nodes[n.v].links}}) | ||
} else { | ||
return n | ||
} | ||
}) | ||
return finalize(editGraph) | ||
} | ||
/** | ||
* applys a lambda function with one input stream and one output stream | ||
@@ -47,0 +171,0 @@ * on an input stream |
@@ -25,2 +25,11 @@ | ||
export function isNPG (graph) { | ||
return !isNG(graph) | ||
} | ||
export function isNG (graph) { | ||
// TODO: improve! | ||
return !_.find(graph.nodes(), (n) => n.indexOf('_PORT_') !== -1) | ||
} | ||
export function prefixNode (prefix, node) { | ||
@@ -33,1 +42,36 @@ return _.merge({}, node, {v: prefixName(prefix, node.v)}) | ||
} | ||
export function hierarchy (graph, node, h = []) { | ||
return (node) ? hierarchy(graph, graph.parent(node), _.concat([node], h)) : h | ||
} | ||
export function rawHierarchyConnection (graph, edge) { | ||
var hFrom = hierarchy(graph, edge.v).slice(0, -1).map((f) => ({node: f, type: 'out'})) | ||
var hTo = hierarchy(graph, edge.w).slice(0, -1).map((t) => ({node: t, type: 'in'})) | ||
var hCon = _.dropWhile(_.zip(hFrom, hTo), (z) => { | ||
return z[0] && z[1] && z[0].node === z[1].node | ||
}) | ||
var unzipH = _.unzip(hCon) | ||
return _.concat(_.compact(_.flatten([_.reverse(unzipH[0]), unzipH[1]]))) | ||
} | ||
export function linkName (link) { | ||
var value = link.value | ||
return `[${link.v}@${value.outPort}→${link.w}@${value.inPort}]` | ||
} | ||
export function hierarchyConnection (graph, edge) { | ||
var hFrom = hierarchy(graph, edge.v).slice(0, -1) | ||
var hTo = hierarchy(graph, edge.w).slice(0, -1) | ||
var hCon = _.dropWhile(_.zip(hFrom, hTo), (f) => f[0] === f[1]) | ||
var unzipH = _.unzip(hCon) | ||
return _.concat(_.compact(_.flatten([_.reverse(unzipH[0]), unzipH[1]]))) | ||
} | ||
export function isConformityPort (p) { | ||
return p.indexOf('[') === 0 && p.indexOf(']') === p.length - 1 | ||
} | ||
export function isConformityEdge (e) { | ||
return isConformityPort(e.value.inPort) || isConformityPort(e.value.outPort) | ||
} |
@@ -11,2 +11,9 @@ | ||
export var successorInPort = (graph, node, port) => | ||
_(graph.nodeEdges(node)) | ||
.filter((e) => e.v === node) | ||
.filter((e) => graph.edge(e).outPort === port) | ||
.map((e) => ({node: e.w, port: graph.edge(e).inPort})) | ||
.value() | ||
export var predecessor = (graph, node, port) => | ||
@@ -19,2 +26,9 @@ _(graph.nodeEdges(node)) | ||
export var predecessorOutPort = (graph, node, port) => | ||
_(graph.nodeEdges(node)) | ||
.filter((e) => e.w === node) | ||
.filter((e) => graph.edge(e).inPort === port) | ||
.map((e) => ({node: e.v, port: graph.edge(e).outPort})) | ||
.value() | ||
export function walk (graph, node, path) { | ||
@@ -21,0 +35,0 @@ return generalWalk(graph, node, path, successor) |
@@ -7,2 +7,3 @@ /* global describe, it */ | ||
import fs from 'fs' | ||
import {nonConformEdges} from '../src/normalization.js' | ||
// import _ from 'lodash' | ||
@@ -94,2 +95,48 @@ | ||
}) | ||
it('can rewrite non-conform edges over one compound-layer', () => { | ||
var aGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/partial_apply.json'))) | ||
var newGraph = rewrite.rewriteNonConformEdges(aGraph, [{v: 'c', w: 'a:add', value: {outPort: 'const1/output', inPort: 's2'}}]) | ||
expect(newGraph.edge({v: 'c', w: 'a'}).inPort).to.equal('[c@const1/output→a:add@s2]') | ||
expect(newGraph.edge({v: 'c', w: 'a'}).inType).to.equal('in') | ||
expect(newGraph.edge({v: 'a', w: 'a:add'}).outPort).to.equal('[c@const1/output→a:add@s2]') | ||
expect(newGraph.edge({v: 'a', w: 'a:add'}).outType).to.equal('in') | ||
}) | ||
/* it('can rewrite non-conform edges over many compound-layer', () => { | ||
var hGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/hierarchy.json'))) | ||
var newGraph = rewrite.rewriteNonConformEdges(hGraph, hGraph.edges().map((e) => ({v: e.v, w: e.w, value: hGraph.edge(e)}))) | ||
console.log(newGraph.edges().map((e) => ({v: e.v, w: e.w, value: newGraph.edge(e)}))) | ||
})*/ | ||
it('`linkToEdges` does not change normal edges', () => { | ||
var pGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/partial.json'))) | ||
var edges = rewrite.linkToEdges(pGraph, {v: 'c', w: 'a', value: {outPort: 'const1/output', inPort: 'value'}}) | ||
expect(edges).to.have.length(1) | ||
}) | ||
/* | ||
it('`linkToEdges` does check the validity of the input link', () => { | ||
var pGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/partial.json'))) | ||
expect(() => rewrite.linkToEdges(pGraph, {v: 'c', w: 'a', value: {outPort: '', inPort: ''}})) | ||
.to.throw(Error) | ||
})*/ | ||
it('`linkToEdges` does add edges for every hierarchy level', () => { | ||
var hGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/hierarchy.json'))) | ||
var edges = rewrite.linkToEdges(hGraph, {v: 'a:b:c', w: 'd:e:f', value: {outPort: 'out', inPort: 'in'}}) | ||
expect(edges).to.have.length(5) | ||
}) | ||
it('`linkToPorts` does add ports for every node in the hierarchy levels', () => { | ||
var hGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/hierarchy.json'))) | ||
var edges = rewrite.linkToPorts(hGraph, {v: 'a:b:c', w: 'd:e:f', value: {outPort: 'out', inPort: 'in'}}) | ||
expect(edges).to.have.length(4) | ||
}) | ||
it('`linkToPorts` does add no ports for an edge', () => { | ||
var pGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/partial.json'))) | ||
var edges = rewrite.linkToPorts(pGraph, {v: 'c', w: 'a', value: {outPort: 'const1/output', inPort: 'value'}}) | ||
expect(edges).to.have.length(0) | ||
}) | ||
}) |
60242
26
1471
5