1
0
Fork 0

GraphViewer: Added Tests for joining of community nodes

This commit is contained in:
Michael Hackstein 2013-05-17 17:16:32 +02:00
parent 9cd77a7829
commit bd50d5c5f0
4 changed files with 91 additions and 20 deletions

View File

@ -54,6 +54,7 @@ function ArangoAdapter(nodes, edges, config) {
queries = {},
nodeCollection,
edgeCollection,
limit,
reducer,
arangodb,
width,
@ -267,7 +268,11 @@ function ArangoAdapter(nodes, edges, config) {
});
});
if (callback) {
callback(result[0].vertex);
var n = insertNode(result[0].vertex);
if (limit < nodes.length) {
reducer.getCommunity(limit, n);
}
callback(n);
}
},
@ -534,8 +539,14 @@ function ArangoAdapter(nodes, edges, config) {
api.edge = api.base + "edge?collection=" + edgeCollection;
};
self.setNodeLimit = function (limit) {
self.setNodeLimit = function (pLimit, callback) {
limit = pLimit;
if (limit < nodes.length) {
reducer.getCommunity(limit);
if (callback !== undefined) {
callback();
}
}
};
}

View File

@ -287,18 +287,21 @@ function NodeReducer(nodes, edges) {
populateValues(dQ, a, heap);
var max = 0;
while (communityDetectionStep(dQ, a, heap, coms)) {
// InfiniteLoopCheck should be removed!
max++;
if (max > 100) {
break;
//console.log(max);
}
}
//console.log(max);
res = _.pluck(_.values(coms), "com");
dist = floatDist(focus._id);
res = res.filter(function(e) {return !_.contains(e, focus._id)});
res = res.filter(function(e) {return e.length > 1});
res.sort(sortByDistance);
if (focus !== undefined) {
dist = floatDist(focus._id);
res = res.filter(function(e) {return !_.contains(e, focus._id)});
res = res.filter(function(e) {return e.length > 1});
res.sort(sortByDistance);
} else {
res = res.filter(function(e) {return e.length > 1});
}
return res[0];
};
}

View File

@ -39,12 +39,12 @@
"use strict";
describe('Arango Adapter', function () {
/*
describeInterface(new ArangoAdapter([], [], {
nodeCollection: "",
edgeCollection: ""
}));
*/
var adapter,
nodes,
edges,
@ -271,7 +271,20 @@
loadGraph,
requests;
beforeEach(function() {
beforeEach(function() {
var self = this;
self.fakeReducerRequest = function() {};
spyOn(window, "NodeReducer").andCallFake(function(v, e) {
return {
getCommunity: function(limit, focus) {
if (focus !== undefined) {
self.fakeReducerRequest(limit, focus);
} else {
self.fakeReducerRequest(limit);
}
}
};
});
adapter = new ArangoAdapter(
nodes,
edges,
@ -420,7 +433,6 @@
});
});
it('should be able to load a tree node from ArangoDB'
+ ' by internal attribute and value', function() {
@ -613,11 +625,6 @@
beforeEach(function() {
runs(function() {
var self = this;
this.fakeReducerRequest = function() {};
spyOn(window, "NodeReducer").andCallFake(function(v, e) {
this.getCommunity = self.fakeReducerRequest;
});
spyOn($, "ajax").andCallFake(function(request) {
if (spyHook !== undefined) {
if(!spyHook(request)) {
@ -850,16 +857,66 @@
adapter.setNodeLimit(6);
spyOn(this, "fakeReducerRequest");
adapter.loadNodeFromTreeById(c1, checkCallbackFunction);
expect(this.fakeReducerRequest).toHaveBeenCalledWith(6, c1);
expect(this.fakeReducerRequest).toHaveBeenCalledWith(6, nodeWithID(c1));
});
});
it('should render a reduced set of nodes if too many nodes are added', function() {
runs(function() {
adapter.setNodeLimit(6);
spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [0, 1, 2, 3];
});
adapter.loadNodeFromTreeById(c1, checkCallbackFunction);
});
waitsFor(function() {
return callbackCheck;
});
runs(function() {
notExistNodes([c0, c1, c2, c3]);
existNodes([c4, c5, c6, c7]);
expect(nodes.length).toEqual(5);
});
});
it('should not trigger the reducer if the limit is set large enough', function() {
spyOn(this, "fakeReducerRequest");
adapter.setNodeLimit(10);
expect(this.fakeReducerRequest).not.toHaveBeenCalled();
});
it('should trigger the reducer if the limit is set too small', function() {
spyOn(this, "fakeReducerRequest");
adapter.setNodeLimit(2);
expect(this.fakeReducerRequest).toHaveBeenCalledWith(2);
});
it('should reshape all objects if limit is set too small', function() {
var called = false;
var callback = function() {
called = true;
};
spyOn(this, "fakeReducerRequest").andCallFake(function() {
return [0, 1, 2];
});
adapter.setNodeLimit(2, callback);
notExistNodes([c0, c1, c2]);
existNodes([c3]);
expect(nodes.length).toEqual(2);
expect(called).toBeTruthy();
});
describe('that has loaded several queries', function() {
var c8, c9, e2_8;

View File

@ -65,7 +65,7 @@ var describeInterface = function (testee) {
expect(testee).toHaveFunction("createNode", 2);
expect(testee).toHaveFunction("deleteNode", 2);
expect(testee).toHaveFunction("patchNode", 3);
expect(testee).toHaveFunction("setNodeLimit", 1);
expect(testee).toHaveFunction("setNodeLimit", 2);
});
};