mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: JSLintified
This commit is contained in:
parent
48f436ed0d
commit
8d8e54cc36
|
@ -1,6 +1,6 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||
/*global $, d3, _, console, alert*/
|
||||
/*gloabel AbstractAdapter*/
|
||||
/*global AbstractAdapter*/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
///
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
|
||||
/*global $, _ */
|
||||
/*global console */
|
||||
/*global NodeReducer, ModularityJoiner, WebWorkerWrapper*/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
|
|
|
@ -74,7 +74,7 @@ function ModularityJoiner() {
|
|||
}
|
||||
},
|
||||
keys: nativeKeys || function(obj) {
|
||||
if (obj !== Object(obj)) {
|
||||
if (typeof obj !== "object" || Array.isArray(obj)) {
|
||||
throw new TypeError('Invalid object');
|
||||
}
|
||||
var keys = [], key;
|
||||
|
@ -351,13 +351,6 @@ function ModularityJoiner() {
|
|||
if (degrees[t]._in === 0 && degrees[t]._out === 0) {
|
||||
delete degrees[t];
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
self.postMessage({
|
||||
cmd: "debug",
|
||||
result: "Source not stored",
|
||||
});
|
||||
*/
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -531,6 +524,7 @@ function ModularityJoiner() {
|
|||
var s = comm.sID,
|
||||
l = comm.lID,
|
||||
q = comm.val;
|
||||
|
||||
comms[s] = comms[s] || {nodes: [s], q: 0};
|
||||
if (comms[l]) {
|
||||
comms[s].nodes = comms[s].nodes.concat(comms[l].nodes);
|
||||
|
@ -586,10 +580,6 @@ function ModularityJoiner() {
|
|||
////////////////////////////////////
|
||||
|
||||
getCommunity = function(limit, focus) {
|
||||
if (isRunning) {
|
||||
throw "Still running.";
|
||||
}
|
||||
isRunning = true;
|
||||
var coms = {},
|
||||
res = [],
|
||||
dist = {},
|
||||
|
@ -616,14 +606,12 @@ function ModularityJoiner() {
|
|||
delete coms[key];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
res = _.pluck(_.values(coms), "nodes");
|
||||
dist = floatDist(focus);
|
||||
res.sort(sortByDistance);
|
||||
isRunning = false;
|
||||
return res[0];
|
||||
}
|
||||
isRunning = false;
|
||||
return getBestCommunity(coms);
|
||||
};
|
||||
|
||||
|
|
|
@ -1751,11 +1751,13 @@
|
|||
testNetFour,
|
||||
called,
|
||||
result,
|
||||
custom,
|
||||
error;
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
runs(function() {
|
||||
custom = function() {};
|
||||
called = false;
|
||||
result = "";
|
||||
error = "";
|
||||
|
@ -1776,6 +1778,7 @@
|
|||
});
|
||||
};
|
||||
var callback = function(d) {
|
||||
custom(d);
|
||||
if (d.data.cmd === "insertEdge") {
|
||||
return;
|
||||
}
|
||||
|
@ -1907,6 +1910,152 @@
|
|||
});
|
||||
});
|
||||
|
||||
it('should be possible to send many getCommunity requests without crashing', function() {
|
||||
|
||||
var customCounter, s0, s1, s2, s3, s4, ts, comResults, errors;
|
||||
|
||||
runs(function() {
|
||||
customCounter = [];
|
||||
comResults = [];
|
||||
errors = [];
|
||||
s0 = helper.insertSatelite(nodes, edges, 0, 500);
|
||||
s1 = helper.insertSatelite(nodes, edges, 1, 300);
|
||||
s2 = helper.insertSatelite(nodes, edges, 2, 313);
|
||||
s3 = helper.insertSatelite(nodes, edges, 3, 461);
|
||||
s4 = helper.insertSatelite(nodes, edges, 4, 251);
|
||||
|
||||
edges.push(helper.createSimpleEdge(nodes, s0, s1));
|
||||
edges.push(helper.createSimpleEdge(nodes, s0, s2));
|
||||
edges.push(helper.createSimpleEdge(nodes, s1, s3));
|
||||
edges.push(helper.createSimpleEdge(nodes, s1, s4));
|
||||
edges.push(helper.createSimpleEdge(nodes, s2, s1));
|
||||
edges.push(helper.createSimpleEdge(nodes, s2, s4));
|
||||
edges.push(helper.createSimpleEdge(nodes, s3, s0));
|
||||
edges.push(helper.createSimpleEdge(nodes, s4, s1));
|
||||
|
||||
custom = function(d) {
|
||||
var data = d.data;
|
||||
customCounter.push(((new Date()).getTime() - ts) + ": " + data.cmd);
|
||||
if (d.data.cmd === "getCommunity") {
|
||||
comResults.push(data.result || data.error);
|
||||
}
|
||||
if (data.error) {
|
||||
errors.push(data.cmd + ": " + data.error);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ts = (new Date()).getTime();
|
||||
_.each(edges, function(e) {
|
||||
joiner.call("insertEdge", e.source._id, e.target._id);
|
||||
});
|
||||
|
||||
ts = (new Date()).getTime();
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return customCounter.length === 1833;
|
||||
});
|
||||
|
||||
runs(function() {
|
||||
customCounter = [];
|
||||
joiner.call("getCommunity", 800);
|
||||
/*
|
||||
joiner.call("deleteEdge", s0._id, s1._id);
|
||||
joiner.call("deleteEdge", s2._id, s1._id);
|
||||
joiner.call("deleteEdge", s3._id, s0._id);
|
||||
|
||||
joiner.call("insertEdge", s3._id, s0._id);
|
||||
joiner.call("insertEdge", s2._id, s1._id);
|
||||
joiner.call("insertEdge", s0._id, s1._id);
|
||||
*/
|
||||
joiner.call("getCommunity", 800);
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return comResults.length === 2;
|
||||
});
|
||||
|
||||
runs(function() {
|
||||
expect(comResults[0]).toEqual(comResults[1]);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash because of insertion/deletion of edges', function() {
|
||||
|
||||
var customCounter, s0, s1, s2, s3, s4, ts, comResults, errors, adjResults;
|
||||
|
||||
runs(function() {
|
||||
customCounter = [];
|
||||
comResults = [];
|
||||
errors = [];
|
||||
adjResults = [];
|
||||
s0 = helper.insertSatelite(nodes, edges, 0, 500);
|
||||
s1 = helper.insertSatelite(nodes, edges, 1, 300);
|
||||
s2 = helper.insertSatelite(nodes, edges, 2, 313);
|
||||
s3 = helper.insertSatelite(nodes, edges, 3, 461);
|
||||
s4 = helper.insertSatelite(nodes, edges, 4, 251);
|
||||
|
||||
edges.push(helper.createSimpleEdge(nodes, s0, s1));
|
||||
edges.push(helper.createSimpleEdge(nodes, s0, s2));
|
||||
edges.push(helper.createSimpleEdge(nodes, s1, s3));
|
||||
edges.push(helper.createSimpleEdge(nodes, s1, s4));
|
||||
edges.push(helper.createSimpleEdge(nodes, s2, s1));
|
||||
edges.push(helper.createSimpleEdge(nodes, s2, s4));
|
||||
edges.push(helper.createSimpleEdge(nodes, s3, s0));
|
||||
edges.push(helper.createSimpleEdge(nodes, s4, s1));
|
||||
|
||||
custom = function(d) {
|
||||
var data = d.data;
|
||||
customCounter.push(((new Date()).getTime() - ts) + ": " + data.cmd);
|
||||
if (data.cmd === "getCommunity") {
|
||||
comResults.push(data.result || data.error);
|
||||
}
|
||||
if (data.error) {
|
||||
errors.push(data.cmd + ": " + data.error);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ts = (new Date()).getTime();
|
||||
_.each(edges, function(e) {
|
||||
joiner.call("insertEdge", e.source._id, e.target._id);
|
||||
});
|
||||
|
||||
ts = (new Date()).getTime();
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return customCounter.length === 1833;
|
||||
});
|
||||
|
||||
runs(function() {
|
||||
customCounter = [];
|
||||
joiner.call("getCommunity", 800);
|
||||
|
||||
joiner.call("deleteEdge", "0", "1");
|
||||
joiner.call("deleteEdge", "2", "1");
|
||||
joiner.call("deleteEdge", "3", "0");
|
||||
|
||||
joiner.call("insertEdge", "3", "0");
|
||||
joiner.call("insertEdge", "2", "1");
|
||||
joiner.call("insertEdge", "0", "1");
|
||||
|
||||
joiner.call("getCommunity", 800);
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return comResults.length === 2;
|
||||
});
|
||||
|
||||
runs(function() {
|
||||
expect(adjResults[0]).toEqual(adjResults[1]);
|
||||
expect(comResults[0]).toEqual(comResults[1]);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}());
|
Loading…
Reference in New Issue