diff --git a/mindplot/src/main/javascript/nlayout/TestSuite.js b/mindplot/src/main/javascript/nlayout/TestSuite.js index 2ab80bba..549f67d6 100644 --- a/mindplot/src/main/javascript/nlayout/TestSuite.js +++ b/mindplot/src/main/javascript/nlayout/TestSuite.js @@ -17,11 +17,11 @@ */ mindplot.nlayout.TestSuite = new Class({ Extends: mindplot.nlayout.ChildrenSorterStrategy, + initialize:function() { this.testAligned(); this.testSymmetry(); this.testBalanced(); - this.testGrid(); this.testEvents(); this.testEventsComplex(); this.testDisconnect(); @@ -32,14 +32,13 @@ mindplot.nlayout.TestSuite = new Class({ testAligned: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 1, 0); manager.connectNode(1, 2, 0); manager.connectNode(2, 3, 0); @@ -47,7 +46,7 @@ mindplot.nlayout.TestSuite = new Class({ manager.layout(); manager.dump(); - manager.plot("testAligned", {width:300,height:200}); + manager.plot("testAligned", {width:1200,height:200}); // All nodes should be vertically aligned $assert(manager.find(0).getPosition().y == manager.find(1).getPosition().y, "Nodes are not aligned"); @@ -57,24 +56,23 @@ mindplot.nlayout.TestSuite = new Class({ }, testSymmetry: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); - manager.addNode(5, size, position); - manager.addNode(6, size, position); - manager.addNode(7, size, position); - manager.addNode(8, size, position); - manager.addNode(9, size, position); - manager.addNode(10, size, position); - manager.addNode(11, size, position); - manager.addNode(12, size, position); - manager.addNode(13, size, position); - manager.addNode(14, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(13, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(14, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 14, 0); manager.connectNode(14, 13, 0); manager.connectNode(13, 1, 0); @@ -92,115 +90,76 @@ mindplot.nlayout.TestSuite = new Class({ manager.layout(); manager.dump(); - manager.plot("testSymmetry",{width:500, height:300}); + manager.plot("testSymmetry",{width:1200, height:400}); //TODO(gb): make asserts }, testBalanced: function() { - var size = {width:80, height:30}; - var plotsize = {width: 800, height:400}; var position = {x:0, y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, {width:120, height:40}); + var plotsize = {width:800, height:400}; + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); - manager.addNode(1, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 1, 0); manager.layout(); manager.plot("testBalanced1", plotsize); - manager.addNode(2, size, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 2, 1); manager.layout(); manager.plot("testBalanced2", plotsize); - manager.addNode(3, size, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 3, 2); manager.layout(); manager.plot("testBalanced3", plotsize); - manager.addNode(4, size, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 4, 3); manager.layout(); manager.plot("testBalanced4", plotsize); - manager.addNode(5, size, position); + manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 5, 4); manager.layout(); manager.plot("testBalanced5", plotsize); - manager.addNode(6, size, position); + manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 6, 5); manager.layout(); manager.plot("testBalanced6", plotsize); - manager.addNode(7, size, position); - manager.addNode(8, size, position); - manager.addNode(9, size, position); + manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(3, 7, 0) manager.connectNode(7, 8, 0) manager.connectNode(7, 9, 1); manager.layout(); manager.plot("testBalanced7", plotsize); - manager.addNode(10, size, position); - manager.addNode(11, size, position); - manager.addNode(12, size, position); + manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(6, 10, 0) manager.connectNode(10, 11, 0) manager.connectNode(10, 12, 1); manager.layout(); manager.plot("testBalanced8", plotsize); - }, - - testGrid: function() { - var size = {width:25,height:25}; - var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); - - manager.addNode(1, size, position); - manager.connectNode(0, 1, 0); - manager.layout(); - manager.plot("testGrid1"); - - manager.addNode(2, size, position); - manager.connectNode(0, 2, 1); - manager.layout(); - manager.plot("testGrid2"); - - manager.addNode(3, size, position); - manager.connectNode(0, 3, 2); - manager.layout(); - manager.plot("testGrid3"); - - manager.addNode(4, size, position); - manager.connectNode(0, 4, 3); - manager.layout(); - manager.plot("testGrid4"); - - manager.addNode(5, size, position); - manager.addNode(6, size, position); - manager.addNode(7, size, position); - manager.connectNode(2, 5, 0); - manager.connectNode(2, 6, 1); - manager.connectNode(6, 7, 0); - manager.layout(); - manager.plot("testGrid5", {width:300, height:300}); - - manager.dump(); //TODO(gb): make asserts }, testEvents: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); // Add 3 nodes... - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); // Now connect one with two.... manager.connectNode(0, 1, 0); @@ -216,27 +175,28 @@ mindplot.nlayout.TestSuite = new Class({ }); manager.layout(true); manager.dump(); - manager.plot("testEvents1"); + manager.plot("testEvents1", {width:800, height:400}); // Ok, if a new node is added, this an event should be fired ... console.log("---- Layout without changes should not affect the tree ---"); events.empty(); manager.layout(true); - manager.plot("testEvents2"); + manager.plot("testEvents2", {width:800, height:400}); $assert(events.length == 0, "Unnecessary tree updated."); + + //TODO(gb): make asserts }, testEventsComplex: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); // Add 3 nodes... - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); // Now connect one with two.... manager.connectNode(0, 1, 0); @@ -252,7 +212,7 @@ mindplot.nlayout.TestSuite = new Class({ // Reposition ... manager.layout(true); manager.dump(); - manager.plot("testEventsComplex1"); + manager.plot("testEventsComplex1", {width:800, height:400}); // Add a new node and connect. Only children nodes should be affected. console.log("---- Connect a new node ---"); @@ -261,22 +221,23 @@ mindplot.nlayout.TestSuite = new Class({ manager.connectNode(1, 4, 2); manager.layout(true); manager.dump(); - manager.plot("testEventsComplex2"); + manager.plot("testEventsComplex2", {width:800, height:400}); // @todo: This seems no to be ok... $assert(events.length == 4, "Only 3 nodes should be repositioned."); + + //TODO(gb): make asserts }, testDisconnect: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); // Prepare a sample graph ... - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 1, 0); manager.connectNode(1, 2, 0); @@ -294,7 +255,7 @@ mindplot.nlayout.TestSuite = new Class({ }); manager.layout(true); manager.dump(); - manager.plot("testDisconnect1", {width:300, height:200}); + manager.plot("testDisconnect1", {width:800, height:400}); // Now, disconnect one node ... console.log("--- Disconnect a single node ---"); @@ -302,7 +263,7 @@ mindplot.nlayout.TestSuite = new Class({ manager.disconnectNode(2); manager.layout(true); manager.dump(); - manager.plot("testDisconnect2", {width:300, height:200}); + manager.plot("testDisconnect2", {width:800, height:400}); $assert(events.some( function(event) { @@ -314,31 +275,32 @@ mindplot.nlayout.TestSuite = new Class({ manager.disconnectNode(3); manager.layout(true); manager.dump(); - manager.plot("testDisconnect3", {width:300, height:200}); + manager.plot("testDisconnect3", {width:800, height:400}); $assert(events.some( function(event) { return event.getId() == 2; }), "Event for disconnected node seems not to be propagated"); + + //TODO(gb): make asserts }, testReconnect: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); - manager.addNode(5, size, position); - manager.addNode(6, size, position); - manager.addNode(7, size, position); - manager.addNode(8, size, position); - manager.addNode(9, size, position); - manager.addNode(10, size, position); - manager.addNode(11, size, position); - manager.addNode(12, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(5, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(6, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(7, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(8, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(9, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(10, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(11, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(12, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 1, 0); manager.connectNode(0, 2, 1); manager.connectNode(0, 3, 2); @@ -354,28 +316,27 @@ mindplot.nlayout.TestSuite = new Class({ manager.layout(); manager.dump(); - manager.plot("testReconnect1",{width:400, height:300}); + manager.plot("testReconnect1",{width:1000, height:400}); // Reconnect node 6 to node 4 manager.disconnectNode(6); manager.connectNode(4,6,0); manager.layout(); manager.dump(); - manager.plot("testReconnect2",{width:400, height:300}); + manager.plot("testReconnect2",{width:1000, height:400}); //TODO(gb): make asserts }, testRemoveNode: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); // Prepare a sample graph ... - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 1, 0); manager.connectNode(1, 2, 0); @@ -391,26 +352,27 @@ mindplot.nlayout.TestSuite = new Class({ }); manager.layout(true); manager.dump(); - manager.plot("testRemoveNode1", {width:300, height:200}); + manager.plot("testRemoveNode1", {width:800, height:200}); // Test removal of a connected node ... console.log("--- Remove node 3 ---"); manager.removeNode(3); manager.layout(true); manager.dump(); - manager.plot("testRemoveNode2"); + manager.plot("testRemoveNode2", {width:800, height:200}); + + //TODO(gb): make asserts }, testFreePosition: function() { - var size = {width:25,height:25}; var position = {x:0,y:0}; - var manager = new mindplot.nlayout.LayoutManager(0, size); + var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE); // Prepare a sample graph ... - manager.addNode(1, size, position); - manager.addNode(2, size, position); - manager.addNode(3, size, position); - manager.addNode(4, size, position); + manager.addNode(1, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(2, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(3, mindplot.nlayout.TestSuite.NODE_SIZE, position); + manager.addNode(4, mindplot.nlayout.TestSuite.NODE_SIZE, position); manager.connectNode(0, 4, 0); manager.connectNode(4, 1, 0); @@ -418,9 +380,12 @@ mindplot.nlayout.TestSuite = new Class({ manager.connectNode(4, 3, 2); manager.layout(); - manager.plot("testFreePosition"); + manager.plot("testFreePosition", {width:800, height:400}); + + //TODO(gb): make asserts } - - }); +mindplot.nlayout.TestSuite.NODE_SIZE = {width:80, height:30}, +mindplot.nlayout.TestSuite.ROOT_NODE_SIZE = {width:120, height:40} + diff --git a/mindplot/src/test/javascript/static/layout.html b/mindplot/src/test/javascript/static/layout.html index 26652ff8..bb64267d 100644 --- a/mindplot/src/test/javascript/static/layout.html +++ b/mindplot/src/test/javascript/static/layout.html @@ -49,15 +49,6 @@