feat: Phase 1 — extract the client (web SPA + desktop) to dtoro/oikos-web
Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
This commit is contained in:
21
web/node_modules/graphology/LICENSE.txt
generated
vendored
Normal file
21
web/node_modules/graphology/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2021 Guillaume Plique (Yomguithereal)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
9
web/node_modules/graphology/README.md
generated
vendored
Normal file
9
web/node_modules/graphology/README.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Graphology
|
||||
|
||||
`graphology` is a specification for a robust & multipurpose JavaScript `Graph` object and aiming at supporting various kinds of graphs under a same unified interface.
|
||||
|
||||
You will also find here the source for the reference implementation of this specification.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation for the library/specs is available [here](https://graphology.github.io).
|
||||
5017
web/node_modules/graphology/dist/graphology.cjs.js
generated
vendored
Normal file
5017
web/node_modules/graphology/dist/graphology.cjs.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
web/node_modules/graphology/dist/graphology.cjs.js.map
generated
vendored
Normal file
1
web/node_modules/graphology/dist/graphology.cjs.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
36
web/node_modules/graphology/dist/graphology.d.ts
generated
vendored
Normal file
36
web/node_modules/graphology/dist/graphology.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import {AbstractGraph, Attributes} from 'graphology-types';
|
||||
|
||||
export default class Graph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends AbstractGraph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
export class DirectedGraph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends Graph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
export class UndirectedGraph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends Graph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
export class MultiGraph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends Graph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
export class MultiDirectedGraph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends Graph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
export class MultiUndirectedGraph<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes,
|
||||
GraphAttributes extends Attributes = Attributes
|
||||
> extends Graph<NodeAttributes, EdgeAttributes, GraphAttributes> {}
|
||||
|
||||
export class InvalidArgumentsGraphError extends Error {}
|
||||
export class NotFoundGraphError extends Error {}
|
||||
export class UsageGraphError extends Error {}
|
||||
6731
web/node_modules/graphology/dist/graphology.esm.js
generated
vendored
Normal file
6731
web/node_modules/graphology/dist/graphology.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
web/node_modules/graphology/dist/graphology.esm.js.map
generated
vendored
Normal file
1
web/node_modules/graphology/dist/graphology.esm.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
6731
web/node_modules/graphology/dist/graphology.mjs
generated
vendored
Normal file
6731
web/node_modules/graphology/dist/graphology.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
web/node_modules/graphology/dist/graphology.mjs.map
generated
vendored
Normal file
1
web/node_modules/graphology/dist/graphology.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5400
web/node_modules/graphology/dist/graphology.umd.js
generated
vendored
Normal file
5400
web/node_modules/graphology/dist/graphology.umd.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
web/node_modules/graphology/dist/graphology.umd.js.map
generated
vendored
Normal file
1
web/node_modules/graphology/dist/graphology.umd.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
web/node_modules/graphology/dist/graphology.umd.min.js
generated
vendored
Normal file
2
web/node_modules/graphology/dist/graphology.umd.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
web/node_modules/graphology/dist/graphology.umd.min.js.map
generated
vendored
Normal file
1
web/node_modules/graphology/dist/graphology.umd.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
90
web/node_modules/graphology/package.json
generated
vendored
Normal file
90
web/node_modules/graphology/package.json
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"name": "graphology",
|
||||
"version": "0.26.0",
|
||||
"description": "A robust and multipurpose Graph object for JavaScript.",
|
||||
"main": "dist/graphology.cjs.js",
|
||||
"module": "dist/graphology.esm.js",
|
||||
"browser": "dist/graphology.umd.min.js",
|
||||
"types": "dist/graphology.d.ts",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist specs",
|
||||
"build": "npm run clean && rollup -c && babel tests --out-dir specs && cp src/endpoint.esm.d.ts dist/graphology.d.ts",
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "npm test && npm run test:types && npm run build",
|
||||
"test": "mocha -u exports --require @babel/register ./test.js",
|
||||
"test:types": "tsc --lib es2015,dom --noEmit --noImplicitAny --noImplicitReturns --strictNullChecks ./test-types.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist/*.js",
|
||||
"dist/*.mjs",
|
||||
"dist/*.ts",
|
||||
"dist/*.map",
|
||||
"specs"
|
||||
],
|
||||
"keywords": [
|
||||
"graph",
|
||||
"graph theory",
|
||||
"directed",
|
||||
"undirected",
|
||||
"network"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/graphology/graphology.git"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Alexis Jacomy",
|
||||
"url": "http://github.com/jacomyal"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Ooghe-Tabanou",
|
||||
"url": "http://github.com/boogheta"
|
||||
},
|
||||
{
|
||||
"name": "Guillaume Plique",
|
||||
"url": "http://github.com/Yomguithereal"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/graphology/graphology/issues"
|
||||
},
|
||||
"homepage": "https://github.com/graphology/graphology#readme",
|
||||
"dependencies": {
|
||||
"events": "^3.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"graphology-types": ">=0.24.0"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"@babel/preset-env"
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
"@babel/transform-classes",
|
||||
{
|
||||
"loose": true
|
||||
}
|
||||
],
|
||||
[
|
||||
"@babel/transform-destructuring",
|
||||
{
|
||||
"loose": true
|
||||
}
|
||||
],
|
||||
[
|
||||
"@babel/transform-spread",
|
||||
{
|
||||
"loose": true
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"exports": {
|
||||
"require": "./dist/graphology.cjs.js",
|
||||
"import": "./dist/graphology.mjs",
|
||||
"types": "./dist/graphology.d.ts"
|
||||
}
|
||||
}
|
||||
873
web/node_modules/graphology/specs/attributes.js
generated
vendored
Normal file
873
web/node_modules/graphology/specs/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,873 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = attributes;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
||||
* Graphology Attributes Specs
|
||||
* ============================
|
||||
*
|
||||
* Testing the attributes-related methods of the graph.
|
||||
*/
|
||||
function attributes(Graph, checkers) {
|
||||
var invalid = checkers.invalid,
|
||||
notFound = checkers.notFound,
|
||||
usage = checkers.usage;
|
||||
function commonTests(method) {
|
||||
return _defineProperty({}, '#.' + method, {
|
||||
'it should throw if the given path is not found.': function it_should_throw_if_the_given_path_is_not_found() {
|
||||
if (!method.includes('Edge')) return;
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[method]('source', 'target', 'name', 'value');
|
||||
}, notFound());
|
||||
},
|
||||
'it should throw when using a path on a multi graph.': function it_should_throw_when_using_a_path_on_a_multi_graph() {
|
||||
if (!method.includes('Edge')) return;
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[method]('source', 'target', 'name', 'value');
|
||||
}, usage());
|
||||
},
|
||||
'it should throw if the element is not found in the graph.': function it_should_throw_if_the_element_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
if (method.includes('Edge') && method.includes('Directed') || method.includes('Undirected')) {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[method]('Test');
|
||||
}, usage());
|
||||
} else {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[method]('Test');
|
||||
}, notFound());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
var tests = {};
|
||||
var relevantMethods = Object.keys(Graph.prototype).filter(function (name) {
|
||||
return (name.includes('NodeAttribute') || name.includes('EdgeAttribute') || name.includes('SourceAttribute') || name.includes('TargetAttribute') || name.includes('OppositeAttribute')) && !name.includes('Each');
|
||||
});
|
||||
relevantMethods.forEach(function (method) {
|
||||
return (0, _helpers.deepMerge)(tests, commonTests(method));
|
||||
});
|
||||
return (0, _helpers.deepMerge)(tests, {
|
||||
'#.getAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'graph');
|
||||
},
|
||||
'it should return undefined if the attribute does not exist.': function it_should_return_undefined_if_the_attribute_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), undefined);
|
||||
}
|
||||
},
|
||||
'#.getNodeAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getNodeAttribute('Martha', 'age'), 34);
|
||||
},
|
||||
'it should return undefined if the attribute does not exist.': function it_should_return_undefined_if_the_attribute_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
_assert["default"].strictEqual(graph.getNodeAttribute('Martha', 'age'), undefined);
|
||||
}
|
||||
},
|
||||
'#.getSourceAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
var _graph$mergeEdge = graph.mergeEdge('Martha', 'Riwan'),
|
||||
edge = _graph$mergeEdge[0];
|
||||
_assert["default"].strictEqual(graph.getSourceAttribute(edge, 'age'), 34);
|
||||
},
|
||||
'it should return undefined if the attribute does not exist.': function it_should_return_undefined_if_the_attribute_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
var _graph$mergeEdge2 = graph.mergeEdge('Martha', 'Riwan'),
|
||||
edge = _graph$mergeEdge2[0];
|
||||
_assert["default"].strictEqual(graph.getSourceAttribute(edge, 'age'), undefined);
|
||||
}
|
||||
},
|
||||
'#.getTargetAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
var _graph$mergeEdge3 = graph.mergeEdge('Riwan', 'Martha'),
|
||||
edge = _graph$mergeEdge3[0];
|
||||
_assert["default"].strictEqual(graph.getTargetAttribute(edge, 'age'), 34);
|
||||
},
|
||||
'it should return undefined if the attribute does not exist.': function it_should_return_undefined_if_the_attribute_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
var _graph$mergeEdge4 = graph.mergeEdge('Riwan', 'Martha'),
|
||||
edge = _graph$mergeEdge4[0];
|
||||
_assert["default"].strictEqual(graph.getTargetAttribute(edge, 'age'), undefined);
|
||||
}
|
||||
},
|
||||
'#.getOppositeAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Riwan', {
|
||||
age: 25
|
||||
});
|
||||
var _graph$mergeEdge5 = graph.mergeEdge('Riwan', 'Martha'),
|
||||
edge = _graph$mergeEdge5[0];
|
||||
_assert["default"].strictEqual(graph.getOppositeAttribute('Riwan', edge, 'age'), 34);
|
||||
_assert["default"].strictEqual(graph.getOppositeAttribute('Martha', edge, 'age'), 25);
|
||||
}
|
||||
},
|
||||
'#.getEdgeAttribute': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
var edge = graph.addEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 2);
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute('John', 'Thomas', 'weight'), 2);
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getDirectedEdgeAttribute('John', 'Thomas', 'weight'), 2);
|
||||
_assert["default"].strictEqual(graph.getUndirectedEdgeAttribute('John', 'Thomas', 'weight'), 3);
|
||||
},
|
||||
'it should return undefined if the attribute does not exist.': function it_should_return_undefined_if_the_attribute_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
var edge = graph.addEdge('John', 'Thomas');
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), undefined);
|
||||
}
|
||||
},
|
||||
'#.getAttributes': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {
|
||||
name: 'graph'
|
||||
});
|
||||
},
|
||||
'it should return an empty object if the node does not have attributes.': function it_should_return_an_empty_object_if_the_node_does_not_have_attributes() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {});
|
||||
}
|
||||
},
|
||||
'#.getNodeAttributes': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('Martha'), {
|
||||
age: 34
|
||||
});
|
||||
},
|
||||
'it should return an empty object if the node does not have attributes.': function it_should_return_an_empty_object_if_the_node_does_not_have_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('Martha'), {});
|
||||
}
|
||||
},
|
||||
'#.getEdgeAttributes': {
|
||||
'it should return the correct value.': function it_should_return_the_correct_value() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
var edge = graph.addEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 2
|
||||
});
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getDirectedEdgeAttributes('John', 'Thomas', 'weight'), {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getUndirectedEdgeAttributes('John', 'Thomas', 'weight'), {
|
||||
weight: 3
|
||||
});
|
||||
},
|
||||
'it should return an empty object if the edge does not have attributes.': function it_should_return_an_empty_object_if_the_edge_does_not_have_attributes() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
var edge = graph.addEdge('John', 'Thomas');
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {});
|
||||
}
|
||||
},
|
||||
'#.hasAttribute': {
|
||||
'it should correctly return whether the attribute is set.': function it_should_correctly_return_whether_the_attribute_is_set() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
_assert["default"].strictEqual(graph.hasAttribute('name'), true);
|
||||
_assert["default"].strictEqual(graph.hasAttribute('info'), false);
|
||||
},
|
||||
'it does not fail with typical prototypal properties.': function it_does_not_fail_with_typical_prototypal_properties() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.hasAttribute('toString'), false);
|
||||
}
|
||||
},
|
||||
'#.hasNodeAttribute': {
|
||||
'it should correctly return whether the attribute is set.': function it_should_correctly_return_whether_the_attribute_is_set() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 20
|
||||
});
|
||||
_assert["default"].strictEqual(graph.hasNodeAttribute('John', 'age'), true);
|
||||
_assert["default"].strictEqual(graph.hasNodeAttribute('John', 'eyes'), false);
|
||||
},
|
||||
'it does not fail with typical prototypal properties.': function it_does_not_fail_with_typical_prototypal_properties() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 20
|
||||
});
|
||||
_assert["default"].strictEqual(graph.hasNodeAttribute('John', 'toString'), false);
|
||||
}
|
||||
},
|
||||
'#.hasEdgeAttribute': {
|
||||
'it should correctly return whether the attribute is set.': function it_should_correctly_return_whether_the_attribute_is_set() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdgeWithKey('J->M', 'John', 'Martha', {
|
||||
weight: 10
|
||||
});
|
||||
_assert["default"].strictEqual(graph.hasEdgeAttribute('J->M', 'weight'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdgeAttribute('J->M', 'type'), false);
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdgeAttribute('John', 'Thomas', 'weight'), true);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdgeAttribute('John', 'Thomas', 'weight'), false);
|
||||
},
|
||||
'it does not fail with typical prototypal properties.': function it_does_not_fail_with_typical_prototypal_properties() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdgeWithKey('J->M', 'John', 'Martha', {
|
||||
weight: 10
|
||||
});
|
||||
_assert["default"].strictEqual(graph.hasEdgeAttribute('J->M', 'toString'), false);
|
||||
}
|
||||
},
|
||||
'#.setAttribute': {
|
||||
"it should correctly set the graph's attribute.": function it_should_correctly_set_the_graphS_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'graph');
|
||||
}
|
||||
},
|
||||
'#.setNodeAttribute': {
|
||||
"it should correctly set the node's attribute.": function it_should_correctly_set_the_nodeS_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 20
|
||||
});
|
||||
graph.setNodeAttribute('John', 'age', 45);
|
||||
_assert["default"].strictEqual(graph.getNodeAttribute('John', 'age'), 45);
|
||||
}
|
||||
},
|
||||
'#.setEdgeAttribute': {
|
||||
"it should correctly set the edge's attribute.": function it_should_correctly_set_the_edgeS_attribute() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha', {
|
||||
weight: 3
|
||||
});
|
||||
graph.setEdgeAttribute(edge, 'weight', 40);
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 40);
|
||||
graph.setEdgeAttribute('John', 'Martha', 'weight', 60);
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 60);
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 0
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
weight: 0
|
||||
});
|
||||
graph.setDirectedEdgeAttribute('John', 'Thomas', 'weight', 2);
|
||||
graph.setUndirectedEdgeAttribute('John', 'Thomas', 'weight', 3);
|
||||
_assert["default"].strictEqual(graph.getDirectedEdgeAttribute('John', 'Thomas', 'weight'), 2);
|
||||
_assert["default"].strictEqual(graph.getUndirectedEdgeAttribute('John', 'Thomas', 'weight'), 3);
|
||||
}
|
||||
},
|
||||
'#.updateAttribute': {
|
||||
'it should throw if the updater is not a function.': function it_should_throw_if_the_updater_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('count', 0);
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateAttribute('count', {
|
||||
hello: 'world'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
"it should correctly set the graph's attribute.": function it_should_correctly_set_the_graphS_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
graph.updateAttribute('name', function (name) {
|
||||
return name + '1';
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'graph1');
|
||||
},
|
||||
'the given value should be undefined if not found.': function the_given_value_should_be_undefined_if_not_found() {
|
||||
var graph = new Graph();
|
||||
var updater = function updater(x) {
|
||||
_assert["default"].strictEqual(x, undefined);
|
||||
return 'graph';
|
||||
};
|
||||
graph.updateAttribute('name', updater);
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'graph');
|
||||
}
|
||||
},
|
||||
'#.updateNodeAttribute': {
|
||||
'it should throw if given an invalid updater.': function it_should_throw_if_given_an_invalid_updater() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 20
|
||||
});
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateNodeAttribute('John', 'age', {
|
||||
hello: 'world'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
'it should throw if not enough arguments are provided.': function it_should_throw_if_not_enough_arguments_are_provided() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Lucy');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateNodeAttribute('Lucy', {
|
||||
hello: 'world'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
"it should correctly set the node's attribute.": function it_should_correctly_set_the_nodeS_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 20
|
||||
});
|
||||
graph.updateNodeAttribute('John', 'age', function (x) {
|
||||
return x + 1;
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getNodeAttribute('John', 'age'), 21);
|
||||
},
|
||||
'the given value should be undefined if not found.': function the_given_value_should_be_undefined_if_not_found() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
var updater = function updater(x) {
|
||||
_assert["default"].strictEqual(x, undefined);
|
||||
return 10;
|
||||
};
|
||||
graph.updateNodeAttribute('John', 'age', updater);
|
||||
_assert["default"].strictEqual(graph.getNodeAttribute('John', 'age'), 10);
|
||||
}
|
||||
},
|
||||
'#.updateEdgeAttribute': {
|
||||
'it should throw if given an invalid updater.': function it_should_throw_if_given_an_invalid_updater() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdge('John', 'Martha', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEdgeAttribute('John', 'Martha', 'weight', {
|
||||
hello: 'world'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
"it should correctly set the edge's attribute.": function it_should_correctly_set_the_edgeS_attribute() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha', {
|
||||
weight: 3
|
||||
});
|
||||
graph.updateEdgeAttribute(edge, 'weight', function (x) {
|
||||
return x + 1;
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 4);
|
||||
graph.updateEdgeAttribute('John', 'Martha', 'weight', function (x) {
|
||||
return x + 2;
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 6);
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 0
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
weight: 0
|
||||
});
|
||||
graph.updateDirectedEdgeAttribute('John', 'Thomas', 'weight', function (x) {
|
||||
return x + 2;
|
||||
});
|
||||
graph.updateUndirectedEdgeAttribute('John', 'Thomas', 'weight', function (x) {
|
||||
return x + 3;
|
||||
});
|
||||
_assert["default"].strictEqual(graph.getDirectedEdgeAttribute('John', 'Thomas', 'weight'), 2);
|
||||
_assert["default"].strictEqual(graph.getUndirectedEdgeAttribute('John', 'Thomas', 'weight'), 3);
|
||||
},
|
||||
'the given value should be undefined if not found.': function the_given_value_should_be_undefined_if_not_found() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha');
|
||||
var updater = function updater(x) {
|
||||
_assert["default"].strictEqual(x, undefined);
|
||||
return 10;
|
||||
};
|
||||
graph.updateEdgeAttribute(edge, 'weight', updater);
|
||||
_assert["default"].strictEqual(graph.getEdgeAttribute(edge, 'weight'), 10);
|
||||
}
|
||||
},
|
||||
'#.removeAttribute': {
|
||||
'it should correctly remove the attribute.': function it_should_correctly_remove_the_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
graph.removeAttribute('name');
|
||||
_assert["default"].strictEqual(graph.hasAttribute('name'), false);
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {});
|
||||
}
|
||||
},
|
||||
'#.removeNodeAttribute': {
|
||||
'it should correctly remove the attribute.': function it_should_correctly_remove_the_attribute() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha', {
|
||||
age: 34
|
||||
});
|
||||
graph.removeNodeAttribute('Martha', 'age');
|
||||
_assert["default"].strictEqual(graph.hasNodeAttribute('Martha', 'age'), false);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('Martha'), {});
|
||||
}
|
||||
},
|
||||
'#.removeEdgeAttribute': {
|
||||
'it should correclty remove the attribute.': function it_should_correclty_remove_the_attribute() {
|
||||
var graph = new Graph();
|
||||
var _graph$mergeEdge6 = graph.mergeEdge('John', 'Martha', {
|
||||
weight: 1,
|
||||
size: 3
|
||||
}),
|
||||
edge = _graph$mergeEdge6[0];
|
||||
graph.removeEdgeAttribute('John', 'Martha', 'weight');
|
||||
graph.removeEdgeAttribute(edge, 'size');
|
||||
_assert["default"].strictEqual(graph.hasEdgeAttribute(edge, 'weight'), false);
|
||||
_assert["default"].strictEqual(graph.hasEdgeAttribute(edge, 'size'), false);
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {});
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
weight: 3
|
||||
});
|
||||
graph.removeDirectedEdgeAttribute('John', 'Thomas', 'weight');
|
||||
graph.removeUndirectedEdgeAttribute('John', 'Thomas', 'weight');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdgeAttribute('John', 'Thomas', 'weight'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdgeAttribute('John', 'Thomas', 'weight'), false);
|
||||
}
|
||||
},
|
||||
'#.replaceAttribute': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.replaceAttributes(true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly replace attributes.': function it_should_correctly_replace_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
graph.replaceAttributes({
|
||||
name: 'other graph'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {
|
||||
name: 'other graph'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.replaceNodeAttributes': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.replaceNodeAttributes('John', true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly replace attributes.': function it_should_correctly_replace_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 45
|
||||
});
|
||||
graph.replaceNodeAttributes('John', {
|
||||
age: 23,
|
||||
eyes: 'blue'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
age: 23,
|
||||
eyes: 'blue'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.replaceEdgeAttributes': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.replaceEdgeAttributes(edge, true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.replaceDirectedEdgeAttributes('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.replaceUndirectedEdgeAttributes('John', 'Thomas', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getDirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getUndirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 3
|
||||
});
|
||||
},
|
||||
'it should correctly replace attributes.': function it_should_correctly_replace_attributes() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha', {
|
||||
weight: 1
|
||||
});
|
||||
graph.replaceEdgeAttributes(edge, {
|
||||
weight: 4,
|
||||
type: 'KNOWS'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {
|
||||
weight: 4,
|
||||
type: 'KNOWS'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.mergeAttributes': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.mergeAttributes(true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly merge attributes.': function it_should_correctly_merge_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
graph.mergeAttributes({
|
||||
color: 'blue'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {
|
||||
name: 'graph',
|
||||
color: 'blue'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.mergeNodeAttributes': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.mergeNodeAttributes('John', true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly merge attributes.': function it_should_correctly_merge_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 45
|
||||
});
|
||||
graph.mergeNodeAttributes('John', {
|
||||
eyes: 'blue'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
age: 45,
|
||||
eyes: 'blue'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.mergeEdgeAttributes': {
|
||||
'it should throw if given attributes are not a plain object.': function it_should_throw_if_given_attributes_are_not_a_plain_object() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.mergeEdgeAttributes(edge, true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.mergeDirectedEdgeAttributes('John', 'Thomas', {
|
||||
weight: 2
|
||||
});
|
||||
graph.mergeUndirectedEdgeAttributes('John', 'Thomas', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getDirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 2,
|
||||
test: 0
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getUndirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 3,
|
||||
test: 0
|
||||
});
|
||||
},
|
||||
'it should correctly merge attributes.': function it_should_correctly_merge_attributes() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha', {
|
||||
weight: 1
|
||||
});
|
||||
graph.mergeEdgeAttributes(edge, {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {
|
||||
weight: 1,
|
||||
type: 'KNOWS'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.updateAttributes': {
|
||||
'it should throw if given updater is not a function.': function it_should_throw_if_given_updater_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateAttribute(true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly update attributes.': function it_should_correctly_update_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('name', 'graph');
|
||||
graph.updateAttributes(function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
color: 'blue'
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {
|
||||
name: 'graph',
|
||||
color: 'blue'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.updateNodeAttributes': {
|
||||
'it should throw if given updater is not a function': function it_should_throw_if_given_updater_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateNodeAttributes('John', true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly update attributes.': function it_should_correctly_update_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 45
|
||||
});
|
||||
graph.updateNodeAttributes('John', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
eyes: 'blue'
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
age: 45,
|
||||
eyes: 'blue'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.updateEdgeAttributes': {
|
||||
'it should throw if given updater is not a function.': function it_should_throw_if_given_updater_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEdgeAttributes(edge, true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should also work with typed edges.': function it_should_also_work_with_typed_edges() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addDirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.addUndirectedEdge('John', 'Thomas', {
|
||||
test: 0
|
||||
});
|
||||
graph.updateDirectedEdgeAttributes('John', 'Thomas', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: 2
|
||||
});
|
||||
});
|
||||
graph.updateUndirectedEdgeAttributes('John', 'Thomas', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: 3
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getDirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 2,
|
||||
test: 0
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getUndirectedEdgeAttributes('John', 'Thomas'), {
|
||||
weight: 3,
|
||||
test: 0
|
||||
});
|
||||
},
|
||||
'it should correctly update attributes.': function it_should_correctly_update_attributes() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
var edge = graph.addEdge('John', 'Martha', {
|
||||
weight: 1
|
||||
});
|
||||
graph.updateEdgeAttributes(edge, function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(edge), {
|
||||
weight: 1,
|
||||
type: 'KNOWS'
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.updateEachNodeAttributes': {
|
||||
'it should throw when given invalid arguments.': function it_should_throw_when_given_invalid_arguments() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachNodeAttributes(null);
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachNodeAttributes(Function.prototype, 'test');
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachNodeAttributes(Function.prototype, {
|
||||
attributes: 'yes'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
"it should update each node's attributes.": function it_should_update_each_nodeS_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Mary', {
|
||||
age: 56
|
||||
});
|
||||
graph.addNode('Suz', {
|
||||
age: 13
|
||||
});
|
||||
graph.updateEachNodeAttributes(function (node, attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
age: attr.age + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.nodes().map(function (n) {
|
||||
return graph.getNodeAttributes(n);
|
||||
}), [{
|
||||
age: 35
|
||||
}, {
|
||||
age: 57
|
||||
}, {
|
||||
age: 14
|
||||
}]);
|
||||
}
|
||||
},
|
||||
'#.updateEachEdgeAttributes': {
|
||||
'it should throw when given invalid arguments.': function it_should_throw_when_given_invalid_arguments() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachEdgeAttributes(null);
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachEdgeAttributes(Function.prototype, 'test');
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEachEdgeAttributes(Function.prototype, {
|
||||
attributes: 'yes'
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
"it should update each node's attributes.": function it_should_update_each_nodeS_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdgeWithKey(0, 'John', 'Lucy', {
|
||||
weight: 1
|
||||
});
|
||||
graph.mergeEdgeWithKey(1, 'John', 'Mary', {
|
||||
weight: 10
|
||||
});
|
||||
graph.updateEachEdgeAttributes(function (edge, attr, source, _t, _sa, _ta, undirected) {
|
||||
_assert["default"].strictEqual(source, 'John');
|
||||
_assert["default"].strictEqual(undirected, false);
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: attr.weight + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.mapEdges(function (_, attr) {
|
||||
return attr;
|
||||
}), [{
|
||||
weight: 2
|
||||
}, {
|
||||
weight: 11
|
||||
}]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
393
web/node_modules/graphology/specs/events.js
generated
vendored
Normal file
393
web/node_modules/graphology/specs/events.js
generated
vendored
Normal file
@@ -0,0 +1,393 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = events;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
||||
* Graphology Events Specs
|
||||
* ========================
|
||||
*
|
||||
* Testing the graph's events.
|
||||
*/
|
||||
var VALID_TYPES = new Set(['set', 'merge', 'replace', 'remove']);
|
||||
function events(Graph) {
|
||||
return {
|
||||
nodeAdded: {
|
||||
'it should fire when a node is added.': function it_should_fire_when_a_node_is_added() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (data) {
|
||||
_assert["default"].strictEqual(data.key, 'John');
|
||||
_assert["default"].deepStrictEqual(data.attributes, {
|
||||
age: 34
|
||||
});
|
||||
});
|
||||
graph.on('nodeAdded', handler);
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
(0, _assert["default"])(handler.called);
|
||||
}
|
||||
},
|
||||
edgeAdded: {
|
||||
'it should fire when an edge is added.': function it_should_fire_when_an_edge_is_added() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (data) {
|
||||
_assert["default"].strictEqual(data.key, 'J->T');
|
||||
_assert["default"].deepStrictEqual(data.attributes, {
|
||||
weight: 1
|
||||
});
|
||||
_assert["default"].strictEqual(data.source, 'John');
|
||||
_assert["default"].strictEqual(data.target, 'Thomas');
|
||||
_assert["default"].strictEqual(data.undirected, false);
|
||||
});
|
||||
graph.on('edgeAdded', handler);
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdgeWithKey('J->T', 'John', 'Thomas', {
|
||||
weight: 1
|
||||
});
|
||||
(0, _assert["default"])(handler.called);
|
||||
}
|
||||
},
|
||||
nodeDropped: {
|
||||
'it should fire when a node is dropped.': function it_should_fire_when_a_node_is_dropped() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (data) {
|
||||
_assert["default"].strictEqual(data.key, 'John');
|
||||
_assert["default"].deepStrictEqual(data.attributes, {
|
||||
age: 34
|
||||
});
|
||||
});
|
||||
graph.on('nodeDropped', handler);
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.dropNode('John');
|
||||
(0, _assert["default"])(handler.called);
|
||||
}
|
||||
},
|
||||
edgeDropped: {
|
||||
'it should fire when an edge is added.': function it_should_fire_when_an_edge_is_added() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (data) {
|
||||
_assert["default"].strictEqual(data.key, 'J->T');
|
||||
_assert["default"].deepStrictEqual(data.attributes, {
|
||||
weight: 1
|
||||
});
|
||||
_assert["default"].strictEqual(data.source, 'John');
|
||||
_assert["default"].strictEqual(data.target, 'Thomas');
|
||||
_assert["default"].strictEqual(data.undirected, false);
|
||||
});
|
||||
graph.on('edgeDropped', handler);
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdgeWithKey('J->T', 'John', 'Thomas', {
|
||||
weight: 1
|
||||
});
|
||||
graph.dropEdge('J->T');
|
||||
(0, _assert["default"])(handler.called);
|
||||
}
|
||||
},
|
||||
cleared: {
|
||||
'it should fire when the graph is cleared.': function it_should_fire_when_the_graph_is_cleared() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)();
|
||||
graph.on('cleared', handler);
|
||||
graph.clear();
|
||||
(0, _assert["default"])(handler.called);
|
||||
}
|
||||
},
|
||||
attributesUpdated: {
|
||||
'it should fire when a graph attribute is updated.': function it_should_fire_when_a_graph_attribute_is_updated() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
(0, _assert["default"])(VALID_TYPES.has(payload.type));
|
||||
if (payload.type === 'set') {
|
||||
_assert["default"].strictEqual(payload.name, 'name');
|
||||
} else if (payload.type === 'remove') {
|
||||
_assert["default"].strictEqual(payload.name, 'name');
|
||||
} else if (payload.type === 'merge') {
|
||||
_assert["default"].deepStrictEqual(payload.data, {
|
||||
author: 'John'
|
||||
});
|
||||
}
|
||||
_assert["default"].deepStrictEqual(payload.attributes, graph.getAttributes());
|
||||
});
|
||||
graph.on('attributesUpdated', handler);
|
||||
graph.setAttribute('name', 'Awesome graph');
|
||||
graph.replaceAttributes({
|
||||
name: 'Shitty graph'
|
||||
});
|
||||
graph.mergeAttributes({
|
||||
author: 'John'
|
||||
});
|
||||
graph.removeAttribute('name');
|
||||
_assert["default"].strictEqual(handler.times, 4);
|
||||
}
|
||||
},
|
||||
nodeAttributesUpdated: {
|
||||
"it should fire when a node's attributes are updated.": function it_should_fire_when_a_nodeS_attributes_are_updated() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].strictEqual(payload.key, 'John');
|
||||
(0, _assert["default"])(VALID_TYPES.has(payload.type));
|
||||
if (payload.type === 'set') {
|
||||
_assert["default"].strictEqual(payload.name, 'age');
|
||||
} else if (payload.type === 'remove') {
|
||||
_assert["default"].strictEqual(payload.name, 'eyes');
|
||||
} else if (payload.type === 'merge') {
|
||||
_assert["default"].deepStrictEqual(payload.data, {
|
||||
eyes: 'blue'
|
||||
});
|
||||
}
|
||||
_assert["default"].strictEqual(payload.attributes, graph.getNodeAttributes(payload.key));
|
||||
});
|
||||
graph.on('nodeAttributesUpdated', handler);
|
||||
graph.addNode('John');
|
||||
graph.setNodeAttribute('John', 'age', 34);
|
||||
graph.replaceNodeAttributes('John', {
|
||||
age: 56
|
||||
});
|
||||
graph.mergeNodeAttributes('John', {
|
||||
eyes: 'blue'
|
||||
});
|
||||
graph.removeNodeAttribute('John', 'eyes');
|
||||
_assert["default"].strictEqual(handler.times, 4);
|
||||
},
|
||||
'it should fire when a node is merged.': function it_should_fire_when_a_node_is_merged() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload, {
|
||||
type: 'merge',
|
||||
key: 'John',
|
||||
attributes: {
|
||||
count: 2
|
||||
},
|
||||
data: {
|
||||
count: 2
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(payload.key), {
|
||||
count: 2
|
||||
});
|
||||
});
|
||||
graph.on('nodeAttributesUpdated', handler);
|
||||
graph.mergeNode('John', {
|
||||
count: 1
|
||||
});
|
||||
graph.mergeNode('John', {
|
||||
count: 2
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
},
|
||||
'it should fire when a node is updated.': function it_should_fire_when_a_node_is_updated() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload, {
|
||||
type: 'replace',
|
||||
key: 'John',
|
||||
attributes: {
|
||||
count: 2
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(payload.key), {
|
||||
count: 2
|
||||
});
|
||||
});
|
||||
graph.on('nodeAttributesUpdated', handler);
|
||||
graph.mergeNode('John', {
|
||||
count: 1
|
||||
});
|
||||
graph.updateNode('John', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
count: attr.count + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
}
|
||||
},
|
||||
edgeAttributesUpdated: {
|
||||
"it should fire when an edge's attributes are updated.": function it_should_fire_when_an_edgeS_attributes_are_updated() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].strictEqual(payload.key, 'J->T');
|
||||
(0, _assert["default"])(VALID_TYPES.has(payload.type));
|
||||
if (payload.type === 'set') {
|
||||
_assert["default"].strictEqual(payload.name, 'weight');
|
||||
} else if (payload.type === 'remove') {
|
||||
_assert["default"].strictEqual(payload.name, 'type');
|
||||
} else if (payload.type === 'merge') {
|
||||
_assert["default"].deepStrictEqual(payload.data, {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
}
|
||||
_assert["default"].strictEqual(payload.attributes, graph.getEdgeAttributes(payload.key));
|
||||
});
|
||||
graph.on('edgeAttributesUpdated', handler);
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdgeWithKey('J->T', 'John', 'Thomas');
|
||||
graph.setEdgeAttribute('J->T', 'weight', 34);
|
||||
graph.replaceEdgeAttributes('J->T', {
|
||||
weight: 56
|
||||
});
|
||||
graph.mergeEdgeAttributes('J->T', {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
graph.removeEdgeAttribute('J->T', 'type');
|
||||
_assert["default"].strictEqual(handler.times, 4);
|
||||
},
|
||||
'it should fire when an edge is merged.': function it_should_fire_when_an_edge_is_merged() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload, {
|
||||
type: 'merge',
|
||||
key: graph.edge('John', 'Mary'),
|
||||
attributes: {
|
||||
weight: 2
|
||||
},
|
||||
data: {
|
||||
weight: 2
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(payload.key), {
|
||||
weight: 2
|
||||
});
|
||||
});
|
||||
graph.on('edgeAttributesUpdated', handler);
|
||||
graph.mergeEdge('John', 'Mary', {
|
||||
weight: 1
|
||||
});
|
||||
graph.mergeEdge('John', 'Mary', {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
},
|
||||
'it should fire when an edge is updated.': function it_should_fire_when_an_edge_is_updated() {
|
||||
var graph = new Graph();
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload, {
|
||||
type: 'replace',
|
||||
key: 'j->m',
|
||||
attributes: {
|
||||
weight: 2
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes(payload.key), {
|
||||
weight: 2
|
||||
});
|
||||
});
|
||||
graph.on('edgeAttributesUpdated', handler);
|
||||
graph.mergeEdgeWithKey('j->m', 'John', 'Mary', {
|
||||
weight: 1
|
||||
});
|
||||
graph.updateEdgeWithKey('j->m', 'John', 'Mary', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: attr.weight + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
}
|
||||
},
|
||||
eachNodeAttributesUpdated: {
|
||||
'it should fire when using #.updateEachNodeAttributes.': function it_should_fire_when_using_UpdateEachNodeAttributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Mary', {
|
||||
age: 56
|
||||
});
|
||||
graph.addNode('Suz', {
|
||||
age: 13
|
||||
});
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].strictEqual(payload.hints, null);
|
||||
});
|
||||
graph.on('eachNodeAttributesUpdated', handler);
|
||||
graph.updateEachNodeAttributes(function (node, attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
age: attr.age + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
},
|
||||
'it should provide hints when user gave them.': function it_should_provide_hints_when_user_gave_them() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Mary', {
|
||||
age: 56
|
||||
});
|
||||
graph.addNode('Suz', {
|
||||
age: 13
|
||||
});
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload.hints, {
|
||||
attributes: ['age']
|
||||
});
|
||||
});
|
||||
graph.on('eachNodeAttributesUpdated', handler);
|
||||
graph.updateEachNodeAttributes(function (node, attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
age: attr.age + 1
|
||||
});
|
||||
}, {
|
||||
attributes: ['age']
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
}
|
||||
},
|
||||
eachEdgeAttributesUpdated: {
|
||||
'it should fire when using #.updateEachEdgeAttributes.': function it_should_fire_when_using_UpdateEachEdgeAttributes() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdgeWithKey(0, 'John', 'Lucy', {
|
||||
weight: 1
|
||||
});
|
||||
graph.mergeEdgeWithKey(1, 'John', 'Mary', {
|
||||
weight: 10
|
||||
});
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].strictEqual(payload.hints, null);
|
||||
});
|
||||
graph.on('eachEdgeAttributesUpdated', handler);
|
||||
graph.updateEachEdgeAttributes(function (node, attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
age: attr.weight + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
},
|
||||
'it should provide hints when user gave them.': function it_should_provide_hints_when_user_gave_them() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdgeWithKey(0, 'John', 'Lucy', {
|
||||
weight: 1
|
||||
});
|
||||
graph.mergeEdgeWithKey(1, 'John', 'Mary', {
|
||||
weight: 10
|
||||
});
|
||||
var handler = (0, _helpers.spy)(function (payload) {
|
||||
_assert["default"].deepStrictEqual(payload.hints, {
|
||||
attributes: ['weight']
|
||||
});
|
||||
});
|
||||
graph.on('eachEdgeAttributesUpdated', handler);
|
||||
graph.updateEachEdgeAttributes(function (node, attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: attr.weight + 1
|
||||
});
|
||||
}, {
|
||||
attributes: ['weight']
|
||||
});
|
||||
_assert["default"].strictEqual(handler.times, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
88
web/node_modules/graphology/specs/helpers.js
generated
vendored
Normal file
88
web/node_modules/graphology/specs/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.addNodesFrom = addNodesFrom;
|
||||
exports.capitalize = capitalize;
|
||||
exports.deepMerge = deepMerge;
|
||||
exports.sameMembers = sameMembers;
|
||||
exports.spy = spy;
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
/**
|
||||
* Graphology Specs Helpers
|
||||
* =========================
|
||||
*
|
||||
* Miscellaneous helpers to test more easily.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Capitalize function.
|
||||
*/
|
||||
function capitalize(string) {
|
||||
return string[0].toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplistic deep merger function.
|
||||
*/
|
||||
function deepMerge() {
|
||||
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
objects[_key] = arguments[_key];
|
||||
}
|
||||
var o = objects[0];
|
||||
var t, i, l, k;
|
||||
for (i = 1, l = objects.length; i < l; i++) {
|
||||
t = objects[i];
|
||||
for (k in t) {
|
||||
if (_typeof(t[k]) === 'object') {
|
||||
o[k] = deepMerge(o[k] || {}, t[k]);
|
||||
} else {
|
||||
o[k] = t[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking that two arrays have the same members.
|
||||
*/
|
||||
function sameMembers(a1, a2) {
|
||||
if (a1.length !== a2.length) return false;
|
||||
var set = new Set(a1);
|
||||
for (var i = 0, l = a2.length; i < l; i++) {
|
||||
if (!set.has(a2[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function spying on the execution of the provided function to ease some
|
||||
* tests, notably related to event handling.
|
||||
*
|
||||
* @param {function} target - Target function.
|
||||
* @param {function} - The spy.
|
||||
*/
|
||||
function spy(target) {
|
||||
var _fn = function fn() {
|
||||
_fn.called = true;
|
||||
_fn.times++;
|
||||
if (typeof target === 'function') return target.apply(null, arguments);
|
||||
};
|
||||
_fn.called = false;
|
||||
_fn.times = 0;
|
||||
return _fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function adding multiple nodes from an array to the given graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @param {array} nodes - Node array.
|
||||
*/
|
||||
function addNodesFrom(graph, nodes) {
|
||||
nodes.forEach(function (node) {
|
||||
graph.addNode(node);
|
||||
});
|
||||
}
|
||||
66
web/node_modules/graphology/specs/index.js
generated
vendored
Normal file
66
web/node_modules/graphology/specs/index.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = specs;
|
||||
var _instantiation = _interopRequireDefault(require("./instantiation"));
|
||||
var _properties = _interopRequireDefault(require("./properties"));
|
||||
var _read = _interopRequireDefault(require("./read"));
|
||||
var _mutation = _interopRequireDefault(require("./mutation"));
|
||||
var _attributes = _interopRequireDefault(require("./attributes"));
|
||||
var _iteration = _interopRequireDefault(require("./iteration"));
|
||||
var _serialization = _interopRequireDefault(require("./serialization"));
|
||||
var _events = _interopRequireDefault(require("./events"));
|
||||
var _utils = _interopRequireDefault(require("./utils"));
|
||||
var _known = _interopRequireDefault(require("./known"));
|
||||
var _misc = _interopRequireDefault(require("./misc"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Specs
|
||||
* =================
|
||||
*
|
||||
* Unit tests factory taking the Graph object implementation.
|
||||
*/
|
||||
|
||||
var createErrorChecker = function createErrorChecker(name) {
|
||||
return function () {
|
||||
return function (error) {
|
||||
return error && error.name === name;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returning the unit tests to run.
|
||||
*
|
||||
* @param {string} path - Path to the implementation (should be absolute).
|
||||
* @return {object} - The tests to run with Mocha.
|
||||
*/
|
||||
function specs(Graph, implementation) {
|
||||
var errors = [['invalid', 'InvalidArgumentsGraphError'], ['notFound', 'NotFoundGraphError'], ['usage', 'UsageGraphError']];
|
||||
|
||||
// Building error checkers
|
||||
var errorCheckers = {};
|
||||
errors.forEach(function (_ref) {
|
||||
var fn = _ref[0],
|
||||
name = _ref[1];
|
||||
return errorCheckers[fn] = createErrorChecker(name);
|
||||
});
|
||||
var tests = {
|
||||
Basic: {
|
||||
Instantiation: (0, _instantiation["default"])(Graph, implementation, errorCheckers),
|
||||
Properties: (0, _properties["default"])(Graph, errorCheckers),
|
||||
Mutation: (0, _mutation["default"])(Graph, errorCheckers),
|
||||
Read: (0, _read["default"])(Graph, errorCheckers),
|
||||
Attributes: (0, _attributes["default"])(Graph, errorCheckers),
|
||||
Iteration: (0, _iteration["default"])(Graph, errorCheckers),
|
||||
Serialization: (0, _serialization["default"])(Graph, errorCheckers),
|
||||
Events: (0, _events["default"])(Graph),
|
||||
Utils: (0, _utils["default"])(Graph, errorCheckers),
|
||||
'Known Methods': (0, _known["default"])(Graph, errorCheckers),
|
||||
Miscellaneous: (0, _misc["default"])(Graph)
|
||||
}
|
||||
};
|
||||
return tests;
|
||||
}
|
||||
187
web/node_modules/graphology/specs/instantiation.js
generated
vendored
Normal file
187
web/node_modules/graphology/specs/instantiation.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = instantiation;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/* eslint no-unused-vars: 0 */
|
||||
/**
|
||||
* Graphology Instantiation Specs
|
||||
* ===============================
|
||||
*
|
||||
* Testing the instantiation of the graph.
|
||||
*/
|
||||
|
||||
var CONSTRUCTORS = ['DirectedGraph', 'UndirectedGraph', 'MultiGraph', 'MultiDirectedGraph', 'MultiUndirectedGraph'];
|
||||
var OPTIONS = [{
|
||||
multi: false,
|
||||
type: 'directed'
|
||||
}, {
|
||||
multi: false,
|
||||
type: 'undirected'
|
||||
}, {
|
||||
multi: true,
|
||||
type: 'mixed'
|
||||
}, {
|
||||
multi: true,
|
||||
type: 'directed'
|
||||
}, {
|
||||
multi: true,
|
||||
type: 'undirected'
|
||||
}];
|
||||
function instantiation(Graph, implementation, checkers) {
|
||||
var invalid = checkers.invalid;
|
||||
return {
|
||||
'Static #.from method': {
|
||||
'it should be possible to create a Graph from a Graph instance.': function it_should_be_possible_to_create_a_Graph_from_a_Graph_instance() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdge('John', 'Thomas');
|
||||
var other = Graph.from(graph);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), other.nodes());
|
||||
_assert["default"].deepStrictEqual(graph.edges(), other.edges());
|
||||
},
|
||||
'it should be possible to create a Graph from a serialized graph': function it_should_be_possible_to_create_a_Graph_from_a_serialized_graph() {
|
||||
var graph = Graph.from({
|
||||
nodes: [{
|
||||
key: 'John'
|
||||
}, {
|
||||
key: 'Thomas'
|
||||
}],
|
||||
edges: [{
|
||||
source: 'John',
|
||||
target: 'Thomas'
|
||||
}]
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John', 'Thomas']);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Thomas'), true);
|
||||
},
|
||||
'it should be possible to provide options.': function it_should_be_possible_to_provide_options() {
|
||||
var graph = Graph.from({
|
||||
node: [{
|
||||
key: 'John'
|
||||
}],
|
||||
attributes: {
|
||||
name: 'Awesome graph'
|
||||
}
|
||||
}, {
|
||||
type: 'directed'
|
||||
});
|
||||
_assert["default"].strictEqual(graph.type, 'directed');
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'Awesome graph');
|
||||
},
|
||||
'it should be possible to take options from the serialized format.': function it_should_be_possible_to_take_options_from_the_serialized_format() {
|
||||
var graph = Graph.from({
|
||||
node: [{
|
||||
key: 'John'
|
||||
}],
|
||||
attributes: {
|
||||
name: 'Awesome graph'
|
||||
},
|
||||
options: {
|
||||
type: 'directed',
|
||||
multi: true
|
||||
}
|
||||
});
|
||||
_assert["default"].strictEqual(graph.type, 'directed');
|
||||
_assert["default"].strictEqual(graph.multi, true);
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'Awesome graph');
|
||||
},
|
||||
'given options should take precedence over the serialization ones.': function given_options_should_take_precedence_over_the_serialization_ones() {
|
||||
var graph = Graph.from({
|
||||
node: [{
|
||||
key: 'John'
|
||||
}],
|
||||
attributes: {
|
||||
name: 'Awesome graph'
|
||||
},
|
||||
options: {
|
||||
type: 'directed',
|
||||
multi: true
|
||||
}
|
||||
}, {
|
||||
type: 'undirected'
|
||||
});
|
||||
_assert["default"].strictEqual(graph.type, 'undirected');
|
||||
_assert["default"].strictEqual(graph.multi, true);
|
||||
_assert["default"].strictEqual(graph.getAttribute('name'), 'Awesome graph');
|
||||
}
|
||||
},
|
||||
Options: {
|
||||
/**
|
||||
* allowSelfLoops
|
||||
*/
|
||||
allowSelfLoops: {
|
||||
'providing a non-boolean value should throw.': function providing_a_nonBoolean_value_should_throw() {
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
allowSelfLoops: 'test'
|
||||
});
|
||||
}, invalid());
|
||||
}
|
||||
},
|
||||
/**
|
||||
* multi
|
||||
*/
|
||||
multi: {
|
||||
'providing a non-boolean value should throw.': function providing_a_nonBoolean_value_should_throw() {
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
multi: 'test'
|
||||
});
|
||||
}, invalid());
|
||||
}
|
||||
},
|
||||
/**
|
||||
* type
|
||||
*/
|
||||
type: {
|
||||
'providing an invalid type should throw.': function providing_an_invalid_type_should_throw() {
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
type: 'test'
|
||||
});
|
||||
}, invalid());
|
||||
}
|
||||
}
|
||||
},
|
||||
Constructors: {
|
||||
'all alternative constructors should be available.': function all_alternative_constructors_should_be_available() {
|
||||
CONSTRUCTORS.forEach(function (name) {
|
||||
return (0, _assert["default"])(name in implementation);
|
||||
});
|
||||
},
|
||||
'alternative constructors should have the correct options.': function alternative_constructors_should_have_the_correct_options() {
|
||||
CONSTRUCTORS.forEach(function (name, index) {
|
||||
var graph = new implementation[name]();
|
||||
var _OPTIONS$index = OPTIONS[index],
|
||||
multi = _OPTIONS$index.multi,
|
||||
type = _OPTIONS$index.type;
|
||||
_assert["default"].strictEqual(graph.multi, multi);
|
||||
_assert["default"].strictEqual(graph.type, type);
|
||||
});
|
||||
},
|
||||
'alternative constructors should throw if given inconsistent options.': function alternative_constructors_should_throw_if_given_inconsistent_options() {
|
||||
CONSTRUCTORS.forEach(function (name, index) {
|
||||
var _OPTIONS$index2 = OPTIONS[index],
|
||||
multi = _OPTIONS$index2.multi,
|
||||
type = _OPTIONS$index2.type;
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new implementation[name]({
|
||||
multi: !multi
|
||||
});
|
||||
}, invalid());
|
||||
if (type === 'mixed') return;
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new implementation[name]({
|
||||
type: type === 'directed' ? 'undirected' : 'directed'
|
||||
});
|
||||
}, invalid());
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
701
web/node_modules/graphology/specs/iteration/edges.js
generated
vendored
Normal file
701
web/node_modules/graphology/specs/iteration/edges.js
generated
vendored
Normal file
@@ -0,0 +1,701 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = edgesIteration;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _utils = require("../../src/utils");
|
||||
var _helpers = require("../helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
||||
* Graphology Edges Iteration Specs
|
||||
* =================================
|
||||
*
|
||||
* Testing the edges iteration-related methods of the graph.
|
||||
*/
|
||||
var METHODS = ['edges', 'inEdges', 'outEdges', 'inboundEdges', 'outboundEdges', 'directedEdges', 'undirectedEdges'];
|
||||
function edgesIteration(Graph, checkers) {
|
||||
var invalid = checkers.invalid,
|
||||
notFound = checkers.notFound;
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas', 'Martha', 'Roger', 'Catherine', 'Alone', 'Forever']);
|
||||
graph.replaceNodeAttributes('John', {
|
||||
age: 13
|
||||
});
|
||||
graph.replaceNodeAttributes('Martha', {
|
||||
age: 15
|
||||
});
|
||||
graph.addDirectedEdgeWithKey('J->T', 'John', 'Thomas', {
|
||||
weight: 14
|
||||
});
|
||||
graph.addDirectedEdgeWithKey('J->M', 'John', 'Martha');
|
||||
graph.addDirectedEdgeWithKey('C->J', 'Catherine', 'John');
|
||||
graph.addUndirectedEdgeWithKey('M<->R', 'Martha', 'Roger');
|
||||
graph.addUndirectedEdgeWithKey('M<->J', 'Martha', 'John');
|
||||
graph.addUndirectedEdgeWithKey('J<->R', 'John', 'Roger');
|
||||
graph.addUndirectedEdgeWithKey('T<->M', 'Thomas', 'Martha');
|
||||
var ALL_EDGES = ['J->T', 'J->M', 'C->J', 'M<->R', 'M<->J', 'J<->R', 'T<->M'];
|
||||
var ALL_DIRECTED_EDGES = ['J->T', 'J->M', 'C->J'];
|
||||
var ALL_UNDIRECTED_EDGES = ['M<->R', 'M<->J', 'J<->R', 'T<->M'];
|
||||
var TEST_DATA = {
|
||||
edges: {
|
||||
all: ALL_EDGES,
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['C->J', 'J->T', 'J->M', 'M<->J', 'J<->R']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['J->M', 'M<->J']
|
||||
}
|
||||
},
|
||||
inEdges: {
|
||||
all: ALL_DIRECTED_EDGES,
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['C->J']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: []
|
||||
}
|
||||
},
|
||||
outEdges: {
|
||||
all: ALL_DIRECTED_EDGES,
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['J->T', 'J->M']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['J->M']
|
||||
}
|
||||
},
|
||||
inboundEdges: {
|
||||
all: ALL_DIRECTED_EDGES.concat(ALL_UNDIRECTED_EDGES),
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['C->J', 'M<->J', 'J<->R']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['M<->J']
|
||||
}
|
||||
},
|
||||
outboundEdges: {
|
||||
all: ALL_DIRECTED_EDGES.concat(ALL_UNDIRECTED_EDGES),
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['J->T', 'J->M', 'M<->J', 'J<->R']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['J->M', 'M<->J']
|
||||
}
|
||||
},
|
||||
directedEdges: {
|
||||
all: ALL_DIRECTED_EDGES,
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['C->J', 'J->T', 'J->M']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['J->M']
|
||||
}
|
||||
},
|
||||
undirectedEdges: {
|
||||
all: ALL_UNDIRECTED_EDGES,
|
||||
node: {
|
||||
key: 'John',
|
||||
edges: ['M<->J', 'J<->R']
|
||||
},
|
||||
path: {
|
||||
source: 'John',
|
||||
target: 'Martha',
|
||||
edges: ['M<->J']
|
||||
}
|
||||
}
|
||||
};
|
||||
function commonTests(name) {
|
||||
return _defineProperty({}, '#.' + name, {
|
||||
'it should throw if too many arguments are provided.': function it_should_throw_if_too_many_arguments_are_provided() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name](1, 2, 3);
|
||||
}, invalid());
|
||||
},
|
||||
'it should throw when the node is not found.': function it_should_throw_when_the_node_is_not_found() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name]('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should throw if either source or target is not found.': function it_should_throw_if_either_source_or_target_is_not_found() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name]('Test', 'Alone');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name]('Alone', 'Test');
|
||||
}, notFound());
|
||||
}
|
||||
});
|
||||
}
|
||||
function specificTests(name, data) {
|
||||
var capitalized = name[0].toUpperCase() + name.slice(1, -1);
|
||||
var iteratorName = name.slice(0, -1) + 'Entries';
|
||||
var forEachName = 'forEach' + capitalized;
|
||||
var findName = 'find' + capitalized;
|
||||
var mapName = 'map' + capitalized + 's';
|
||||
var filterName = 'filter' + capitalized + 's';
|
||||
var reduceName = 'reduce' + capitalized + 's';
|
||||
var someName = 'some' + capitalized;
|
||||
var everyName = 'every' + capitalized;
|
||||
return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, '#.' + name, {
|
||||
'it should return all the relevant edges.': function it_should_return_all_the_relevant_edges() {
|
||||
var edges = graph[name]().sort();
|
||||
_assert["default"].deepStrictEqual(edges, data.all.slice().sort());
|
||||
},
|
||||
"it should return a node's relevant edges.": function it_should_return_a_nodeS_relevant_edges() {
|
||||
var edges = graph[name](data.node.key);
|
||||
_assert["default"].deepStrictEqual(edges, data.node.edges);
|
||||
_assert["default"].deepStrictEqual(graph[name]('Alone'), []);
|
||||
},
|
||||
'it should return all the relevant edges between source & target.': function it_should_return_all_the_relevant_edges_between_source__target() {
|
||||
var edges = graph[name](data.path.source, data.path.target);
|
||||
(0, _assert["default"])((0, _helpers.sameMembers)(edges, data.path.edges));
|
||||
_assert["default"].deepStrictEqual(graph[name]('Forever', 'Alone'), []);
|
||||
}
|
||||
}), '#.' + forEachName, {
|
||||
'it should possible to use callback iterators.': function it_should_possible_to_use_callback_iterators() {
|
||||
var edges = [];
|
||||
graph[forEachName](function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
});
|
||||
edges.sort();
|
||||
_assert["default"].deepStrictEqual(edges, data.all.slice().sort());
|
||||
},
|
||||
"it should be possible to use callback iterators over a node's relevant edges.": function it_should_be_possible_to_use_callback_iterators_over_a_nodeS_relevant_edges() {
|
||||
var edges = [];
|
||||
graph[forEachName](data.node.key, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
});
|
||||
edges.sort();
|
||||
_assert["default"].deepStrictEqual(edges, data.node.edges.slice().sort());
|
||||
},
|
||||
'it should be possible to use callback iterators over all the relevant edges between source & target.': function it_should_be_possible_to_use_callback_iterators_over_all_the_relevant_edges_between_source__target() {
|
||||
var edges = [];
|
||||
graph[forEachName](data.path.source, data.path.target, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
});
|
||||
(0, _assert["default"])((0, _helpers.sameMembers)(edges, data.path.edges));
|
||||
}
|
||||
}), '#.' + mapName, {
|
||||
'it should possible to map edges.': function it_should_possible_to_map_edges() {
|
||||
var result = graph[mapName](function (key) {
|
||||
return key;
|
||||
});
|
||||
result.sort();
|
||||
_assert["default"].deepStrictEqual(result, data.all.slice().sort());
|
||||
},
|
||||
"it should be possible to map a node's relevant edges.": function it_should_be_possible_to_map_a_nodeS_relevant_edges() {
|
||||
var result = graph[mapName](data.node.key, function (key) {
|
||||
return key;
|
||||
});
|
||||
result.sort();
|
||||
_assert["default"].deepStrictEqual(result, data.node.edges.slice().sort());
|
||||
},
|
||||
'it should be possible to map the relevant edges between source & target.': function it_should_be_possible_to_map_the_relevant_edges_between_source__target() {
|
||||
var result = graph[mapName](data.path.source, data.path.target, function (key) {
|
||||
return key;
|
||||
});
|
||||
result.sort();
|
||||
(0, _assert["default"])((0, _helpers.sameMembers)(result, data.path.edges));
|
||||
}
|
||||
}), '#.' + filterName, {
|
||||
'it should possible to filter edges.': function it_should_possible_to_filter_edges() {
|
||||
var result = graph[filterName](function (key) {
|
||||
return data.all.includes(key);
|
||||
});
|
||||
result.sort();
|
||||
_assert["default"].deepStrictEqual(result, data.all.slice().sort());
|
||||
},
|
||||
"it should be possible to filter a node's relevant edges.": function it_should_be_possible_to_filter_a_nodeS_relevant_edges() {
|
||||
var result = graph[filterName](data.node.key, function (key) {
|
||||
return data.all.includes(key);
|
||||
});
|
||||
result.sort();
|
||||
_assert["default"].deepStrictEqual(result, data.node.edges.slice().sort());
|
||||
},
|
||||
'it should be possible to filter the relevant edges between source & target.': function it_should_be_possible_to_filter_the_relevant_edges_between_source__target() {
|
||||
var result = graph[filterName](data.path.source, data.path.target, function (key) {
|
||||
return data.all.includes(key);
|
||||
});
|
||||
result.sort();
|
||||
(0, _assert["default"])((0, _helpers.sameMembers)(result, data.path.edges));
|
||||
}
|
||||
}), '#.' + reduceName, {
|
||||
'it should throw when given bad arguments.': function it_should_throw_when_given_bad_arguments() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[reduceName]('test');
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[reduceName](1, 2, 3, 4, 5);
|
||||
}, invalid());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[reduceName]('notafunction', 0);
|
||||
}, TypeError);
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[reduceName]('test', function () {
|
||||
return true;
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
'it should possible to reduce edges.': function it_should_possible_to_reduce_edges() {
|
||||
var result = graph[reduceName](function (x) {
|
||||
return x + 1;
|
||||
}, 0);
|
||||
_assert["default"].strictEqual(result, data.all.length);
|
||||
},
|
||||
"it should be possible to reduce a node's relevant edges.": function it_should_be_possible_to_reduce_a_nodeS_relevant_edges() {
|
||||
var result = graph[reduceName](data.node.key, function (x) {
|
||||
return x + 1;
|
||||
}, 0);
|
||||
_assert["default"].strictEqual(result, data.node.edges.length);
|
||||
},
|
||||
'it should be possible to reduce the relevant edges between source & target.': function it_should_be_possible_to_reduce_the_relevant_edges_between_source__target() {
|
||||
var result = graph[reduceName](data.path.source, data.path.target, function (x) {
|
||||
return x + 1;
|
||||
}, 0);
|
||||
_assert["default"].strictEqual(result, data.path.edges.length);
|
||||
}
|
||||
}), '#.' + findName, {
|
||||
'it should possible to find an edge.': function it_should_possible_to_find_an_edge() {
|
||||
var edges = [];
|
||||
var found = graph[findName](function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, edges[0]);
|
||||
_assert["default"].strictEqual(edges.length, 1);
|
||||
found = graph[findName](function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, undefined);
|
||||
},
|
||||
"it should be possible to find a node's edge.": function it_should_be_possible_to_find_a_nodeS_edge() {
|
||||
var edges = [];
|
||||
var found = graph[findName](data.node.key, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, edges[0]);
|
||||
_assert["default"].strictEqual(edges.length, 1);
|
||||
found = graph[findName](data.node.key, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, undefined);
|
||||
},
|
||||
'it should be possible to find an edge between source & target.': function it_should_be_possible_to_find_an_edge_between_source__target() {
|
||||
var edges = [];
|
||||
var found = graph[findName](data.path.source, data.path.target, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, edges[0]);
|
||||
_assert["default"].strictEqual(edges.length, graph[name](data.path.source, data.path.target).length ? 1 : 0);
|
||||
found = graph[findName](data.path.source, data.path.target, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, undefined);
|
||||
}
|
||||
}), '#.' + someName, {
|
||||
'it should possible to assert whether any edge matches a predicate.': function it_should_possible_to_assert_whether_any_edge_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[someName](function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, true);
|
||||
_assert["default"].strictEqual(edges.length, 1);
|
||||
found = graph[someName](function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, false);
|
||||
},
|
||||
"it should possible to assert whether any node's edge matches a predicate.": function it_should_possible_to_assert_whether_any_nodeS_edge_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[someName](data.node.key, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, true);
|
||||
_assert["default"].strictEqual(edges.length, 1);
|
||||
found = graph[someName](data.node.key, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, false);
|
||||
},
|
||||
'it should possible to assert whether any edge between source & target matches a predicate.': function it_should_possible_to_assert_whether_any_edge_between_source__target_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[someName](data.path.source, data.path.target, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, graph[name](data.path.source, data.path.target).length !== 0);
|
||||
_assert["default"].strictEqual(edges.length, graph[name](data.path.source, data.path.target).length ? 1 : 0);
|
||||
found = graph[someName](data.path.source, data.path.target, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, false);
|
||||
},
|
||||
'it should always return false on empty sets.': function it_should_always_return_false_on_empty_sets() {
|
||||
var empty = new Graph();
|
||||
_assert["default"].strictEqual(empty[someName](function () {
|
||||
return true;
|
||||
}), false);
|
||||
}
|
||||
}), '#.' + everyName, {
|
||||
'it should possible to assert whether all edges matches a predicate.': function it_should_possible_to_assert_whether_all_edges_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[everyName](function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, true);
|
||||
found = graph[everyName](function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, false);
|
||||
},
|
||||
"it should possible to assert whether all of a node's edges matches a predicate.": function it_should_possible_to_assert_whether_all_of_a_nodeS_edges_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[everyName](data.node.key, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, true);
|
||||
found = graph[everyName](data.node.key, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, false);
|
||||
},
|
||||
'it should possible to assert whether all edges between source & target matches a predicate.': function it_should_possible_to_assert_whether_all_edges_between_source__target_matches_a_predicate() {
|
||||
var edges = [];
|
||||
var found = graph[everyName](data.path.source, data.path.target, function (key, attributes, source, target, sA, tA, u) {
|
||||
edges.push(key);
|
||||
_assert["default"].deepStrictEqual(attributes, key === 'J->T' ? {
|
||||
weight: 14
|
||||
} : {});
|
||||
_assert["default"].strictEqual(source, graph.source(key));
|
||||
_assert["default"].strictEqual(target, graph.target(key));
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(source), sA);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), tA);
|
||||
_assert["default"].strictEqual(graph.isUndirected(key), u);
|
||||
return true;
|
||||
});
|
||||
var isEmpty = graph[name](data.path.source, data.path.target).length === 0;
|
||||
_assert["default"].strictEqual(found, true);
|
||||
found = graph[everyName](data.path.source, data.path.target, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, isEmpty ? true : false);
|
||||
},
|
||||
'it should always return true on empty sets.': function it_should_always_return_true_on_empty_sets() {
|
||||
var empty = new Graph();
|
||||
_assert["default"].strictEqual(empty[everyName](function () {
|
||||
return true;
|
||||
}), true);
|
||||
}
|
||||
}), '#.' + iteratorName, {
|
||||
'it should be possible to return an iterator over the relevant edges.': function it_should_be_possible_to_return_an_iterator_over_the_relevant_edges() {
|
||||
var iterator = graph[iteratorName]();
|
||||
_assert["default"].deepStrictEqual(Array.from(iterator), data.all.map(function (edge) {
|
||||
var _graph$extremities = graph.extremities(edge),
|
||||
source = _graph$extremities[0],
|
||||
target = _graph$extremities[1];
|
||||
return {
|
||||
edge: edge,
|
||||
attributes: graph.getEdgeAttributes(edge),
|
||||
source: source,
|
||||
target: target,
|
||||
sourceAttributes: graph.getNodeAttributes(source),
|
||||
targetAttributes: graph.getNodeAttributes(target),
|
||||
undirected: graph.isUndirected(edge)
|
||||
};
|
||||
}));
|
||||
},
|
||||
"it should be possible to return an iterator over a node's relevant edges.": function it_should_be_possible_to_return_an_iterator_over_a_nodeS_relevant_edges() {
|
||||
var iterator = graph[iteratorName](data.node.key);
|
||||
_assert["default"].deepStrictEqual(Array.from(iterator), data.node.edges.map(function (edge) {
|
||||
var _graph$extremities2 = graph.extremities(edge),
|
||||
source = _graph$extremities2[0],
|
||||
target = _graph$extremities2[1];
|
||||
return {
|
||||
edge: edge,
|
||||
attributes: graph.getEdgeAttributes(edge),
|
||||
source: source,
|
||||
target: target,
|
||||
sourceAttributes: graph.getNodeAttributes(source),
|
||||
targetAttributes: graph.getNodeAttributes(target),
|
||||
undirected: graph.isUndirected(edge)
|
||||
};
|
||||
}));
|
||||
},
|
||||
'it should be possible to return an iterator over relevant edges between source & target.': function it_should_be_possible_to_return_an_iterator_over_relevant_edges_between_source__target() {
|
||||
var iterator = graph[iteratorName](data.path.source, data.path.target);
|
||||
_assert["default"].deepStrictEqual(Array.from(iterator), data.path.edges.map(function (edge) {
|
||||
var _graph$extremities3 = graph.extremities(edge),
|
||||
source = _graph$extremities3[0],
|
||||
target = _graph$extremities3[1];
|
||||
return {
|
||||
edge: edge,
|
||||
attributes: graph.getEdgeAttributes(edge),
|
||||
source: source,
|
||||
target: target,
|
||||
sourceAttributes: graph.getNodeAttributes(source),
|
||||
targetAttributes: graph.getNodeAttributes(target),
|
||||
undirected: graph.isUndirected(edge)
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
var tests = {
|
||||
Miscellaneous: {
|
||||
'simple graph indices should work.': function simple_graph_indices_should_work() {
|
||||
var simpleGraph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(simpleGraph, [1, 2, 3, 4]);
|
||||
simpleGraph.addEdgeWithKey('1->2', 1, 2);
|
||||
simpleGraph.addEdgeWithKey('1->3', 1, 3);
|
||||
simpleGraph.addEdgeWithKey('1->4', 1, 4);
|
||||
_assert["default"].deepStrictEqual(simpleGraph.edges(1), ['1->2', '1->3', '1->4']);
|
||||
},
|
||||
'it should also work with typed graphs.': function it_should_also_work_with_typed_graphs() {
|
||||
var undirected = new Graph({
|
||||
type: 'undirected'
|
||||
}),
|
||||
directed = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
undirected.mergeEdgeWithKey('1--2', 1, 2);
|
||||
directed.mergeEdgeWithKey('1->2', 1, 2);
|
||||
_assert["default"].deepStrictEqual(undirected.edges(1, 2), ['1--2']);
|
||||
_assert["default"].deepStrictEqual(directed.edges(1, 2), ['1->2']);
|
||||
},
|
||||
'self loops should appear when using #.inEdges and should appear only once with #.edges.': function self_loops_should_appear_when_using_InEdges_and_should_appear_only_once_with_Edges() {
|
||||
var directed = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
directed.addNode('Lucy');
|
||||
directed.addEdgeWithKey('Lucy', 'Lucy', 'Lucy');
|
||||
_assert["default"].deepStrictEqual(directed.inEdges('Lucy'), ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(Array.from(directed.inEdgeEntries('Lucy')).map(function (x) {
|
||||
return x.edge;
|
||||
}), ['Lucy']);
|
||||
var edges = [];
|
||||
directed.forEachInEdge('Lucy', function (edge) {
|
||||
edges.push(edge);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(edges, ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(directed.edges('Lucy'), ['Lucy']);
|
||||
edges = [];
|
||||
directed.forEachEdge('Lucy', function (edge) {
|
||||
edges.push(edge);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(edges, ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(Array.from(directed.edgeEntries('Lucy')).map(function (x) {
|
||||
return x.edge;
|
||||
}), ['Lucy']);
|
||||
},
|
||||
'it should be possible to retrieve self loops.': function it_should_be_possible_to_retrieve_self_loops() {
|
||||
var loopy = new Graph();
|
||||
loopy.addNode('John');
|
||||
loopy.addEdgeWithKey('d', 'John', 'John');
|
||||
loopy.addUndirectedEdgeWithKey('u', 'John', 'John');
|
||||
_assert["default"].deepStrictEqual(new Set(loopy.edges('John', 'John')), new Set(['d', 'u']));
|
||||
_assert["default"].deepStrictEqual(loopy.directedEdges('John', 'John'), ['d']);
|
||||
_assert["default"].deepStrictEqual(loopy.undirectedEdges('John', 'John'), ['u']);
|
||||
var edges = [];
|
||||
loopy.forEachDirectedEdge('John', 'John', function (edge) {
|
||||
edges.push(edge);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(edges, ['d']);
|
||||
edges = [];
|
||||
loopy.forEachUndirectedEdge('John', 'John', function (edge) {
|
||||
edges.push(edge);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(edges, ['u']);
|
||||
},
|
||||
'self loops in multi graphs should work properly (#352).': function self_loops_in_multi_graphs_should_work_properly_352() {
|
||||
var loopy = new Graph({
|
||||
multi: true
|
||||
});
|
||||
loopy.addNode('n');
|
||||
loopy.addEdgeWithKey('e1', 'n', 'n');
|
||||
loopy.addEdgeWithKey('e2', 'n', 'n');
|
||||
loopy.addUndirectedEdgeWithKey('e3', 'n', 'n');
|
||||
|
||||
// Arrays
|
||||
_assert["default"].deepStrictEqual(loopy.edges('n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.outboundEdges('n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.inboundEdges('n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.outEdges('n'), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(loopy.inEdges('n'), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(loopy.undirectedEdges('n'), ['e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.directedEdges('n'), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(loopy.edges('n', 'n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.outboundEdges('n', 'n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.inboundEdges('n', 'n'), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.outEdges('n', 'n'), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(loopy.inEdges('n', 'n'), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(loopy.undirectedEdges('n', 'n'), ['e3']);
|
||||
_assert["default"].deepStrictEqual(loopy.directedEdges('n', 'n'), ['e2', 'e1']);
|
||||
|
||||
// Iterators
|
||||
var mapKeys = function mapKeys(it) {
|
||||
return Array.from((0, _utils.map)(it, function (e) {
|
||||
return e.edge;
|
||||
}));
|
||||
};
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.edgeEntries('n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.outboundEdgeEntries('n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.inboundEdgeEntries('n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.outEdgeEntries('n')), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.inEdgeEntries('n')), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.undirectedEdgeEntries('n')), ['e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.directedEdgeEntries('n')), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.edgeEntries('n', 'n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.outboundEdgeEntries('n', 'n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.inboundEdgeEntries('n', 'n')), ['e2', 'e1', 'e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.outEdgeEntries('n', 'n')), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.inEdgeEntries('n', 'n')), ['e2', 'e1']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.undirectedEdgeEntries('n', 'n')), ['e3']);
|
||||
_assert["default"].deepStrictEqual(mapKeys(loopy.directedEdgeEntries('n', 'n')), ['e2', 'e1']);
|
||||
},
|
||||
'findOutboundEdge should work on multigraphs (#319).': function findOutboundEdge_should_work_on_multigraphs_319() {
|
||||
var loopy = new Graph({
|
||||
multi: true
|
||||
});
|
||||
loopy.mergeEdgeWithKey('e1', 'n', 'm');
|
||||
loopy.mergeEdgeWithKey('e2', 'n', 'n');
|
||||
_assert["default"].strictEqual(loopy.findOutboundEdge(function (_e, _a, s, t) {
|
||||
return s === t;
|
||||
}), 'e2');
|
||||
_assert["default"].strictEqual(loopy.findOutboundEdge('n', function (_e, _a, s, t) {
|
||||
return s === t;
|
||||
}), 'e2');
|
||||
_assert["default"].strictEqual(loopy.findOutboundEdge('n', 'n', function (_e, _a, s, t) {
|
||||
return s === t;
|
||||
}), 'e2');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Common tests
|
||||
METHODS.forEach(function (name) {
|
||||
return (0, _helpers.deepMerge)(tests, commonTests(name));
|
||||
});
|
||||
|
||||
// Specific tests
|
||||
for (var name in TEST_DATA) (0, _helpers.deepMerge)(tests, specificTests(name, TEST_DATA[name]));
|
||||
return tests;
|
||||
}
|
||||
129
web/node_modules/graphology/specs/iteration/index.js
generated
vendored
Normal file
129
web/node_modules/graphology/specs/iteration/index.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = iteration;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _nodes = _interopRequireDefault(require("./nodes"));
|
||||
var _edges = _interopRequireDefault(require("./edges"));
|
||||
var _neighbors = _interopRequireDefault(require("./neighbors"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Iteration Specs
|
||||
* ===========================
|
||||
*
|
||||
* Testing the iteration-related methods of the graph.
|
||||
*/
|
||||
|
||||
function iteration(Graph, checkers) {
|
||||
return {
|
||||
Adjacency: {
|
||||
'#.forEachAdjacencyEntry': {
|
||||
'it should iterate over the relevant elements.': function it_should_iterate_over_the_relevant_elements() {
|
||||
function test(multi) {
|
||||
var graph = new Graph({
|
||||
multi: multi
|
||||
});
|
||||
graph.addNode('John', {
|
||||
hello: 'world'
|
||||
});
|
||||
var _graph$mergeUndirecte = graph.mergeUndirectedEdge('John', 'Mary', {
|
||||
weight: 3
|
||||
}),
|
||||
e1 = _graph$mergeUndirecte[0];
|
||||
graph.mergeUndirectedEdge('Thomas', 'John');
|
||||
graph.mergeDirectedEdge('John', 'Thomas');
|
||||
var count = 0;
|
||||
graph.forEachAdjacencyEntry(function (node, neighbor, attr, neighborAttr, edge, edgeAttr, undirected) {
|
||||
count++;
|
||||
if (node === 'John') {
|
||||
_assert["default"].deepStrictEqual(attr, {
|
||||
hello: 'world'
|
||||
});
|
||||
} else {
|
||||
_assert["default"].deepStrictEqual(attr, {});
|
||||
}
|
||||
if (neighbor === 'John') {
|
||||
_assert["default"].deepStrictEqual(neighborAttr, {
|
||||
hello: 'world'
|
||||
});
|
||||
} else {
|
||||
_assert["default"].deepStrictEqual(neighborAttr, {});
|
||||
}
|
||||
if (edge === e1) {
|
||||
_assert["default"].deepStrictEqual(edgeAttr, {
|
||||
weight: 3
|
||||
});
|
||||
} else {
|
||||
_assert["default"].deepStrictEqual(edgeAttr, {});
|
||||
}
|
||||
_assert["default"].strictEqual(graph.isUndirected(edge), undirected);
|
||||
});
|
||||
_assert["default"].strictEqual(count, graph.directedSize + graph.undirectedSize * 2);
|
||||
graph.addNode('Disconnected');
|
||||
count = 0;
|
||||
graph.forEachAdjacencyEntryWithOrphans(function (node, neighbor, attr, neighborAttr, edge, edgeAttr, undirected) {
|
||||
count++;
|
||||
if (node !== 'Disconnected') return;
|
||||
_assert["default"].strictEqual(neighbor, null);
|
||||
_assert["default"].strictEqual(neighborAttr, null);
|
||||
_assert["default"].strictEqual(edge, null);
|
||||
_assert["default"].strictEqual(edgeAttr, null);
|
||||
_assert["default"].strictEqual(undirected, null);
|
||||
}, true);
|
||||
_assert["default"].strictEqual(count, graph.directedSize + graph.undirectedSize * 2 + 1);
|
||||
}
|
||||
test(false);
|
||||
test(true);
|
||||
}
|
||||
},
|
||||
'#.forEachAssymetricAdjacencyEntry': {
|
||||
'it should iterate over the relevant elements.': function it_should_iterate_over_the_relevant_elements() {
|
||||
function test(multi) {
|
||||
var graph = new Graph({
|
||||
multi: multi
|
||||
});
|
||||
graph.addNode('John', {
|
||||
hello: 'world'
|
||||
});
|
||||
graph.mergeUndirectedEdge('John', 'Mary', {
|
||||
weight: 3
|
||||
});
|
||||
graph.mergeUndirectedEdge('Thomas', 'John');
|
||||
graph.mergeDirectedEdge('John', 'Thomas');
|
||||
var edges = [];
|
||||
graph.forEachAssymetricAdjacencyEntry(function (node, neighbor, attr, neighborAttr, edge, edgeAttr, undirected) {
|
||||
if (undirected) {
|
||||
_assert["default"].strictEqual(node < neighbor, true);
|
||||
}
|
||||
edges.push(edge);
|
||||
});
|
||||
_assert["default"].strictEqual(edges.length, graph.directedSize + graph.undirectedSize);
|
||||
_assert["default"].deepStrictEqual(new Set(edges).size, edges.length);
|
||||
graph.addNode('Disconnected');
|
||||
var count = 0;
|
||||
var nulls = 0;
|
||||
graph.forEachAssymetricAdjacencyEntryWithOrphans(function (node, neighbor, attr, neighborAttr, edge, edgeAttr, undirected) {
|
||||
count++;
|
||||
if (neighbor) return;
|
||||
nulls++;
|
||||
_assert["default"].strictEqual(neighbor, null);
|
||||
_assert["default"].strictEqual(neighborAttr, null);
|
||||
_assert["default"].strictEqual(edge, null);
|
||||
_assert["default"].strictEqual(edgeAttr, null);
|
||||
_assert["default"].strictEqual(undirected, null);
|
||||
}, true);
|
||||
_assert["default"].strictEqual(count, graph.directedSize + graph.undirectedSize + 3);
|
||||
_assert["default"].strictEqual(nulls, 3);
|
||||
}
|
||||
test(false);
|
||||
test(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
Nodes: (0, _nodes["default"])(Graph, checkers),
|
||||
Edges: (0, _edges["default"])(Graph, checkers),
|
||||
Neighbors: (0, _neighbors["default"])(Graph, checkers)
|
||||
};
|
||||
}
|
||||
248
web/node_modules/graphology/specs/iteration/neighbors.js
generated
vendored
Normal file
248
web/node_modules/graphology/specs/iteration/neighbors.js
generated
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = neighborsIteration;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("../helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
||||
* Graphology Edges Iteration Specs
|
||||
* =================================
|
||||
*
|
||||
* Testing the edges iteration-related methods of the graph.
|
||||
*/
|
||||
var METHODS = ['neighbors', 'inNeighbors', 'outNeighbors', 'inboundNeighbors', 'outboundNeighbors', 'directedNeighbors', 'undirectedNeighbors'];
|
||||
function neighborsIteration(Graph, checkers) {
|
||||
var notFound = checkers.notFound,
|
||||
invalid = checkers.invalid;
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas', 'Martha', 'Roger', 'Catherine', 'Alone', 'Forever']);
|
||||
graph.replaceNodeAttributes('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.replaceNodeAttributes('Martha', {
|
||||
age: 35
|
||||
});
|
||||
graph.addDirectedEdgeWithKey('J->T', 'John', 'Thomas');
|
||||
graph.addDirectedEdgeWithKey('J->M', 'John', 'Martha');
|
||||
graph.addDirectedEdgeWithKey('C->J', 'Catherine', 'John');
|
||||
graph.addUndirectedEdgeWithKey('M<->R', 'Martha', 'Roger');
|
||||
graph.addUndirectedEdgeWithKey('M<->J', 'Martha', 'John');
|
||||
graph.addUndirectedEdgeWithKey('J<->R', 'John', 'Roger');
|
||||
graph.addUndirectedEdgeWithKey('T<->M', 'Thomas', 'Martha');
|
||||
var TEST_DATA = {
|
||||
neighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Catherine', 'Thomas', 'Martha', 'Roger']
|
||||
}
|
||||
},
|
||||
inNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Catherine']
|
||||
}
|
||||
},
|
||||
outNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Thomas', 'Martha']
|
||||
}
|
||||
},
|
||||
inboundNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Catherine', 'Martha', 'Roger']
|
||||
}
|
||||
},
|
||||
outboundNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Thomas', 'Martha', 'Roger']
|
||||
}
|
||||
},
|
||||
directedNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Catherine', 'Thomas', 'Martha']
|
||||
}
|
||||
},
|
||||
undirectedNeighbors: {
|
||||
node: {
|
||||
key: 'John',
|
||||
neighbors: ['Martha', 'Roger']
|
||||
}
|
||||
}
|
||||
};
|
||||
function commonTests(name) {
|
||||
return _defineProperty({}, '#.' + name, {
|
||||
'it should throw when the node is not found.': function it_should_throw_when_the_node_is_not_found() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name]('Test');
|
||||
}, notFound());
|
||||
if (~name.indexOf('count')) return;
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[name]('Test', 'SecondTest');
|
||||
}, notFound());
|
||||
}
|
||||
});
|
||||
}
|
||||
function specificTests(name, data) {
|
||||
var capitalized = name[0].toUpperCase() + name.slice(1, -1);
|
||||
var forEachName = 'forEach' + capitalized;
|
||||
var findName = 'find' + capitalized;
|
||||
var iteratorName = name.slice(0, -1) + 'Entries';
|
||||
var areName = 'are' + capitalized + 's';
|
||||
var mapName = 'map' + capitalized + 's';
|
||||
var filterName = 'filter' + capitalized + 's';
|
||||
var reduceName = 'reduce' + capitalized + 's';
|
||||
var someName = 'some' + capitalized;
|
||||
var everyName = 'every' + capitalized;
|
||||
return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, '#.' + name, {
|
||||
'it should return the correct neighbors array.': function it_should_return_the_correct_neighbors_array() {
|
||||
var neighbors = graph[name](data.node.key);
|
||||
_assert["default"].deepStrictEqual(neighbors, data.node.neighbors);
|
||||
_assert["default"].deepStrictEqual(graph[name]('Alone'), []);
|
||||
}
|
||||
}), '#.' + forEachName, {
|
||||
'it should be possible to iterate over neighbors using a callback.': function it_should_be_possible_to_iterate_over_neighbors_using_a_callback() {
|
||||
var neighbors = [];
|
||||
graph[forEachName](data.node.key, function (target, attrs) {
|
||||
neighbors.push(target);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), attrs);
|
||||
_assert["default"].strictEqual(graph[areName](data.node.key, target), true);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(neighbors, data.node.neighbors);
|
||||
}
|
||||
}), '#.' + mapName, {
|
||||
'it should be possible to map neighbors using a callback.': function it_should_be_possible_to_map_neighbors_using_a_callback() {
|
||||
var result = graph[mapName](data.node.key, function (target) {
|
||||
return target;
|
||||
});
|
||||
_assert["default"].deepStrictEqual(result, data.node.neighbors);
|
||||
}
|
||||
}), '#.' + filterName, {
|
||||
'it should be possible to filter neighbors using a callback.': function it_should_be_possible_to_filter_neighbors_using_a_callback() {
|
||||
var result = graph[filterName](data.node.key, function () {
|
||||
return true;
|
||||
});
|
||||
_assert["default"].deepStrictEqual(result, data.node.neighbors);
|
||||
result = graph[filterName](data.node.key, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].deepStrictEqual(result, []);
|
||||
}
|
||||
}), '#.' + reduceName, {
|
||||
'it sould throw if not given an initial value.': function it_sould_throw_if_not_given_an_initial_value() {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[reduceName]('node', function () {
|
||||
return true;
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
'it should be possible to reduce neighbors using a callback.': function it_should_be_possible_to_reduce_neighbors_using_a_callback() {
|
||||
var result = graph[reduceName](data.node.key, function (acc, key) {
|
||||
return acc.concat(key);
|
||||
}, []);
|
||||
_assert["default"].deepStrictEqual(result, data.node.neighbors);
|
||||
}
|
||||
}), '#.' + findName, {
|
||||
'it should be possible to find neighbors.': function it_should_be_possible_to_find_neighbors() {
|
||||
var neighbors = [];
|
||||
var found = graph[findName](data.node.key, function (target, attrs) {
|
||||
neighbors.push(target);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes(target), attrs);
|
||||
_assert["default"].strictEqual(graph[areName](data.node.key, target), true);
|
||||
return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, neighbors[0]);
|
||||
_assert["default"].deepStrictEqual(neighbors, data.node.neighbors.slice(0, 1));
|
||||
found = graph[findName](data.node.key, function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, undefined);
|
||||
}
|
||||
}), '#.' + someName, {
|
||||
'it should always return false on empty set.': function it_should_always_return_false_on_empty_set() {
|
||||
var loneGraph = new Graph();
|
||||
loneGraph.addNode('alone');
|
||||
_assert["default"].strictEqual(loneGraph[someName]('alone', function () {
|
||||
return true;
|
||||
}), false);
|
||||
},
|
||||
'it should be possible to assert whether any neighbor matches a predicate.': function it_should_be_possible_to_assert_whether_any_neighbor_matches_a_predicate() {
|
||||
_assert["default"].strictEqual(graph[someName](data.node.key, function () {
|
||||
return true;
|
||||
}), data.node.neighbors.length > 0);
|
||||
}
|
||||
}), '#.' + everyName, {
|
||||
'it should always return true on empty set.': function it_should_always_return_true_on_empty_set() {
|
||||
var loneGraph = new Graph();
|
||||
loneGraph.addNode('alone');
|
||||
_assert["default"].strictEqual(loneGraph[everyName]('alone', function () {
|
||||
return true;
|
||||
}), true);
|
||||
},
|
||||
'it should be possible to assert whether any neighbor matches a predicate.': function it_should_be_possible_to_assert_whether_any_neighbor_matches_a_predicate() {
|
||||
_assert["default"].strictEqual(graph[everyName](data.node.key, function () {
|
||||
return true;
|
||||
}), data.node.neighbors.length > 0);
|
||||
}
|
||||
}), '#.' + iteratorName, {
|
||||
'it should be possible to create an iterator over neighbors.': function it_should_be_possible_to_create_an_iterator_over_neighbors() {
|
||||
var iterator = graph[iteratorName](data.node.key);
|
||||
_assert["default"].deepStrictEqual(Array.from(iterator), data.node.neighbors.map(function (neighbor) {
|
||||
return {
|
||||
neighbor: neighbor,
|
||||
attributes: graph.getNodeAttributes(neighbor)
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
var tests = {
|
||||
Miscellaneous: {
|
||||
'self loops should appear when using #.inNeighbors and should appear only once with #.neighbors.': function self_loops_should_appear_when_using_InNeighbors_and_should_appear_only_once_with_Neighbors() {
|
||||
var directed = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
directed.addNode('Lucy');
|
||||
directed.addEdgeWithKey('test', 'Lucy', 'Lucy');
|
||||
_assert["default"].deepStrictEqual(directed.inNeighbors('Lucy'), ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(Array.from(directed.inNeighborEntries('Lucy')).map(function (x) {
|
||||
return x.neighbor;
|
||||
}), ['Lucy']);
|
||||
var neighbors = [];
|
||||
directed.forEachInNeighbor('Lucy', function (neighbor) {
|
||||
neighbors.push(neighbor);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(neighbors, ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(directed.neighbors('Lucy'), ['Lucy']);
|
||||
neighbors = [];
|
||||
directed.forEachNeighbor('Lucy', function (neighbor) {
|
||||
neighbors.push(neighbor);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(neighbors, ['Lucy']);
|
||||
_assert["default"].deepStrictEqual(Array.from(directed.neighborEntries('Lucy')).map(function (x) {
|
||||
return x.neighbor;
|
||||
}), ['Lucy']);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Common tests
|
||||
METHODS.forEach(function (name) {
|
||||
return (0, _helpers.deepMerge)(tests, commonTests(name));
|
||||
});
|
||||
|
||||
// Specific tests
|
||||
for (var name in TEST_DATA) (0, _helpers.deepMerge)(tests, specificTests(name, TEST_DATA[name]));
|
||||
return tests;
|
||||
}
|
||||
219
web/node_modules/graphology/specs/iteration/nodes.js
generated
vendored
Normal file
219
web/node_modules/graphology/specs/iteration/nodes.js
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = nodesIteration;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("../helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Nodes Iteration Specs
|
||||
* =================================
|
||||
*
|
||||
* Testing the nodes iteration-related methods of the graph.
|
||||
*/
|
||||
|
||||
function nodesIteration(Graph, checkers) {
|
||||
var invalid = checkers.invalid;
|
||||
return {
|
||||
'#.nodes': {
|
||||
'it should return the list of nodes of the graph.': function it_should_return_the_list_of_nodes_of_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['one', 'two', 'three']);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['one', 'two', 'three']);
|
||||
}
|
||||
},
|
||||
'#.forEachNode': {
|
||||
'it should throw if given callback is not a function.': function it_should_throw_if_given_callback_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.forEachNode(null);
|
||||
}, invalid());
|
||||
},
|
||||
'it should be possible to iterate over nodes and their attributes.': function it_should_be_possible_to_iterate_over_nodes_and_their_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Martha', {
|
||||
age: 33
|
||||
});
|
||||
var count = 0;
|
||||
graph.forEachNode(function (key, attributes) {
|
||||
_assert["default"].strictEqual(key, count ? 'Martha' : 'John');
|
||||
_assert["default"].deepStrictEqual(attributes, count ? {
|
||||
age: 33
|
||||
} : {
|
||||
age: 34
|
||||
});
|
||||
count++;
|
||||
});
|
||||
_assert["default"].strictEqual(count, 2);
|
||||
}
|
||||
},
|
||||
'#.findNode': {
|
||||
'it should throw if given callback is not a function.': function it_should_throw_if_given_callback_is_not_a_function() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.findNode(null);
|
||||
}, invalid());
|
||||
},
|
||||
'it should be possible to find a node in the graph.': function it_should_be_possible_to_find_a_node_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
age: 34
|
||||
});
|
||||
graph.addNode('Martha', {
|
||||
age: 33
|
||||
});
|
||||
var count = 0;
|
||||
var found = graph.findNode(function (key, attributes) {
|
||||
_assert["default"].strictEqual(key, 'John');
|
||||
_assert["default"].deepStrictEqual(attributes, {
|
||||
age: 34
|
||||
});
|
||||
count++;
|
||||
if (key === 'John') return true;
|
||||
});
|
||||
_assert["default"].strictEqual(found, 'John');
|
||||
_assert["default"].strictEqual(count, 1);
|
||||
found = graph.findNode(function () {
|
||||
return false;
|
||||
});
|
||||
_assert["default"].strictEqual(found, undefined);
|
||||
}
|
||||
},
|
||||
'#.mapNodes': {
|
||||
'it should be possible to map nodes.': function it_should_be_possible_to_map_nodes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('one', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addNode('two', {
|
||||
weight: 3
|
||||
});
|
||||
var result = graph.mapNodes(function (node, attr) {
|
||||
return attr.weight * 2;
|
||||
});
|
||||
_assert["default"].deepStrictEqual(result, [4, 6]);
|
||||
}
|
||||
},
|
||||
'#.someNode': {
|
||||
'it should always return false on empty sets.': function it_should_always_return_false_on_empty_sets() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.someNode(function () {
|
||||
return true;
|
||||
}), false);
|
||||
},
|
||||
'it should be possible to find if some node matches a predicate.': function it_should_be_possible_to_find_if_some_node_matches_a_predicate() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('one', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addNode('two', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].strictEqual(graph.someNode(function (node, attr) {
|
||||
return attr.weight > 6;
|
||||
}), false);
|
||||
_assert["default"].strictEqual(graph.someNode(function (node, attr) {
|
||||
return attr.weight > 2;
|
||||
}), true);
|
||||
}
|
||||
},
|
||||
'#.everyNode': {
|
||||
'it should always return true on empty sets.': function it_should_always_return_true_on_empty_sets() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.everyNode(function () {
|
||||
return true;
|
||||
}), true);
|
||||
},
|
||||
'it should be possible to find if all node matches a predicate.': function it_should_be_possible_to_find_if_all_node_matches_a_predicate() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('one', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addNode('two', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].strictEqual(graph.everyNode(function (node, attr) {
|
||||
return attr.weight > 2;
|
||||
}), false);
|
||||
_assert["default"].strictEqual(graph.everyNode(function (node, attr) {
|
||||
return attr.weight > 1;
|
||||
}), true);
|
||||
}
|
||||
},
|
||||
'#.filterNodes': {
|
||||
'it should be possible to filter nodes.': function it_should_be_possible_to_filter_nodes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('one', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addNode('two', {
|
||||
weight: 3
|
||||
});
|
||||
graph.addNode('three', {
|
||||
weight: 4
|
||||
});
|
||||
var result = graph.filterNodes(function (node, _ref) {
|
||||
var weight = _ref.weight;
|
||||
return weight >= 3;
|
||||
});
|
||||
_assert["default"].deepStrictEqual(result, ['two', 'three']);
|
||||
}
|
||||
},
|
||||
'#.reduceNodes': {
|
||||
'it should throw if initial value is not given.': function it_should_throw_if_initial_value_is_not_given() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.reduceNodes(function (x, _, attr) {
|
||||
return x + attr.weight;
|
||||
});
|
||||
}, invalid());
|
||||
},
|
||||
'it should be possible to reduce nodes.': function it_should_be_possible_to_reduce_nodes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('one', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addNode('two', {
|
||||
weight: 3
|
||||
});
|
||||
graph.addNode('three', {
|
||||
weight: 4
|
||||
});
|
||||
var result = graph.reduceNodes(function (x, _, attr) {
|
||||
return x + attr.weight;
|
||||
}, 0);
|
||||
_assert["default"].strictEqual(result, 9);
|
||||
}
|
||||
},
|
||||
'#.nodeEntries': {
|
||||
'it should be possible to create a nodes iterator.': function it_should_be_possible_to_create_a_nodes_iterator() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['one', 'two', 'three']);
|
||||
graph.replaceNodeAttributes('two', {
|
||||
hello: 'world'
|
||||
});
|
||||
var iterator = graph.nodeEntries();
|
||||
_assert["default"].deepStrictEqual(iterator.next().value, {
|
||||
node: 'one',
|
||||
attributes: {}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(iterator.next().value, {
|
||||
node: 'two',
|
||||
attributes: {
|
||||
hello: 'world'
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(iterator.next().value, {
|
||||
node: 'three',
|
||||
attributes: {}
|
||||
});
|
||||
_assert["default"].strictEqual(iterator.next().done, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
45
web/node_modules/graphology/specs/known.js
generated
vendored
Normal file
45
web/node_modules/graphology/specs/known.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = knownMethods;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Known Methods Specs
|
||||
* ===============================
|
||||
*
|
||||
* Testing the known methods of the graph.
|
||||
*/
|
||||
|
||||
function knownMethods(Graph) {
|
||||
return {
|
||||
'#.toJSON': {
|
||||
'it should return the serialized graph.': function it_should_return_the_serialized_graph() {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Jack', 'Martha']);
|
||||
graph.setNodeAttribute('John', 'age', 34);
|
||||
graph.addEdgeWithKey('J->J•1', 'John', 'Jack');
|
||||
graph.addEdgeWithKey('J->J•2', 'John', 'Jack', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addEdgeWithKey('J->J•3', 'John', 'Jack');
|
||||
graph.addUndirectedEdgeWithKey('J<->J•1', 'John', 'Jack');
|
||||
graph.addUndirectedEdgeWithKey('J<->J•2', 'John', 'Jack', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.toJSON(), graph["export"]());
|
||||
}
|
||||
},
|
||||
'#.toString': {
|
||||
'it should return "[object Graph]".': function it_should_return_Object_Graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.toString(), '[object Graph]');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
88
web/node_modules/graphology/specs/misc.js
generated
vendored
Normal file
88
web/node_modules/graphology/specs/misc.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = misc;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Misc Specs
|
||||
* ======================
|
||||
*
|
||||
* Testing the miscellaneous things about the graph.
|
||||
*/
|
||||
|
||||
function misc(Graph) {
|
||||
return {
|
||||
Structure: {
|
||||
'a simple mixed graph can have A->B, B->A & A<->B': function a_simple_mixed_graph_can_have_AB_BA__AB() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Audrey', 'Benjamin']);
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
graph.addEdge('Audrey', 'Benjamin');
|
||||
graph.addEdge('Benjamin', 'Audrey');
|
||||
graph.addUndirectedEdge('Benjamin', 'Audrey');
|
||||
});
|
||||
},
|
||||
'deleting the last edge between A & B should correctly clear neighbor index.': function deleting_the_last_edge_between_A__B_should_correctly_clear_neighbor_index() {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.addNode('A');
|
||||
graph.addNode('B');
|
||||
graph.addEdge('A', 'B');
|
||||
graph.addEdge('A', 'B');
|
||||
graph.forEachEdge('A', function (edge) {
|
||||
return graph.dropEdge(edge);
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.neighbors('A'), []);
|
||||
_assert["default"].deepStrictEqual(graph.neighbors('B'), []);
|
||||
},
|
||||
'exhaustive deletion use-cases should not break doubly-linked lists implementation of multigraph edge storage.': function exhaustive_deletion_useCases_should_not_break_doublyLinked_lists_implementation_of_multigraph_edge_storage() {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.mergeEdgeWithKey('1', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('2', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('3', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('4', 'A', 'B');
|
||||
graph.dropEdge('1');
|
||||
graph.dropEdge('2');
|
||||
graph.dropEdge('3');
|
||||
graph.dropEdge('4');
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('A', 'B'), false);
|
||||
graph.mergeEdgeWithKey('1', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('2', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('3', 'A', 'B');
|
||||
graph.mergeEdgeWithKey('4', 'A', 'B');
|
||||
_assert["default"].strictEqual(graph.size, 4);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('A', 'B'), true);
|
||||
graph.dropEdge('2');
|
||||
graph.dropEdge('3');
|
||||
_assert["default"].strictEqual(graph.size, 2);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('A', 'B'), true);
|
||||
graph.dropEdge('4');
|
||||
graph.dropEdge('1');
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('A', 'B'), false);
|
||||
}
|
||||
},
|
||||
'Key coercion': {
|
||||
'keys should be correctly coerced to strings.': function keys_should_be_correctly_coerced_to_strings() {
|
||||
var graph = new Graph();
|
||||
graph.addNode(1);
|
||||
graph.addNode('2');
|
||||
_assert["default"].strictEqual(graph.hasNode(1), true);
|
||||
_assert["default"].strictEqual(graph.hasNode('1'), true);
|
||||
_assert["default"].strictEqual(graph.hasNode(2), true);
|
||||
_assert["default"].strictEqual(graph.hasNode('2'), true);
|
||||
graph.addEdgeWithKey(3, 1, 2);
|
||||
_assert["default"].strictEqual(graph.hasEdge(3), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('3'), true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
721
web/node_modules/graphology/specs/mutation.js
generated
vendored
Normal file
721
web/node_modules/graphology/specs/mutation.js
generated
vendored
Normal file
@@ -0,0 +1,721 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = mutation;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
||||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
||||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
||||
* Graphology Mutation Specs
|
||||
* ==========================
|
||||
*
|
||||
* Testing the mutation methods of the graph.
|
||||
*/
|
||||
function mutation(Graph, checkers) {
|
||||
var invalid = checkers.invalid,
|
||||
notFound = checkers.notFound,
|
||||
usage = checkers.usage;
|
||||
return {
|
||||
'#.addNode': {
|
||||
'it should throw if given attributes is not an object.': function it_should_throw_if_given_attributes_is_not_an_object() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addNode('test', true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should throw if the given node already exist.': function it_should_throw_if_the_given_node_already_exist() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addNode('Martha');
|
||||
}, usage());
|
||||
},
|
||||
'it should return the added node.': function it_should_return_the_added_node() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.addNode('John'), 'John');
|
||||
}
|
||||
},
|
||||
'#.mergeNode': {
|
||||
'it should add the node if it does not exist yet.': function it_should_add_the_node_if_it_does_not_exist_yet() {
|
||||
var graph = new Graph();
|
||||
graph.mergeNode('John');
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
},
|
||||
'it should do nothing if the node already exists.': function it_should_do_nothing_if_the_node_already_exists() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.mergeNode('John');
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
},
|
||||
'it should merge the attributes.': function it_should_merge_the_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
eyes: 'blue'
|
||||
});
|
||||
graph.mergeNode('John', {
|
||||
age: 15
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
eyes: 'blue',
|
||||
age: 15
|
||||
});
|
||||
},
|
||||
'it should coerce keys to string.': function it_should_coerce_keys_to_string() {
|
||||
var graph = new Graph();
|
||||
graph.addNode(4);
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
return graph.mergeNode(4);
|
||||
});
|
||||
},
|
||||
'it should return useful information.': function it_should_return_useful_information() {
|
||||
var graph = new Graph();
|
||||
var _graph$mergeNode = graph.mergeNode('Jack'),
|
||||
key = _graph$mergeNode[0],
|
||||
wasAdded = _graph$mergeNode[1];
|
||||
_assert["default"].strictEqual(key, 'Jack');
|
||||
_assert["default"].strictEqual(wasAdded, true);
|
||||
var _graph$mergeNode2 = graph.mergeNode('Jack');
|
||||
key = _graph$mergeNode2[0];
|
||||
wasAdded = _graph$mergeNode2[1];
|
||||
_assert["default"].strictEqual(key, 'Jack');
|
||||
_assert["default"].strictEqual(wasAdded, false);
|
||||
}
|
||||
},
|
||||
'#.updateNode': {
|
||||
'it should add the node if it does not exist yet.': function it_should_add_the_node_if_it_does_not_exist_yet() {
|
||||
var graph = new Graph();
|
||||
graph.updateNode('John');
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
},
|
||||
'it should do nothing if the node already exists.': function it_should_do_nothing_if_the_node_already_exists() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.updateNode('John');
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
},
|
||||
'it should update the attributes.': function it_should_update_the_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John', {
|
||||
eyes: 'blue',
|
||||
count: 1
|
||||
});
|
||||
graph.updateNode('John', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
count: attr.count + 1
|
||||
});
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John']);
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
eyes: 'blue',
|
||||
count: 2
|
||||
});
|
||||
},
|
||||
'it should be possible to start from blank attributes.': function it_should_be_possible_to_start_from_blank_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.updateNode('John', function () {
|
||||
return {
|
||||
count: 2
|
||||
};
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {
|
||||
count: 2
|
||||
});
|
||||
},
|
||||
'it should coerce keys to string.': function it_should_coerce_keys_to_string() {
|
||||
var graph = new Graph();
|
||||
graph.addNode(4);
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
return graph.updateNode(4);
|
||||
});
|
||||
},
|
||||
'it should return useful information.': function it_should_return_useful_information() {
|
||||
var graph = new Graph();
|
||||
var _graph$updateNode = graph.updateNode('Jack'),
|
||||
key = _graph$updateNode[0],
|
||||
wasAdded = _graph$updateNode[1];
|
||||
_assert["default"].strictEqual(key, 'Jack');
|
||||
_assert["default"].strictEqual(wasAdded, true);
|
||||
var _graph$updateNode2 = graph.updateNode('Jack');
|
||||
key = _graph$updateNode2[0];
|
||||
wasAdded = _graph$updateNode2[1];
|
||||
_assert["default"].strictEqual(key, 'Jack');
|
||||
_assert["default"].strictEqual(wasAdded, false);
|
||||
}
|
||||
},
|
||||
'#.addDirectedEdge': {
|
||||
'it should throw if given attributes is not an object.': function it_should_throw_if_given_attributes_is_not_an_object() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('source', 'target', true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should throw if the graph is undirected.': function it_should_throw_if_the_graph_is_undirected() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('source', 'target');
|
||||
}, usage());
|
||||
},
|
||||
'it should throw if either the source or the target does not exist.': function it_should_throw_if_either_the_source_or_the_target_does_not_exist() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('Thomas', 'Eric');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('Martha', 'Eric');
|
||||
}, notFound());
|
||||
},
|
||||
'it should throw if the edge is a loop and the graph does not allow it.': function it_should_throw_if_the_edge_is_a_loop_and_the_graph_does_not_allow_it() {
|
||||
var graph = new Graph({
|
||||
allowSelfLoops: false
|
||||
});
|
||||
graph.addNode('Thomas');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('Thomas', 'Thomas');
|
||||
}, usage());
|
||||
},
|
||||
'it should be possible to add self loops.': function it_should_be_possible_to_add_self_loops() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
var loop = graph.addDirectedEdge('Thomas', 'Thomas');
|
||||
_assert["default"].deepStrictEqual(graph.extremities(loop), ['Thomas', 'Thomas']);
|
||||
},
|
||||
'it should throw if the graph is not multi & we try to add twice the same edge.': function it_should_throw_if_the_graph_is_not_multi__we_try_to_add_twice_the_same_edge() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
graph.addNode('Martha');
|
||||
graph.addDirectedEdge('Thomas', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdge('Thomas', 'Martha');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdgeWithKey('T->M', 'Thomas', 'Martha');
|
||||
}, usage());
|
||||
},
|
||||
"it should return the generated edge's key.": function it_should_return_the_generated_edgeS_key() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addDirectedEdge('Thomas', 'Martha');
|
||||
(0, _assert["default"])(typeof edge === 'string' || typeof edge === 'number');
|
||||
(0, _assert["default"])(!(edge instanceof Graph));
|
||||
}
|
||||
},
|
||||
'#.addEdge': {
|
||||
'it should add a directed edge if the graph is directed or mixed.': function it_should_add_a_directed_edge_if_the_graph_is_directed_or_mixed() {
|
||||
var graph = new Graph(),
|
||||
directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var mixedEdge = graph.addEdge('John', 'Martha');
|
||||
directedGraph.addNode('John');
|
||||
directedGraph.addNode('Martha');
|
||||
var directedEdge = directedGraph.addEdge('John', 'Martha');
|
||||
(0, _assert["default"])(graph.isDirected(mixedEdge));
|
||||
(0, _assert["default"])(directedGraph.isDirected(directedEdge));
|
||||
},
|
||||
'it should add an undirected edge if the graph is undirected.': function it_should_add_an_undirected_edge_if_the_graph_is_undirected() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addEdge('John', 'Martha');
|
||||
(0, _assert["default"])(graph.isUndirected(edge));
|
||||
}
|
||||
},
|
||||
'#.addDirectedEdgeWithKey': {
|
||||
'it should throw if an edge with the same key already exists.': function it_should_throw_if_an_edge_with_the_same_key_already_exists() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
graph.addNode('Martha');
|
||||
graph.addDirectedEdgeWithKey('T->M', 'Thomas', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdgeWithKey('T->M', 'Thomas', 'Martha');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addUndirectedEdgeWithKey('T->M', 'Thomas', 'Martha');
|
||||
}, usage());
|
||||
}
|
||||
},
|
||||
'#.addUndirectedEdgeWithKey': {
|
||||
'it should throw if an edge with the same key already exists.': function it_should_throw_if_an_edge_with_the_same_key_already_exists() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
graph.addNode('Martha');
|
||||
graph.addUndirectedEdgeWithKey('T<->M', 'Thomas', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addUndirectedEdgeWithKey('T<->M', 'Thomas', 'Martha');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.addDirectedEdgeWithKey('T<->M', 'Thomas', 'Martha');
|
||||
}, usage());
|
||||
}
|
||||
},
|
||||
'#.addEdgeWithKey': {
|
||||
'it should add a directed edge if the graph is directed or mixed.': function it_should_add_a_directed_edge_if_the_graph_is_directed_or_mixed() {
|
||||
var graph = new Graph(),
|
||||
directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var mixedEdge = graph.addEdgeWithKey('J->M', 'John', 'Martha');
|
||||
directedGraph.addNode('John');
|
||||
directedGraph.addNode('Martha');
|
||||
var directedEdge = directedGraph.addEdgeWithKey('J->M', 'John', 'Martha');
|
||||
(0, _assert["default"])(graph.isDirected(mixedEdge));
|
||||
(0, _assert["default"])(directedGraph.isDirected(directedEdge));
|
||||
},
|
||||
'it should add an undirected edge if the graph is undirected.': function it_should_add_an_undirected_edge_if_the_graph_is_undirected() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addEdgeWithKey('J<->M', 'John', 'Martha');
|
||||
(0, _assert["default"])(graph.isUndirected(edge));
|
||||
}
|
||||
},
|
||||
'#.mergeEdge': {
|
||||
'it should add the edge if it does not yet exist.': function it_should_add_the_edge_if_it_does_not_yet_exist() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.mergeEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
},
|
||||
'it should do nothing if the edge already exists.': function it_should_do_nothing_if_the_edge_already_exists() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdge('John', 'Martha');
|
||||
graph.mergeEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
},
|
||||
'it should merge existing attributes if any.': function it_should_merge_existing_attributes_if_any() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdge('John', 'Martha', {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
graph.mergeEdge('John', 'Martha', {
|
||||
weight: 2
|
||||
});
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes('John', 'Martha'), {
|
||||
type: 'KNOWS',
|
||||
weight: 2
|
||||
});
|
||||
},
|
||||
'it should add missing nodes in the path.': function it_should_add_missing_nodes_in_the_path() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John', 'Martha']);
|
||||
},
|
||||
'it should throw in case of inconsistencies.': function it_should_throw_in_case_of_inconsistencies() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdgeWithKey('J->M', 'John', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.mergeEdgeWithKey('J->M', 'John', 'Thomas');
|
||||
}, usage());
|
||||
},
|
||||
'it should be able to merge undirected edges in both directions.': function it_should_be_able_to_merge_undirected_edges_in_both_directions() {
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
var graph = new Graph();
|
||||
graph.mergeUndirectedEdgeWithKey('J<->M', 'John', 'Martha');
|
||||
graph.mergeUndirectedEdgeWithKey('J<->M', 'John', 'Martha');
|
||||
graph.mergeUndirectedEdgeWithKey('J<->M', 'Martha', 'John');
|
||||
}, usage());
|
||||
},
|
||||
'it should distinguish between typed edges.': function it_should_distinguish_between_typed_edges() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge('John', 'Martha', {
|
||||
type: 'LIKES'
|
||||
});
|
||||
graph.mergeUndirectedEdge('John', 'Martha', {
|
||||
weight: 34
|
||||
});
|
||||
_assert["default"].strictEqual(graph.size, 2);
|
||||
},
|
||||
'it should be possible to merge a self loop.': function it_should_be_possible_to_merge_a_self_loop() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge('John', 'John', {
|
||||
type: 'IS'
|
||||
});
|
||||
_assert["default"].strictEqual(graph.order, 1);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
},
|
||||
'it should return useful information.': function it_should_return_useful_information() {
|
||||
var graph = new Graph();
|
||||
var info = graph.mergeEdge('John', 'Jack');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('John', 'Jack'), true, true, true]);
|
||||
info = graph.mergeEdge('John', 'Jack');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('John', 'Jack'), false, false, false]);
|
||||
graph.addNode('Mary');
|
||||
info = graph.mergeEdge('Mary', 'Sue');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Mary', 'Sue'), true, false, true]);
|
||||
info = graph.mergeEdge('Gwladys', 'Mary');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Gwladys', 'Mary'), true, true, false]);
|
||||
graph.addNode('Quintin');
|
||||
info = graph.mergeEdge('Quintin', 'Mary');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Quintin', 'Mary'), true, false, false]);
|
||||
}
|
||||
},
|
||||
'#.updateEdge': {
|
||||
'it should add the edge if it does not yet exist.': function it_should_add_the_edge_if_it_does_not_yet_exist() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.updateEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
},
|
||||
'it should do nothing if the edge already exists.': function it_should_do_nothing_if_the_edge_already_exists() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdge('John', 'Martha');
|
||||
graph.updateEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
},
|
||||
'it should be possible to start from blank attributes.': function it_should_be_possible_to_start_from_blank_attributes() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.updateEdge('John', 'Martha', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: 3
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes('John', 'Martha'), {
|
||||
weight: 3
|
||||
});
|
||||
},
|
||||
'it should update existing attributes if any.': function it_should_update_existing_attributes_if_any() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
graph.addEdge('John', 'Martha', {
|
||||
type: 'KNOWS'
|
||||
});
|
||||
graph.updateEdge('John', 'Martha', function (attr) {
|
||||
return _objectSpread(_objectSpread({}, attr), {}, {
|
||||
weight: 2
|
||||
});
|
||||
});
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Martha'), true);
|
||||
_assert["default"].deepStrictEqual(graph.getEdgeAttributes('John', 'Martha'), {
|
||||
type: 'KNOWS',
|
||||
weight: 2
|
||||
});
|
||||
},
|
||||
'it should add missing nodes in the path.': function it_should_add_missing_nodes_in_the_path() {
|
||||
var graph = new Graph();
|
||||
graph.updateEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John', 'Martha']);
|
||||
},
|
||||
'it should throw in case of inconsistencies.': function it_should_throw_in_case_of_inconsistencies() {
|
||||
var graph = new Graph();
|
||||
graph.updateEdgeWithKey('J->M', 'John', 'Martha');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.updateEdgeWithKey('J->M', 'John', 'Thomas');
|
||||
}, usage());
|
||||
},
|
||||
'it should distinguish between typed edges.': function it_should_distinguish_between_typed_edges() {
|
||||
var graph = new Graph();
|
||||
graph.updateEdge('John', 'Martha', function () {
|
||||
return {
|
||||
type: 'LIKES'
|
||||
};
|
||||
});
|
||||
graph.updateUndirectedEdge('John', 'Martha', function () {
|
||||
return {
|
||||
weight: 34
|
||||
};
|
||||
});
|
||||
_assert["default"].strictEqual(graph.size, 2);
|
||||
},
|
||||
'it should be possible to merge a self loop.': function it_should_be_possible_to_merge_a_self_loop() {
|
||||
var graph = new Graph();
|
||||
graph.updateEdge('John', 'John', function () {
|
||||
return {
|
||||
type: 'IS'
|
||||
};
|
||||
});
|
||||
_assert["default"].strictEqual(graph.order, 1);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
},
|
||||
'it should return useful information.': function it_should_return_useful_information() {
|
||||
var graph = new Graph();
|
||||
var info = graph.updateEdge('John', 'Jack');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('John', 'Jack'), true, true, true]);
|
||||
info = graph.updateEdge('John', 'Jack');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('John', 'Jack'), false, false, false]);
|
||||
graph.addNode('Mary');
|
||||
info = graph.updateEdge('Mary', 'Sue');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Mary', 'Sue'), true, false, true]);
|
||||
info = graph.updateEdge('Gwladys', 'Mary');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Gwladys', 'Mary'), true, true, false]);
|
||||
graph.addNode('Quintin');
|
||||
info = graph.updateEdge('Quintin', 'Mary');
|
||||
_assert["default"].deepStrictEqual(info, [graph.edge('Quintin', 'Mary'), true, false, false]);
|
||||
}
|
||||
},
|
||||
'#.dropEdge': {
|
||||
'it should throw if the edge or nodes in the path are not found in the graph.': function it_should_throw_if_the_edge_or_nodes_in_the_path_are_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Martha']);
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.dropEdge('Test');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.dropEdge('Forever', 'Alone');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.dropEdge('John', 'Test');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.dropEdge('John', 'Martha');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly remove the given edge from the graph.': function it_should_correctly_remove_the_given_edge_from_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Margaret']);
|
||||
var edge = graph.addEdge('John', 'Margaret');
|
||||
graph.dropEdge(edge);
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.degree('John'), 0);
|
||||
_assert["default"].strictEqual(graph.degree('Margaret'), 0);
|
||||
_assert["default"].strictEqual(graph.hasEdge(edge), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('John', 'Margaret'), false);
|
||||
},
|
||||
'it should be possible to remove an edge using source & target.': function it_should_be_possible_to_remove_an_edge_using_source__target() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Margaret']);
|
||||
graph.addEdge('John', 'Margaret');
|
||||
graph.dropEdge('John', 'Margaret');
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.degree('John'), 0);
|
||||
_assert["default"].strictEqual(graph.degree('Margaret'), 0);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Margaret'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('John', 'Margaret'), false);
|
||||
},
|
||||
'it should work with self loops.': function it_should_work_with_self_loops() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge('John', 'John');
|
||||
graph.dropEdge('John', 'John');
|
||||
_assert["default"].deepStrictEqual(graph.edges(), []);
|
||||
_assert["default"].deepStrictEqual(graph.edges('John'), []);
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
var multiGraph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
multiGraph.mergeEdgeWithKey('j', 'John', 'John');
|
||||
multiGraph.mergeEdgeWithKey('k', 'John', 'John');
|
||||
multiGraph.dropEdge('j');
|
||||
_assert["default"].deepStrictEqual(multiGraph.edges(), ['k']);
|
||||
_assert["default"].deepStrictEqual(multiGraph.edges('John'), ['k']);
|
||||
_assert["default"].strictEqual(multiGraph.size, 1);
|
||||
}
|
||||
},
|
||||
'#.dropNode': {
|
||||
'it should throw if the edge is not found in the graph.': function it_should_throw_if_the_edge_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.dropNode('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly remove the given node from the graph.': function it_should_correctly_remove_the_given_node_from_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Margaret']);
|
||||
var edge = graph.addEdge('John', 'Margaret');
|
||||
graph.mergeEdge('Jack', 'Trudy');
|
||||
graph.dropNode('Margaret');
|
||||
_assert["default"].strictEqual(graph.order, 3);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasNode('Margaret'), false);
|
||||
_assert["default"].strictEqual(graph.hasEdge(edge), false);
|
||||
_assert["default"].strictEqual(graph.degree('John'), 0);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('John', 'Margaret'), false);
|
||||
},
|
||||
'it should also work with mixed, multi graphs and self loops.': function it_should_also_work_with_mixed_multi_graphs_and_self_loops() {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.mergeEdge('A', 'B');
|
||||
graph.mergeEdge('A', 'B');
|
||||
graph.mergeEdge('B', 'A');
|
||||
graph.mergeEdge('A', 'B');
|
||||
graph.mergeEdge('A', 'A');
|
||||
graph.mergeUndirectedEdge('A', 'B');
|
||||
graph.mergeUndirectedEdge('A', 'B');
|
||||
graph.mergeUndirectedEdge('A', 'A');
|
||||
var copy = graph.copy();
|
||||
graph.dropNode('B');
|
||||
_assert["default"].strictEqual(graph.size, 2);
|
||||
_assert["default"].strictEqual(graph.directedSelfLoopCount, 1);
|
||||
_assert["default"].strictEqual(graph.undirectedSelfLoopCount, 1);
|
||||
copy.dropNode('A');
|
||||
_assert["default"].strictEqual(copy.size, 0);
|
||||
_assert["default"].strictEqual(copy.directedSelfLoopCount, 0);
|
||||
_assert["default"].strictEqual(copy.undirectedSelfLoopCount, 0);
|
||||
},
|
||||
'it should also coerce keys as strings.': function it_should_also_coerce_keys_as_strings() {
|
||||
function Key(name) {
|
||||
this.name = name;
|
||||
}
|
||||
Key.prototype.toString = function () {
|
||||
return this.name;
|
||||
};
|
||||
var graph = new Graph();
|
||||
var key = new Key('test');
|
||||
graph.addNode(key);
|
||||
graph.dropNode(key);
|
||||
_assert["default"].strictEqual(graph.order, 0);
|
||||
_assert["default"].strictEqual(graph.hasNode(key), false);
|
||||
}
|
||||
},
|
||||
'#.dropDirectedEdge': {
|
||||
'it should throw if given incorrect arguments.': function it_should_throw_if_given_incorrect_arguments() {
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.mergeEdge('a', 'b');
|
||||
graph.dropDirectedEdge('a', 'b');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.mergeEdgeWithKey('1', 'a', 'b');
|
||||
graph.dropDirectedEdge('1');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph();
|
||||
graph.dropDirectedEdge('a', 'b');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly drop the relevant edge.': function it_should_correctly_drop_the_relevant_edge() {
|
||||
var graph = new Graph();
|
||||
graph.mergeUndirectedEdge('a', 'b');
|
||||
graph.mergeDirectedEdge('a', 'b');
|
||||
graph.dropDirectedEdge('a', 'b');
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('a', 'b'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('a', 'b'), true);
|
||||
}
|
||||
},
|
||||
'#.dropUndirectedEdge': {
|
||||
'it should throw if given incorrect arguments.': function it_should_throw_if_given_incorrect_arguments() {
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
multi: true,
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.mergeEdge('a', 'b');
|
||||
graph.dropUndirectedEdge('a', 'b');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
multi: true,
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.mergeEdgeWithKey('1', 'a', 'b');
|
||||
graph.dropUndirectedEdge('1');
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.dropUndirectedEdge('a', 'b');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly drop the relevant edge.': function it_should_correctly_drop_the_relevant_edge() {
|
||||
var graph = new Graph();
|
||||
graph.mergeUndirectedEdge('a', 'b');
|
||||
graph.mergeDirectedEdge('a', 'b');
|
||||
graph.dropUndirectedEdge('a', 'b');
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 0);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('a', 'b'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('a', 'b'), true);
|
||||
}
|
||||
},
|
||||
'#.clear': {
|
||||
'it should empty the graph.': function it_should_empty_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Lindsay', 'Martha']);
|
||||
var edge = graph.addEdge('Lindsay', 'Martha');
|
||||
graph.clear();
|
||||
_assert["default"].strictEqual(graph.order, 0);
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.hasNode('Lindsay'), false);
|
||||
_assert["default"].strictEqual(graph.hasNode('Martha'), false);
|
||||
_assert["default"].strictEqual(graph.hasEdge(edge), false);
|
||||
},
|
||||
'it should be possible to use the graph normally afterwards.': function it_should_be_possible_to_use_the_graph_normally_afterwards() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Lindsay', 'Martha']);
|
||||
graph.addEdge('Lindsay', 'Martha');
|
||||
graph.clear();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Lindsay', 'Martha']);
|
||||
var edge = graph.addEdge('Lindsay', 'Martha');
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasNode('Lindsay'), true);
|
||||
_assert["default"].strictEqual(graph.hasNode('Martha'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge(edge), true);
|
||||
}
|
||||
},
|
||||
'#.clearEdges': {
|
||||
'it should drop every edge from the graph.': function it_should_drop_every_edge_from_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Lindsay', 'Martha']);
|
||||
var edge = graph.addEdge('Lindsay', 'Martha');
|
||||
graph.clearEdges();
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
_assert["default"].strictEqual(graph.hasNode('Lindsay'), true);
|
||||
_assert["default"].strictEqual(graph.hasNode('Martha'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge(edge), false);
|
||||
},
|
||||
'it should properly reset instance counters.': function it_should_properly_reset_instance_counters() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge(0, 1);
|
||||
_assert["default"].strictEqual(graph.directedSize, 1);
|
||||
graph.clearEdges();
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
graph.mergeEdge(0, 1);
|
||||
graph.clear();
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
},
|
||||
'it should properly clear node indices, regarding self loops notably.': function it_should_properly_clear_node_indices_regarding_self_loops_notably() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge(1, 1);
|
||||
_assert["default"].strictEqual(graph.degree(1), 2);
|
||||
graph.clearEdges();
|
||||
_assert["default"].strictEqual(graph.degree(1), 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
173
web/node_modules/graphology/specs/properties.js
generated
vendored
Normal file
173
web/node_modules/graphology/specs/properties.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = properties;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /**
|
||||
* Graphology Properties Specs
|
||||
* ============================
|
||||
*
|
||||
* Testing the properties of the graph.
|
||||
*/
|
||||
var PROPERTIES = ['order', 'size', 'directedSize', 'undirectedSize', 'type', 'multi', 'allowSelfLoops', 'implementation', 'selfLoopCount', 'directedSelfLoopCount', 'undirectedSelfLoopCount'];
|
||||
function properties(Graph) {
|
||||
return {
|
||||
/**
|
||||
* Regarding all properties.
|
||||
*/
|
||||
misc: {
|
||||
'all expected properties should be set.': function all_expected_properties_should_be_set() {
|
||||
var graph = new Graph();
|
||||
PROPERTIES.forEach(function (property) {
|
||||
(0, _assert["default"])(property in graph, property);
|
||||
});
|
||||
},
|
||||
'properties should be read-only.': function properties_should_be_readOnly() {
|
||||
var graph = new Graph();
|
||||
|
||||
// Attempting to mutate the properties
|
||||
PROPERTIES.forEach(function (property) {
|
||||
_assert["default"]["throws"](function () {
|
||||
graph[property] = 'test';
|
||||
}, TypeError);
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Order.
|
||||
*/
|
||||
'#.order': {
|
||||
'it should be 0 if the graph is empty.': function it_should_be_0_if_the_graph_is_empty() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.order, 0);
|
||||
},
|
||||
'adding nodes should increase order.': function adding_nodes_should_increase_order() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Jack');
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Size.
|
||||
*/
|
||||
'#.size': {
|
||||
'it should be 0 if the graph is empty.': function it_should_be_0_if_the_graph_is_empty() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
},
|
||||
'adding & dropping edges should affect size.': function adding__dropping_edges_should_affect_size() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Jack');
|
||||
graph.addDirectedEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
graph.dropEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.size, 0);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Directed Size.
|
||||
*/
|
||||
'#.directedSize': {
|
||||
'it should be 0 if the graph is empty.': function it_should_be_0_if_the_graph_is_empty() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
},
|
||||
'adding & dropping edges should affect directed size.': function adding__dropping_edges_should_affect_directed_size() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Jack');
|
||||
var directedEdge = graph.addDirectedEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.directedSize, 1);
|
||||
var undirectedEdge = graph.addUndirectedEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.directedSize, 1);
|
||||
graph.dropEdge(directedEdge);
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
graph.dropEdge(undirectedEdge);
|
||||
_assert["default"].strictEqual(graph.directedSize, 0);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Undirected Size.
|
||||
*/
|
||||
'#.undirectedSize': {
|
||||
'it should be 0 if the graph is empty.': function it_should_be_0_if_the_graph_is_empty() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 0);
|
||||
},
|
||||
'adding & dropping edges should affect undirected size.': function adding__dropping_edges_should_affect_undirected_size() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Jack');
|
||||
var directedEdge = graph.addDirectedEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 0);
|
||||
var undirectedEdge = graph.addUndirectedEdge('John', 'Jack');
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 1);
|
||||
graph.dropEdge(directedEdge);
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 1);
|
||||
graph.dropEdge(undirectedEdge);
|
||||
_assert["default"].strictEqual(graph.undirectedSize, 0);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Multi.
|
||||
*/
|
||||
'#.multi': {
|
||||
'it should be false by default.': function it_should_be_false_by_default() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.multi, false);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Type.
|
||||
*/
|
||||
'#.type': {
|
||||
'it should be "mixed" by default.': function it_should_be_Mixed_by_default() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.type, 'mixed');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Self loops.
|
||||
*/
|
||||
'#.allowSelfLoops': {
|
||||
'it should be true by default.': function it_should_be_true_by_default() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.allowSelfLoops, true);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Implementation.
|
||||
*/
|
||||
'#.implementation': {
|
||||
'it should exist and be a string.': function it_should_exist_and_be_a_string() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(_typeof(graph.implementation), 'string');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Self Loop Count.
|
||||
*/
|
||||
'#.selfLoopCount': {
|
||||
'it should exist and be correct.': function it_should_exist_and_be_correct() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('John', 'John');
|
||||
graph.mergeDirectedEdge('Lucy', 'Lucy');
|
||||
graph.mergeUndirectedEdge('Joana', 'Joana');
|
||||
_assert["default"].strictEqual(graph.selfLoopCount, 3);
|
||||
_assert["default"].strictEqual(graph.directedSelfLoopCount, 2);
|
||||
_assert["default"].strictEqual(graph.undirectedSelfLoopCount, 1);
|
||||
graph.forEachEdge(function (edge) {
|
||||
return graph.dropEdge(edge);
|
||||
});
|
||||
_assert["default"].strictEqual(graph.selfLoopCount, 0);
|
||||
_assert["default"].strictEqual(graph.directedSelfLoopCount, 0);
|
||||
_assert["default"].strictEqual(graph.undirectedSelfLoopCount, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
772
web/node_modules/graphology/specs/read.js
generated
vendored
Normal file
772
web/node_modules/graphology/specs/read.js
generated
vendored
Normal file
@@ -0,0 +1,772 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = read;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Read Specs
|
||||
* ======================
|
||||
*
|
||||
* Testing the read methods of the graph.
|
||||
*/
|
||||
|
||||
function read(Graph, checkers) {
|
||||
var invalid = checkers.invalid,
|
||||
notFound = checkers.notFound,
|
||||
usage = checkers.usage;
|
||||
return {
|
||||
'#.hasNode': {
|
||||
'it should correctly return whether the given node is found in the graph.': function it_should_correctly_return_whether_the_given_node_is_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"].strictEqual(graph.hasNode('John'), false);
|
||||
graph.addNode('John');
|
||||
_assert["default"].strictEqual(graph.hasNode('John'), true);
|
||||
}
|
||||
},
|
||||
'#.hasDirectedEdge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.hasDirectedEdge(1, 2, 3);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly return whether a matching edge exists in the graph.': function it_should_correctly_return_whether_a_matching_edge_exists_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
graph.addNode('Catherine');
|
||||
graph.addNode('John');
|
||||
graph.addDirectedEdgeWithKey('M->C', 'Martha', 'Catherine');
|
||||
graph.addUndirectedEdgeWithKey('C<->J', 'Catherine', 'John');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('M->C'), true);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('C<->J'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('test'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Martha', 'Catherine'), true);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Martha', 'Thomas'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Catherine', 'John'), false);
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('John', 'Catherine'), false);
|
||||
},
|
||||
'it should work with self loops.': function it_should_work_with_self_loops() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Lucy', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Lucy', 'Lucy'), true);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Lucy', 'Lucy'), false);
|
||||
}
|
||||
},
|
||||
'#.hasUndirectedEdge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.hasUndirectedEdge(1, 2, 3);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly return whether a matching edge exists in the graph.': function it_should_correctly_return_whether_a_matching_edge_exists_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
graph.addNode('Catherine');
|
||||
graph.addNode('John');
|
||||
graph.addDirectedEdgeWithKey('M->C', 'Martha', 'Catherine');
|
||||
graph.addUndirectedEdgeWithKey('C<->J', 'Catherine', 'John');
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('M->C'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('C<->J'), true);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('test'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Martha', 'Catherine'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Martha', 'Thomas'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Catherine', 'John'), true);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('John', 'Catherine'), true);
|
||||
},
|
||||
'it should work with self loops.': function it_should_work_with_self_loops() {
|
||||
var graph = new Graph();
|
||||
graph.mergeUndirectedEdge('Lucy', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Lucy', 'Lucy'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Lucy', 'Lucy'), true);
|
||||
}
|
||||
},
|
||||
'#.hasEdge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.hasEdge(1, 2, 3);
|
||||
}, invalid());
|
||||
},
|
||||
'it should correctly return whether a matching edge exists in the graph.': function it_should_correctly_return_whether_a_matching_edge_exists_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Martha');
|
||||
graph.addNode('Catherine');
|
||||
graph.addNode('John');
|
||||
graph.addDirectedEdgeWithKey('M->C', 'Martha', 'Catherine');
|
||||
graph.addUndirectedEdgeWithKey('C<->J', 'Catherine', 'John');
|
||||
_assert["default"].strictEqual(graph.hasEdge('M->C'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('C<->J'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('test'), false);
|
||||
_assert["default"].strictEqual(graph.hasEdge('Martha', 'Catherine'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('Martha', 'Thomas'), false);
|
||||
_assert["default"].strictEqual(graph.hasEdge('Catherine', 'John'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Catherine'), true);
|
||||
},
|
||||
'it should work properly with typed graphs.': function it_should_work_properly_with_typed_graphs() {
|
||||
var directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
}),
|
||||
undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(directedGraph, [1, 2]);
|
||||
(0, _helpers.addNodesFrom)(undirectedGraph, [1, 2]);
|
||||
_assert["default"].strictEqual(directedGraph.hasEdge(1, 2), false);
|
||||
_assert["default"].strictEqual(undirectedGraph.hasEdge(1, 2), false);
|
||||
},
|
||||
'it should work with self loops.': function it_should_work_with_self_loops() {
|
||||
var graph = new Graph();
|
||||
graph.mergeUndirectedEdge('Lucy', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.hasDirectedEdge('Lucy', 'Lucy'), false);
|
||||
_assert["default"].strictEqual(graph.hasUndirectedEdge('Lucy', 'Lucy'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge('Lucy', 'Lucy'), true);
|
||||
},
|
||||
'it should work with multi graphs (issue #431).': function it_should_work_with_multi_graphs_Issue_431() {
|
||||
var graph = new Graph({
|
||||
multi: true,
|
||||
type: 'directed'
|
||||
});
|
||||
var na = graph.addNode('A');
|
||||
var nb = graph.addNode('B');
|
||||
var eid = graph.addEdge('A', 'B');
|
||||
_assert["default"].strictEqual(graph.hasEdge('A', 'B'), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge(na, nb), true);
|
||||
_assert["default"].strictEqual(graph.hasEdge(eid), true);
|
||||
}
|
||||
},
|
||||
'#.directedEdge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph(),
|
||||
multiGraph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
multiGraph.directedEdge(1, 2);
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.directedEdge('Jack', 'John');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.directedEdge('John', 'Jack');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct edge.': function it_should_return_the_correct_edge() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Jack', 'Lucy']);
|
||||
graph.addDirectedEdgeWithKey('J->L', 'Jack', 'Lucy');
|
||||
graph.addUndirectedEdgeWithKey('J<->L', 'Jack', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.directedEdge('Lucy', 'Jack'), undefined);
|
||||
_assert["default"].strictEqual(graph.directedEdge('Jack', 'Lucy'), 'J->L');
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Jack', 'Lucy');
|
||||
_assert["default"].strictEqual(undirectedGraph.directedEdge('Jack', 'Lucy'), undefined);
|
||||
},
|
||||
'it should return the correct self loop.': function it_should_return_the_correct_self_loop() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addEdgeWithKey('d', 'John', 'John');
|
||||
graph.addUndirectedEdgeWithKey('u', 'John', 'John');
|
||||
_assert["default"].strictEqual(graph.directedEdge('John', 'John'), 'd');
|
||||
}
|
||||
},
|
||||
'#.undirectedEdge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph(),
|
||||
multiGraph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
multiGraph.undirectedEdge(1, 2);
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.undirectedEdge('Jack', 'John');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.undirectedEdge('John', 'Jack');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct edge.': function it_should_return_the_correct_edge() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Jack', 'Lucy']);
|
||||
graph.addDirectedEdgeWithKey('J->L', 'Jack', 'Lucy');
|
||||
graph.addUndirectedEdgeWithKey('J<->L', 'Jack', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.undirectedEdge('Lucy', 'Jack'), 'J<->L');
|
||||
_assert["default"].strictEqual(graph.undirectedEdge('Jack', 'Lucy'), 'J<->L');
|
||||
var directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
directedGraph.mergeEdge('Jack', 'Lucy');
|
||||
_assert["default"].strictEqual(directedGraph.undirectedEdge('Jack', 'Lucy'), undefined);
|
||||
},
|
||||
'it should return the correct self loop.': function it_should_return_the_correct_self_loop() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addEdgeWithKey('d', 'John', 'John');
|
||||
graph.addUndirectedEdgeWithKey('u', 'John', 'John');
|
||||
_assert["default"].strictEqual(graph.undirectedEdge('John', 'John'), 'u');
|
||||
}
|
||||
},
|
||||
'#.edge': {
|
||||
'it should throw if invalid arguments are provided.': function it_should_throw_if_invalid_arguments_are_provided() {
|
||||
var graph = new Graph(),
|
||||
multiGraph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.addNode('John');
|
||||
_assert["default"]["throws"](function () {
|
||||
multiGraph.edge(1, 2);
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.edge('Jack', 'John');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.edge('John', 'Jack');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct edge.': function it_should_return_the_correct_edge() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Jack', 'Lucy']);
|
||||
graph.addDirectedEdgeWithKey('J->L', 'Jack', 'Lucy');
|
||||
graph.addUndirectedEdgeWithKey('J<->L', 'Jack', 'Lucy');
|
||||
_assert["default"].strictEqual(graph.edge('Lucy', 'Jack'), 'J<->L');
|
||||
_assert["default"].strictEqual(graph.edge('Jack', 'Lucy'), 'J->L');
|
||||
},
|
||||
'it should return the correct self loop.': function it_should_return_the_correct_self_loop() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addEdgeWithKey('d', 'John', 'John');
|
||||
graph.addUndirectedEdgeWithKey('u', 'John', 'John');
|
||||
_assert["default"].strictEqual(graph.edge('John', 'John'), 'd');
|
||||
}
|
||||
},
|
||||
'#.areDirectedNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areDirectedNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areDirectedNeighbors('Mary', 'Joseph'), true);
|
||||
_assert["default"].strictEqual(graph.areDirectedNeighbors('Joseph', 'Mary'), true);
|
||||
_assert["default"].strictEqual(graph.areDirectedNeighbors('Martha', 'Mary'), false);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areDirectedNeighbors('Mary', 'Martha'), false);
|
||||
}
|
||||
},
|
||||
'#.areInNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areInNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areInNeighbors('Mary', 'Joseph'), false);
|
||||
_assert["default"].strictEqual(graph.areInNeighbors('Joseph', 'Mary'), true);
|
||||
_assert["default"].strictEqual(graph.areInNeighbors('Martha', 'Mary'), false);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areInNeighbors('Mary', 'Martha'), false);
|
||||
}
|
||||
},
|
||||
'#.areOutNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areOutNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areOutNeighbors('Mary', 'Joseph'), true);
|
||||
_assert["default"].strictEqual(graph.areOutNeighbors('Joseph', 'Mary'), false);
|
||||
_assert["default"].strictEqual(graph.areOutNeighbors('Martha', 'Mary'), false);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areOutNeighbors('Mary', 'Martha'), false);
|
||||
}
|
||||
},
|
||||
'#.areOutboundNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areOutboundNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areOutboundNeighbors('Mary', 'Joseph'), true);
|
||||
_assert["default"].strictEqual(graph.areOutboundNeighbors('Joseph', 'Mary'), false);
|
||||
_assert["default"].strictEqual(graph.areOutboundNeighbors('Martha', 'Mary'), true);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areOutboundNeighbors('Mary', 'Martha'), true);
|
||||
}
|
||||
},
|
||||
'#.areInboundNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areInboundNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areInboundNeighbors('Mary', 'Joseph'), false);
|
||||
_assert["default"].strictEqual(graph.areInboundNeighbors('Joseph', 'Mary'), true);
|
||||
_assert["default"].strictEqual(graph.areInboundNeighbors('Martha', 'Mary'), true);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areInboundNeighbors('Mary', 'Martha'), true);
|
||||
}
|
||||
},
|
||||
'#.areUndirectedNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areUndirectedNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areUndirectedNeighbors('Mary', 'Joseph'), false);
|
||||
_assert["default"].strictEqual(graph.areUndirectedNeighbors('Joseph', 'Mary'), false);
|
||||
_assert["default"].strictEqual(graph.areUndirectedNeighbors('Martha', 'Mary'), true);
|
||||
var directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
directedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(directedGraph.areUndirectedNeighbors('Mary', 'Martha'), false);
|
||||
}
|
||||
},
|
||||
'#.areNeighbors': {
|
||||
'it should throw if node is not in the graph.': function it_should_throw_if_node_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.areNeighbors('source', 'target');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether two nodes are neighbors.': function it_should_correctly_return_whether_two_nodes_are_neighbors() {
|
||||
var graph = new Graph();
|
||||
graph.mergeDirectedEdge('Mary', 'Joseph');
|
||||
graph.mergeUndirectedEdge('Martha', 'Mary');
|
||||
_assert["default"].strictEqual(graph.areNeighbors('Mary', 'Joseph'), true);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('Joseph', 'Mary'), true);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('Martha', 'Mary'), true);
|
||||
_assert["default"].strictEqual(graph.areNeighbors('Joseph', 'Martha'), false);
|
||||
var undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
undirectedGraph.mergeEdge('Mary', 'Martha');
|
||||
_assert["default"].strictEqual(undirectedGraph.areNeighbors('Mary', 'Martha'), true);
|
||||
}
|
||||
},
|
||||
'#.source': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.source('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct source.': function it_should_return_the_correct_source() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addDirectedEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.source(edge), 'John');
|
||||
}
|
||||
},
|
||||
'#.target': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.target('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct target.': function it_should_return_the_correct_target() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addDirectedEdge('John', 'Martha');
|
||||
_assert["default"].strictEqual(graph.target(edge), 'Martha');
|
||||
}
|
||||
},
|
||||
'#.extremities': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.extremities('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct extremities.': function it_should_return_the_correct_extremities() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Martha');
|
||||
var edge = graph.addDirectedEdge('John', 'Martha');
|
||||
_assert["default"].deepStrictEqual(graph.extremities(edge), ['John', 'Martha']);
|
||||
}
|
||||
},
|
||||
'#.opposite': {
|
||||
'it should throw if either the node or the edge is not found in the graph.': function it_should_throw_if_either_the_node_or_the_edge_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Thomas');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.opposite('Jeremy', 'T->J');
|
||||
}, notFound());
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.opposite('Thomas', 'T->J');
|
||||
}, notFound());
|
||||
},
|
||||
'it should throw if the node & the edge are not related.': function it_should_throw_if_the_node__the_edge_are_not_related() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Thomas', 'Isabella', 'Estelle']);
|
||||
graph.addEdgeWithKey('I->E', 'Isabella', 'Estelle');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.opposite('Thomas', 'I->E');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct node.': function it_should_return_the_correct_node() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Thomas', 'Estelle']);
|
||||
var edge = graph.addEdge('Thomas', 'Estelle');
|
||||
_assert["default"].strictEqual(graph.opposite('Thomas', edge), 'Estelle');
|
||||
}
|
||||
},
|
||||
'#.hasExtremity': {
|
||||
'it should throw if either the edge is not found in the graph.': function it_should_throw_if_either_the_edge_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge('Thomas', 'Laura');
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.hasExtremity('inexisting-edge', 'Thomas');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct answer.': function it_should_return_the_correct_answer() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('Jack');
|
||||
var _graph$mergeEdge = graph.mergeEdge('Thomas', 'Estelle'),
|
||||
edge = _graph$mergeEdge[0];
|
||||
_assert["default"].strictEqual(graph.hasExtremity(edge, 'Thomas'), true);
|
||||
_assert["default"].strictEqual(graph.hasExtremity(edge, 'Estelle'), true);
|
||||
_assert["default"].strictEqual(graph.hasExtremity(edge, 'Jack'), false);
|
||||
_assert["default"].strictEqual(graph.hasExtremity(edge, 'Who?'), false);
|
||||
}
|
||||
},
|
||||
'#.isDirected': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.isDirected('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether the edge is directed or not.': function it_should_correctly_return_whether_the_edge_is_directed_or_not() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Rachel');
|
||||
graph.addNode('Suzan');
|
||||
var directedEdge = graph.addDirectedEdge('John', 'Rachel'),
|
||||
undirectedEdge = graph.addUndirectedEdge('Rachel', 'Suzan');
|
||||
_assert["default"].strictEqual(graph.isDirected(directedEdge), true);
|
||||
_assert["default"].strictEqual(graph.isDirected(undirectedEdge), false);
|
||||
}
|
||||
},
|
||||
'#.isUndirected': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.isUndirected('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether the edge is undirected or not.': function it_should_correctly_return_whether_the_edge_is_undirected_or_not() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Rachel');
|
||||
graph.addNode('Suzan');
|
||||
var directedEdge = graph.addDirectedEdge('John', 'Rachel'),
|
||||
undirectedEdge = graph.addUndirectedEdge('Rachel', 'Suzan');
|
||||
_assert["default"].strictEqual(graph.isUndirected(directedEdge), false);
|
||||
_assert["default"].strictEqual(graph.isUndirected(undirectedEdge), true);
|
||||
}
|
||||
},
|
||||
'#.isSelfLoop': {
|
||||
'it should throw if the edge is not in the graph.': function it_should_throw_if_the_edge_is_not_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.isSelfLoop('test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should correctly return whether the edge is a self-loop or not.': function it_should_correctly_return_whether_the_edge_is_a_selfLoop_or_not() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('John');
|
||||
graph.addNode('Rachel');
|
||||
var selfLoop = graph.addDirectedEdge('John', 'John'),
|
||||
edge = graph.addUndirectedEdge('John', 'Rachel');
|
||||
_assert["default"].strictEqual(graph.isSelfLoop(selfLoop), true);
|
||||
_assert["default"].strictEqual(graph.isSelfLoop(edge), false);
|
||||
}
|
||||
},
|
||||
Degree: {
|
||||
'#.inDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.inDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct in degree.': function it_should_return_the_correct_in_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('William', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inDegree('Sue'), 2);
|
||||
graph.addDirectedEdge('Sue', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inDegree('Sue'), 3);
|
||||
_assert["default"].strictEqual(graph.inDegreeWithoutSelfLoops('Sue'), 2);
|
||||
},
|
||||
'it should always return 0 in an undirected graph.': function it_should_always_return_0_in_an_undirected_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inDegree('Helen'), 0);
|
||||
}
|
||||
},
|
||||
'#.inboundDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.inboundDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct in degree.': function it_should_return_the_correct_in_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('William', 'Sue');
|
||||
graph.addUndirectedEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inboundDegree('Sue'), 3);
|
||||
graph.addDirectedEdge('Sue', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inboundDegree('Sue'), 4);
|
||||
_assert["default"].strictEqual(graph.inboundDegreeWithoutSelfLoops('Sue'), 3);
|
||||
},
|
||||
'it should always the undirected degree in an undirected graph.': function it_should_always_the_undirected_degree_in_an_undirected_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inboundDegree('Helen'), 1);
|
||||
}
|
||||
},
|
||||
'#.outDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.outDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct out degree.': function it_should_return_the_correct_out_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('Helen', 'William');
|
||||
_assert["default"].strictEqual(graph.outDegree('Helen'), 2);
|
||||
graph.addDirectedEdge('Helen', 'Helen');
|
||||
_assert["default"].strictEqual(graph.outDegree('Helen'), 3);
|
||||
_assert["default"].strictEqual(graph.outDegreeWithoutSelfLoops('Helen'), 2);
|
||||
},
|
||||
'it should always return 0 in an undirected graph.': function it_should_always_return_0_in_an_undirected_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.outDegree('Sue'), 0);
|
||||
}
|
||||
},
|
||||
'#.outboundDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.outboundDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct out degree.': function it_should_return_the_correct_out_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('Helen', 'William');
|
||||
graph.addUndirectedEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.outboundDegree('Helen'), 3);
|
||||
graph.addDirectedEdge('Helen', 'Helen');
|
||||
_assert["default"].strictEqual(graph.outboundDegree('Helen'), 4);
|
||||
_assert["default"].strictEqual(graph.outboundDegreeWithoutSelfLoops('Helen'), 3);
|
||||
},
|
||||
'it should always the undirected degree in an undirected graph.': function it_should_always_the_undirected_degree_in_an_undirected_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.outboundDegree('Sue'), 1);
|
||||
}
|
||||
},
|
||||
'#.directedDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.directedDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct directed degree.': function it_should_return_the_correct_directed_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John', 'Martha']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('Helen', 'William');
|
||||
graph.addDirectedEdge('Martha', 'Helen');
|
||||
graph.addUndirectedEdge('Helen', 'John');
|
||||
_assert["default"].strictEqual(graph.directedDegree('Helen'), 3);
|
||||
_assert["default"].strictEqual(graph.directedDegree('Helen'), graph.inDegree('Helen') + graph.outDegree('Helen'));
|
||||
graph.addDirectedEdge('Helen', 'Helen');
|
||||
_assert["default"].strictEqual(graph.directedDegree('Helen'), 5);
|
||||
_assert["default"].strictEqual(graph.directedDegreeWithoutSelfLoops('Helen'), 3);
|
||||
},
|
||||
'it should always return 0 in an undirected graph.': function it_should_always_return_0_in_an_undirected_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.inDegree('Helen'), 0);
|
||||
}
|
||||
},
|
||||
'#.undirectedDegree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.undirectedDegree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct undirected degree.': function it_should_return_the_correct_undirected_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('Helen', 'William');
|
||||
graph.addUndirectedEdge('Helen', 'John');
|
||||
_assert["default"].strictEqual(graph.undirectedDegree('Helen'), 1);
|
||||
graph.addUndirectedEdge('Helen', 'Helen');
|
||||
_assert["default"].strictEqual(graph.undirectedDegree('Helen'), 3);
|
||||
_assert["default"].strictEqual(graph.undirectedDegreeWithoutSelfLoops('Helen'), 1);
|
||||
},
|
||||
'it should always return 0 in a directed graph.': function it_should_always_return_0_in_a_directed_graph() {
|
||||
var graph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue']);
|
||||
graph.addEdge('Helen', 'Sue');
|
||||
_assert["default"].strictEqual(graph.undirectedDegree('Helen'), 0);
|
||||
}
|
||||
},
|
||||
'#.degree': {
|
||||
'it should throw if the node is not found in the graph.': function it_should_throw_if_the_node_is_not_found_in_the_graph() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph.degree('Test');
|
||||
}, notFound());
|
||||
},
|
||||
'it should return the correct degree.': function it_should_return_the_correct_degree() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['Helen', 'Sue', 'William', 'John', 'Martha']);
|
||||
graph.addDirectedEdge('Helen', 'Sue');
|
||||
graph.addDirectedEdge('Helen', 'William');
|
||||
graph.addDirectedEdge('Martha', 'Helen');
|
||||
graph.addUndirectedEdge('Helen', 'John');
|
||||
_assert["default"].strictEqual(graph.degree('Helen'), 4);
|
||||
_assert["default"].strictEqual(graph.degree('Helen'), graph.directedDegree('Helen') + graph.undirectedDegree('Helen'));
|
||||
graph.addUndirectedEdge('Helen', 'Helen');
|
||||
_assert["default"].strictEqual(graph.degree('Helen'), 6);
|
||||
_assert["default"].strictEqual(graph.degreeWithoutSelfLoops('Helen'), 4);
|
||||
}
|
||||
},
|
||||
'it should also work with typed graphs.': function it_should_also_work_with_typed_graphs() {
|
||||
var directedGraph = new Graph({
|
||||
type: 'directed'
|
||||
}),
|
||||
undirectedGraph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
(0, _helpers.addNodesFrom)(directedGraph, [1, 2]);
|
||||
(0, _helpers.addNodesFrom)(undirectedGraph, [1, 2]);
|
||||
_assert["default"].strictEqual(directedGraph.degree(1), 0);
|
||||
_assert["default"].strictEqual(undirectedGraph.degree(1), 0);
|
||||
directedGraph.addDirectedEdge(1, 2);
|
||||
undirectedGraph.addUndirectedEdge(1, 2);
|
||||
_assert["default"].strictEqual(directedGraph.degree(1), 1);
|
||||
_assert["default"].strictEqual(undirectedGraph.degree(1), 1);
|
||||
},
|
||||
'it should correctly consider self loops in the multi case (issue #431).': function it_should_correctly_consider_self_loops_in_the_multi_case_Issue_431() {
|
||||
var multiGraph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
multiGraph.mergeDirectedEdge(0, 1);
|
||||
multiGraph.mergeDirectedEdge(0, 1);
|
||||
multiGraph.mergeDirectedEdge(1, 0);
|
||||
multiGraph.mergeUndirectedEdge(0, 1);
|
||||
multiGraph.mergeUndirectedEdge(0, 1);
|
||||
multiGraph.mergeDirectedEdge(2, 0);
|
||||
multiGraph.mergeDirectedEdge(0, 3);
|
||||
multiGraph.mergeUndirectedEdge(0, 3);
|
||||
multiGraph.mergeDirectedEdge(0, 0);
|
||||
multiGraph.mergeDirectedEdge(0, 0);
|
||||
multiGraph.mergeDirectedEdge(0, 0);
|
||||
multiGraph.mergeUndirectedEdge(0, 0);
|
||||
multiGraph.mergeUndirectedEdge(0, 0);
|
||||
_assert["default"].strictEqual(multiGraph.degree(0), 18);
|
||||
_assert["default"].strictEqual(multiGraph.directedDegree(0), 11);
|
||||
_assert["default"].strictEqual(multiGraph.undirectedDegree(0), 7);
|
||||
_assert["default"].strictEqual(multiGraph.outDegree(0), 6);
|
||||
_assert["default"].strictEqual(multiGraph.inDegree(0), 5);
|
||||
_assert["default"].strictEqual(multiGraph.degreeWithoutSelfLoops(0), 8);
|
||||
_assert["default"].strictEqual(multiGraph.directedDegreeWithoutSelfLoops(0), 5);
|
||||
_assert["default"].strictEqual(multiGraph.undirectedDegreeWithoutSelfLoops(0), 3);
|
||||
_assert["default"].strictEqual(multiGraph.outDegreeWithoutSelfLoops(0), 3);
|
||||
_assert["default"].strictEqual(multiGraph.inDegreeWithoutSelfLoops(0), 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
204
web/node_modules/graphology/specs/serialization.js
generated
vendored
Normal file
204
web/node_modules/graphology/specs/serialization.js
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = serialization;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Serializaton Specs
|
||||
* ==============================
|
||||
*
|
||||
* Testing the serialization methods of the graph.
|
||||
*/
|
||||
|
||||
function serialization(Graph, checkers) {
|
||||
var invalid = checkers.invalid,
|
||||
notFound = checkers.notFound;
|
||||
return {
|
||||
'#.export': {
|
||||
'it should correctly return the serialized graph.': function it_should_correctly_return_the_serialized_graph() {
|
||||
var graph = new Graph({
|
||||
multi: true
|
||||
});
|
||||
graph.setAttribute('name', 'graph');
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Jack', 'Martha']);
|
||||
graph.setNodeAttribute('John', 'age', 34);
|
||||
graph.addEdgeWithKey('J->J•1', 'John', 'Jack');
|
||||
graph.addEdgeWithKey('J->J•2', 'John', 'Jack', {
|
||||
weight: 2
|
||||
});
|
||||
graph.addEdgeWithKey('J->J•3', 'John', 'Jack');
|
||||
graph.addUndirectedEdgeWithKey('J<->J•1', 'John', 'Jack');
|
||||
graph.addUndirectedEdgeWithKey('J<->J•2', 'John', 'Jack', {
|
||||
weight: 3
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph["export"](), {
|
||||
attributes: {
|
||||
name: 'graph'
|
||||
},
|
||||
nodes: [{
|
||||
key: 'John',
|
||||
attributes: {
|
||||
age: 34
|
||||
}
|
||||
}, {
|
||||
key: 'Jack'
|
||||
}, {
|
||||
key: 'Martha'
|
||||
}],
|
||||
edges: [{
|
||||
key: 'J->J•1',
|
||||
source: 'John',
|
||||
target: 'Jack'
|
||||
}, {
|
||||
key: 'J->J•2',
|
||||
source: 'John',
|
||||
target: 'Jack',
|
||||
attributes: {
|
||||
weight: 2
|
||||
}
|
||||
}, {
|
||||
key: 'J->J•3',
|
||||
source: 'John',
|
||||
target: 'Jack'
|
||||
}, {
|
||||
key: 'J<->J•1',
|
||||
source: 'John',
|
||||
target: 'Jack',
|
||||
undirected: true
|
||||
}, {
|
||||
key: 'J<->J•2',
|
||||
source: 'John',
|
||||
target: 'Jack',
|
||||
attributes: {
|
||||
weight: 3
|
||||
},
|
||||
undirected: true
|
||||
}],
|
||||
options: {
|
||||
allowSelfLoops: true,
|
||||
multi: true,
|
||||
type: 'mixed'
|
||||
}
|
||||
});
|
||||
},
|
||||
'it should not need to tell whether edges are undirected if the graph is.': function it_should_not_need_to_tell_whether_edges_are_undirected_if_the_graph_is() {
|
||||
var graph = new Graph({
|
||||
type: 'undirected'
|
||||
});
|
||||
graph.mergeEdgeWithKey(0, 1, 2);
|
||||
_assert["default"].deepStrictEqual(graph["export"](), {
|
||||
options: {
|
||||
type: 'undirected',
|
||||
multi: false,
|
||||
allowSelfLoops: true
|
||||
},
|
||||
attributes: {},
|
||||
nodes: [{
|
||||
key: '1'
|
||||
}, {
|
||||
key: '2'
|
||||
}],
|
||||
edges: [{
|
||||
key: '0',
|
||||
source: '1',
|
||||
target: '2'
|
||||
}]
|
||||
});
|
||||
}
|
||||
},
|
||||
'#.import': {
|
||||
'it should throw if the given data is invalid.': function it_should_throw_if_the_given_data_is_invalid() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph["import"](true);
|
||||
}, invalid());
|
||||
},
|
||||
'it should be possible to import a graph instance.': function it_should_be_possible_to_import_a_graph_instance() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdge('John', 'Thomas');
|
||||
var other = new Graph();
|
||||
other["import"](graph);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), other.nodes());
|
||||
_assert["default"].deepStrictEqual(graph.edges(), other.edges());
|
||||
},
|
||||
'it should be possible to import a serialized graph.': function it_should_be_possible_to_import_a_serialized_graph() {
|
||||
var graph = new Graph();
|
||||
graph["import"]({
|
||||
nodes: [{
|
||||
key: 'John'
|
||||
}, {
|
||||
key: 'Thomas'
|
||||
}],
|
||||
edges: [{
|
||||
source: 'John',
|
||||
target: 'Thomas'
|
||||
}]
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John', 'Thomas']);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Thomas'), true);
|
||||
},
|
||||
'it should be possible to import only edges when merging.': function it_should_be_possible_to_import_only_edges_when_merging() {
|
||||
var graph = new Graph();
|
||||
graph["import"]({
|
||||
edges: [{
|
||||
source: 'John',
|
||||
target: 'Thomas'
|
||||
}]
|
||||
}, true);
|
||||
_assert["default"].deepStrictEqual(graph.nodes(), ['John', 'Thomas']);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge('John', 'Thomas'), true);
|
||||
},
|
||||
'it should be possible to import attributes.': function it_should_be_possible_to_import_attributes() {
|
||||
var graph = new Graph();
|
||||
graph["import"]({
|
||||
attributes: {
|
||||
name: 'graph'
|
||||
}
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), {
|
||||
name: 'graph'
|
||||
});
|
||||
},
|
||||
'it should throw if nodes are absent, edges are present and we merge.': function it_should_throw_if_nodes_are_absent_edges_are_present_and_we_merge() {
|
||||
var graph = new Graph();
|
||||
_assert["default"]["throws"](function () {
|
||||
graph["import"]({
|
||||
edges: [{
|
||||
source: '1',
|
||||
target: '2'
|
||||
}]
|
||||
});
|
||||
}, notFound());
|
||||
},
|
||||
'it should import undirected graphs properly.': function it_should_import_undirected_graphs_properly() {
|
||||
var graph = Graph.from({
|
||||
options: {
|
||||
type: 'undirected',
|
||||
multi: false,
|
||||
allowSelfLoops: true
|
||||
},
|
||||
attributes: {},
|
||||
nodes: [{
|
||||
key: '1'
|
||||
}, {
|
||||
key: '2'
|
||||
}],
|
||||
edges: [{
|
||||
key: '0',
|
||||
source: '1',
|
||||
target: '2'
|
||||
}]
|
||||
});
|
||||
_assert["default"].strictEqual(graph.order, 2);
|
||||
_assert["default"].strictEqual(graph.size, 1);
|
||||
_assert["default"].strictEqual(graph.hasEdge(2, 1), true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
204
web/node_modules/graphology/specs/utils.js
generated
vendored
Normal file
204
web/node_modules/graphology/specs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = utils;
|
||||
var _assert = _interopRequireDefault(require("assert"));
|
||||
var _helpers = require("./helpers");
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
||||
/**
|
||||
* Graphology Utils Specs
|
||||
* =======================
|
||||
*
|
||||
* Testing the utils methods.
|
||||
*/
|
||||
|
||||
var PROPERTIES = ['type', 'multi', 'map', 'selfLoops'];
|
||||
function utils(Graph, checkers) {
|
||||
var usage = checkers.usage;
|
||||
return {
|
||||
'#.nullCopy': {
|
||||
'it should create an null copy of the graph.': function it_should_create_an_null_copy_of_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdge('John', 'Thomas');
|
||||
var copy = graph.nullCopy();
|
||||
_assert["default"].deepStrictEqual(copy.nodes(), []);
|
||||
_assert["default"].strictEqual(copy.order, 0);
|
||||
_assert["default"].strictEqual(copy.size, 0);
|
||||
PROPERTIES.forEach(function (property) {
|
||||
_assert["default"].strictEqual(graph[property], copy[property]);
|
||||
});
|
||||
},
|
||||
'it should be possible to pass options to merge.': function it_should_be_possible_to_pass_options_to_merge() {
|
||||
var graph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
var copy = graph.nullCopy({
|
||||
type: 'undirected'
|
||||
});
|
||||
_assert["default"].strictEqual(copy.type, 'undirected');
|
||||
_assert["default"]["throws"](function () {
|
||||
copy.addDirectedEdge('one', 'two');
|
||||
}, /addDirectedEdge/);
|
||||
},
|
||||
'copying the graph should conserve its attributes.': function copying_the_graph_should_conserve_its_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('title', 'The Graph');
|
||||
var copy = graph.nullCopy();
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), copy.getAttributes());
|
||||
}
|
||||
},
|
||||
'#.emptyCopy': {
|
||||
'it should create an empty copy of the graph.': function it_should_create_an_empty_copy_of_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdge('John', 'Thomas');
|
||||
var copy = graph.emptyCopy();
|
||||
_assert["default"].deepStrictEqual(copy.nodes(), ['John', 'Thomas']);
|
||||
_assert["default"].strictEqual(copy.order, 2);
|
||||
_assert["default"].strictEqual(copy.size, 0);
|
||||
PROPERTIES.forEach(function (property) {
|
||||
_assert["default"].strictEqual(graph[property], copy[property]);
|
||||
});
|
||||
copy.mergeEdge('Mary', 'Thomas');
|
||||
copy.setNodeAttribute('John', 'age', 32);
|
||||
_assert["default"].strictEqual(copy.order, 3);
|
||||
_assert["default"].strictEqual(copy.size, 1);
|
||||
_assert["default"].deepStrictEqual(copy.getNodeAttributes('John'), {
|
||||
age: 32
|
||||
});
|
||||
_assert["default"].deepStrictEqual(graph.getNodeAttributes('John'), {});
|
||||
},
|
||||
'it should be possible to pass options to merge.': function it_should_be_possible_to_pass_options_to_merge() {
|
||||
var graph = new Graph({
|
||||
type: 'directed'
|
||||
});
|
||||
var copy = graph.emptyCopy({
|
||||
type: 'undirected'
|
||||
});
|
||||
_assert["default"].strictEqual(copy.type, 'undirected');
|
||||
_assert["default"]["throws"](function () {
|
||||
copy.addDirectedEdge('one', 'two');
|
||||
}, /addDirectedEdge/);
|
||||
},
|
||||
'copying the graph should conserve its attributes.': function copying_the_graph_should_conserve_its_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('title', 'The Graph');
|
||||
var copy = graph.emptyCopy();
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), copy.getAttributes());
|
||||
}
|
||||
},
|
||||
'#.copy': {
|
||||
'it should create a full copy of the graph.': function it_should_create_a_full_copy_of_the_graph() {
|
||||
var graph = new Graph();
|
||||
(0, _helpers.addNodesFrom)(graph, ['John', 'Thomas']);
|
||||
graph.addEdge('John', 'Thomas');
|
||||
var copy = graph.copy();
|
||||
_assert["default"].deepStrictEqual(copy.nodes(), graph.nodes());
|
||||
_assert["default"].deepStrictEqual(copy.edges(), graph.edges());
|
||||
_assert["default"].strictEqual(copy.order, 2);
|
||||
_assert["default"].strictEqual(copy.size, 1);
|
||||
PROPERTIES.forEach(function (property) {
|
||||
_assert["default"].strictEqual(graph[property], graph[property]);
|
||||
});
|
||||
},
|
||||
'it should not break when copying a graph with wrangled edge ids (issue #213).': function it_should_not_break_when_copying_a_graph_with_wrangled_edge_ids_Issue_213() {
|
||||
var graph = new Graph();
|
||||
graph.addNode('n0');
|
||||
graph.addNode('n1');
|
||||
graph.addNode('n2');
|
||||
graph.addNode('n3');
|
||||
graph.addEdge('n0', 'n1');
|
||||
graph.addEdge('n1', 'n2');
|
||||
graph.addEdge('n2', 'n3');
|
||||
graph.addEdge('n3', 'n0');
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
graph.copy();
|
||||
});
|
||||
|
||||
// Do surgery on second edge
|
||||
var edgeToSplit = graph.edge('n1', 'n2');
|
||||
var newNode = 'n12';
|
||||
graph.addNode(newNode);
|
||||
graph.dropEdge('n1', 'n2');
|
||||
graph.addEdge('n1', newNode);
|
||||
graph.addEdgeWithKey(edgeToSplit, newNode, 'n2');
|
||||
var copy = graph.copy();
|
||||
_assert["default"].deepStrictEqual(new Set(graph.nodes()), new Set(copy.nodes()));
|
||||
_assert["default"].deepStrictEqual(new Set(graph.edges()), new Set(copy.edges()));
|
||||
_assert["default"].notStrictEqual(graph.getNodeAttributes('n1'), copy.getNodeAttributes('n1'));
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
copy.addEdge('n0', 'n12');
|
||||
});
|
||||
},
|
||||
'it should not break on adversarial inputs.': function it_should_not_break_on_adversarial_inputs() {
|
||||
var graph = new Graph();
|
||||
graph.mergeEdge(0, 1);
|
||||
graph.mergeEdge(1, 2);
|
||||
graph.mergeEdge(2, 0);
|
||||
var copy = graph.copy();
|
||||
copy.mergeEdge(3, 4);
|
||||
var serializedCopy = Graph.from(graph["export"]());
|
||||
_assert["default"].doesNotThrow(function () {
|
||||
serializedCopy.mergeEdge(3, 4);
|
||||
});
|
||||
_assert["default"].strictEqual(serializedCopy.size, 4);
|
||||
},
|
||||
'copying the graph should conserve its attributes.': function copying_the_graph_should_conserve_its_attributes() {
|
||||
var graph = new Graph();
|
||||
graph.setAttribute('title', 'The Graph');
|
||||
var copy = graph.copy();
|
||||
_assert["default"].deepStrictEqual(graph.getAttributes(), copy.getAttributes());
|
||||
},
|
||||
'it should be possible to upgrade a graph.': function it_should_be_possible_to_upgrade_a_graph() {
|
||||
var strict = new Graph({
|
||||
type: 'directed',
|
||||
allowSelfLoops: false
|
||||
});
|
||||
var loose = new Graph({
|
||||
multi: true
|
||||
});
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
type: 'directed'
|
||||
}).type, 'directed');
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
multi: false
|
||||
}).multi, false);
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
allowSelfLoops: false
|
||||
}).allowSelfLoops, false);
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
type: 'mixed'
|
||||
}).type, 'mixed');
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
multi: true
|
||||
}).multi, true);
|
||||
_assert["default"].strictEqual(strict.copy({
|
||||
allowSelfLoops: true
|
||||
}).allowSelfLoops, true);
|
||||
_assert["default"]["throws"](function () {
|
||||
strict.copy({
|
||||
type: 'undirected'
|
||||
});
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
loose.copy({
|
||||
type: 'undirected'
|
||||
});
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
loose.copy({
|
||||
multi: false
|
||||
});
|
||||
}, usage());
|
||||
_assert["default"]["throws"](function () {
|
||||
loose.copy({
|
||||
allowSelfLoops: false
|
||||
});
|
||||
}, usage());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user