From 20e41e48ca9e62bcc56d1ddf8a15370e6da9e3a7 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 16 Jul 2013 10:59:39 +0200 Subject: [PATCH] GraphViewer: Added first basic functions for the community node --- .../js/graphViewer/graph/communityNode.js | 63 +++++++++++++++++++ .../specCommunityNode/communityNodeSpec.js | 53 +++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/html/admin/js/graphViewer/graph/communityNode.js b/html/admin/js/graphViewer/graph/communityNode.js index fd723376df..8d604df83f 100644 --- a/html/admin/js/graphViewer/graph/communityNode.js +++ b/html/admin/js/graphViewer/graph/communityNode.js @@ -1,4 +1,5 @@ /*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */ +/*global _ */ //////////////////////////////////////////////////////////////////////////////// /// @brief Graph functionality /// @@ -31,4 +32,66 @@ function CommunityNode(initial) { "use strict"; + var + + //////////////////////////////////// + // Private variables // + //////////////////////////////////// + + nodes = {}, + + //////////////////////////////////// + // Private functions // + //////////////////////////////////// + + toArray = function(obj) { + var res = []; + _.each(obj, function(v) { + res.push(v); + }); + return res; + }, + + hasNode = function(id) { + return !!nodes[id]; + }, + + getNodes = function() { + return toArray(nodes); + }, + + getNode = function(id) { + return nodes[id]; + }, + + insertNode = function(n) { + nodes[n._id] = n; + }, + + insertEdge = function(e) { + + }, + + dissolve = function() { + + }; + + //////////////////////////////////// + // Setup // + //////////////////////////////////// + + _.each(initial, function(n) { + insertNode(n); + }); + + //////////////////////////////////// + // Public functions // + //////////////////////////////////// + + this.hasNode = hasNode; + this.getNodes = getNodes; + this.getNode = getNode; + this.insertNode = insertNode; + this.insertEdge = insertEdge; + this.dissolve = dissolve; } diff --git a/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js b/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js index eceaf994ae..3f7087b350 100644 --- a/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specCommunityNode/communityNodeSpec.js @@ -75,16 +75,65 @@ expect(testee).toHaveFunction("getNodes", 0); }); - it('should offer a function to check if node is included', function() { + it('should offer a function to check if a node is included', function() { + expect(testee).toHaveFunction("hasNode", 1); + }); + + it('should offer a function to get a node if it is included', function() { expect(testee).toHaveFunction("getNode", 1); }); + it('should offer a function to insert an additional node', function() { + expect(testee).toHaveFunction("insertNode", 1); + }); + + it('should offer a function to insert an additional edge', function() { + expect(testee).toHaveFunction("insertEdge", 1); + }); + + it('should offer a function to dissolve the community', function() { + expect(testee).toHaveFunction("dissolve", 0); + }); }); it('should create a communityNode containing the given nodes', function() { var c = new CommunityNode(nodes.slice(3, 13)); + expect(c.getNodes()).toEqual(nodes.slice(3, 13)); }); - + + it('should be able to insert a new node', function() { + var c = new CommunityNode(nodes.slice(3, 13)), + n = { + _id: "fuxx", + _inboundCounter: 0, + _outboundCounter: 0, + position: { + x: 1, + y: 1, + z: 1 + } + }; + c.insertNode(n); + expect(c.getNodes()).toEqual(nodes.slice(3, 13).concat([n])); + }); + + it('should be able to check if a node is included', function() { + var n = { + _id: "fuxx", + _inboundCounter: 0, + _outboundCounter: 0, + position: { + x: 1, + y: 1, + z: 1 + } + }, + c = new CommunityNode([n]); + + expect(c.hasNode("fuxx")).toBeTruthy(); + expect(c.hasNode("1")).toBeFalsy(); + }); + }); }());