BalancedSorter predict and verify

This commit is contained in:
Gonzalo Bellver
2012-01-13 12:37:11 -03:00
parent cbc036291d
commit 2bb68de4f1
5 changed files with 226 additions and 74 deletions

View File

@@ -28,6 +28,7 @@ mindplot.nlayout.TestSuite = new Class({
this.testReconnect();
this.testRemoveNode();
this.testSymmetricPredict();
this.testBalancedPredict();
},
testAligned: function() {
@@ -151,6 +152,35 @@ mindplot.nlayout.TestSuite = new Class({
manager.layout();
manager.plot("testBalanced8", plotsize);
manager.addNode(13, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.connectNode(0, 13, 4);
manager.layout();
manager.plot("testBalanced9", {width:1000, height:400});
manager.addNode(14, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.connectNode(0, 14, 5);
manager.layout();
manager.plot("testBalanced10", {width:1000, height:400});
manager.addNode(15, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.connectNode(0, 15, 4);
manager.layout();
manager.plot("testBalanced11", {width:1000, height:400});
manager.addNode(16, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.connectNode(0, 16, 25);
manager.layout();
manager.plot("testBalanced12", {width:1000, height:400});
manager.addNode(17, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.addNode(18, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.addNode(19, mindplot.nlayout.TestSuite.NODE_SIZE, position);
manager.connectNode(0, 17, 11);
manager.connectNode(0, 18, 13);
manager.connectNode(0, 19, 10);
manager.layout();
manager.plot("testBalanced13", {width:1000, height:400});
$assert(manager.find(1).getPosition().x > 0, "even order nodes must be at right of central topic");
$assert(manager.find(3).getPosition().x > 0, "even order nodes must be at right of central topic");
$assert(manager.find(5).getPosition().x > 0, "even order nodes must be at right of central topic");
@@ -181,7 +211,7 @@ mindplot.nlayout.TestSuite = new Class({
// Now connect one with two....
manager.connectNode(0, 1, 0);
manager.connectNode(0, 2, 0);
manager.connectNode(0, 2, 1);
manager.connectNode(1, 3, 0);
// Basic layout repositioning ...
@@ -365,8 +395,18 @@ mindplot.nlayout.TestSuite = new Class({
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.connectNode(0, 1, 0);
manager.connectNode(0, 5, 1);
manager.connectNode(0, 6, 2);
manager.connectNode(0, 7, 3);
manager.connectNode(0, 8, 4);
manager.connectNode(0, 9, 5);
manager.connectNode(1, 2, 0);
manager.connectNode(1, 3, 1);
manager.connectNode(3, 4, 0);
@@ -387,6 +427,18 @@ mindplot.nlayout.TestSuite = new Class({
manager.layout(true);
manager.plot("testRemoveNode2", {width:1000, height:200});
// Remove a node from the root node
console.log("\t--- Remove node 6 ---");
manager.removeNode(6);
manager.layout(true);
manager.plot("testRemoveNode3", {width:1000, height:200});
// Remove a node from the root node
console.log("\t--- Remove node 5 ---");
manager.removeNode(5);
manager.layout(true);
manager.plot("testRemoveNode4", {width:1000, height:200});
$assert(manager.find(1).getPosition().y == manager.find(2).getPosition().y, "After removal of node 3, nodes 1 and 2 should be alingned");
console.log("\n");
},
@@ -423,36 +475,96 @@ mindplot.nlayout.TestSuite = new Class({
manager.layout();
console.log("\tPredict where would a node be if tried to add as children of node 9 and dropped at (-280, 45):");
var predict1 = manager.plot("testPredict1", {width:1000, height:400});
console.log("\tAdded as child of node 9 and dropped at (-280, 45):");
var predict1 = manager.plot("testSymmetricPredict1", {width:1000, height:400});
this._plotPrediction(predict1, manager.predict(9, {x:-280, y:45}));
console.log("\tPredict where would a node be if tried to add as children of node 1 and dropped at (155, -90):");
var predict2 = manager.plot("testPredict2", {width:1000, height:400});
console.log("\tAdded as child of node 1 and dropped at (155, -90):");
var predict2 = manager.plot("testSymmetricPredict2", {width:1000, height:400});
this._plotPrediction(predict2, manager.predict(1, {x:-155, y:-90}));
console.log("\tPredict where would a node be if tried to add as children of node 5 and dropped at (375, 15):");
var predict3 = manager.plot("testPredict3", {width:1000, height:400});
console.log("\tAdded as child of node 5 and dropped at (375, 15):");
var predict3 = manager.plot("testSymmetricPredict3", {width:1000, height:400});
this._plotPrediction(predict3, manager.predict(5, {x:375, y:15}));
console.log("\tPredict where would a node be if tried to add as children of node 5 and dropped at (375, 45):");
var predict4 = manager.plot("testPredict4", {width:1000, height:400});
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
var predict4 = manager.plot("testSymmetricPredict4", {width:1000, height:400});
this._plotPrediction(predict4, manager.predict(5, {x:375, y:45}));
console.log("\tPredict where would a node be if tried to add as children of node 5 and dropped at (375, 45):");
var predict5 = manager.plot("testPredict5", {width:1000, height:400});
console.log("\tAdded as child of node 5 and dropped at (375, 45):");
var predict5 = manager.plot("testSymmetricPredict5", {width:1000, height:400});
this._plotPrediction(predict5, manager.predict(5, {x:375, y:65}));
console.log("\tPredict where would a node be if tried to add as children of node 3 and dropped at (280, 45):");
var predict6 = manager.plot("testPredict6", {width:1000, height:400});
console.log("\tAdded as child of node 3 and dropped at (280, 45):");
var predict6 = manager.plot("testSymmetricPredict6", {width:1000, height:400});
this._plotPrediction(predict6, manager.predict(3, {x:280, y:45}));
console.log("\tPredict where would a node be if tried to add as children of node 3 and dropped at (255, 110):");
var predict7 = manager.plot("testPredict7", {width:1000, height:400});
console.log("\tAdded as child of node 3 and dropped at (255, 110):");
var predict7 = manager.plot("testSymmetricPredict7", {width:1000, height:400});
this._plotPrediction(predict7, manager.predict(3, {x:255, y:110}));
console.log("\tPredict where would a node be if tried to add as children of node 2 and dropped at (-260, 0):");
var predict8 = manager.plot("testPredict8", {width:1000, height:400});
console.log("\tAdded as child of node 2 and dropped at (-260, 0):");
var predict8 = manager.plot("testSymmetricPredict8", {width:1000, height:400});
this._plotPrediction(predict8, manager.predict(2, {x:-260, y:0}));
console.log("\tPredict where would a node be if tried to add as children of node 5 and dropped at (380, -30):");
var predict9 = manager.plot("testPredict9", {width:1000, height:400});
console.log("\tAdded as child of node 5 and dropped at (380, -30):");
var predict9 = manager.plot("testSymmetricPredict9", {width:1000, height:400});
this._plotPrediction(predict9, manager.predict(5, {x:380, y:-30}));
},
testBalancedPredict: function() {
console.log("testBalancedPredict");
var position = {x:0, y:0};
var manager = new mindplot.nlayout.LayoutManager(0, mindplot.nlayout.TestSuite.ROOT_NODE_SIZE);
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(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.connectNode(0,1,0);
manager.connectNode(0,2,1);
manager.connectNode(0,3,2);
manager.connectNode(0,4,3);
manager.connectNode(0,5,4);
manager.connectNode(4,7,0);
manager.connectNode(4,8,1);
manager.connectNode(8,9,0);
manager.connectNode(3,10,0);
manager.connectNode(3,11,1);
manager.layout();
console.log("\tAdded as child of node 0 and dropped at (165, -70):");
var predict1 = manager.plot("testBalancedPredict1", {width:1000, height:400});
this._plotPrediction(predict1, manager.predict(0, {x:165, y:-70}));
console.log("\tAdded as child of node 0 and dropped at (165, -10):");
var predict2 = manager.plot("testBalancedPredict2", {width:1000, height:400});
this._plotPrediction(predict2, manager.predict(0, {x:165, y:-10}));
console.log("\tAdded as child of node 0 and dropped at (145, 15):");
var predict3 = manager.plot("testBalancedPredict3", {width:1000, height:400});
this._plotPrediction(predict3, manager.predict(0, {x:145, y:15}));
console.log("\tAdded as child of node 0 and dropped at (145, 70):");
var predict4 = manager.plot("testBalancedPredict4", {width:1000, height:400});
this._plotPrediction(predict4, manager.predict(0, {x:145, y:70}));
console.log("\tAdded as child of node 0 and dropped at (-145, -50):");
var predict5 = manager.plot("testBalancedPredict5", {width:1000, height:400});
this._plotPrediction(predict5, manager.predict(0, {x:-145, y:-50}));
console.log("\tAdded as child of node 0 and dropped at (-145, -10):");
var predict6 = manager.plot("testBalancedPredict6", {width:1000, height:400});
this._plotPrediction(predict6, manager.predict(0, {x:-145, y:-10}));
console.log("\tAdded as child of node 0 and dropped at (-145, 40):");
var predict7 = manager.plot("testBalancedPredict7", {width:1000, height:400});
this._plotPrediction(predict7, manager.predict(0, {x:-145, y:400}));
console.log("\tAdded as child of node 0 and dropped at (0, 40):");
var predict8 = manager.plot("testBalancedPredict8", {width:1000, height:400});
this._plotPrediction(predict8, manager.predict(0, {x:0, y:40}));
console.log("\tAdded as child of node 0 and dropped at (0, 0):");
var predict9 = manager.plot("testBalancedPredict9", {width:1000, height:400});
this._plotPrediction(predict9, manager.predict(0, {x:0, y:0}));
},
_plotPrediction: function(canvas, prediction) {
console.log("\t\tprediction {order:" + prediction[0] + ", position: (" + prediction.getLast().x + "," + prediction.getLast().y + ")}");
var cx = prediction.getLast().x + canvas.width / 2 - mindplot.nlayout.TestSuite.NODE_SIZE.width / 2;

View File

@@ -59,6 +59,11 @@
<div id="testBalanced6" class="col last"></div>
<div id="testBalanced7" class="col"></div>
<div id="testBalanced8" class="col last"></div>
<div id="testBalanced9" class="col last"></div>
<div id="testBalanced10" class="col last"></div>
<div id="testBalanced11" class="col last"></div>
<div id="testBalanced12" class="col last"></div>
<div id="testBalanced13" class="col last"></div>
<h2>testEvents:</h2>
<div id="testEvents1" class="col"></div>
@@ -80,18 +85,30 @@
<h2>testRemoveNode:</h2>
<div id="testRemoveNode1" class="col"></div>
<div id="testRemoveNode2" class="col last"></div>
<div id="testRemoveNode3" class="col last"></div>
<div id="testRemoveNode4" class="col last"></div>
<h2>testSymmetricPredict:</h2>
<div id="testPredict1"></div>
<div id="testPredict2"></div>
<div id="testPredict3"></div>
<div id="testPredict4"></div>
<div id="testPredict5"></div>
<div id="testPredict6"></div>
<div id="testPredict7"></div>
<div id="testPredict8"></div>
<div id="testPredict9"></div>
<div id="testSymmetricPredict1"></div>
<div id="testSymmetricPredict2"></div>
<div id="testSymmetricPredict3"></div>
<div id="testSymmetricPredict4"></div>
<div id="testSymmetricPredict5"></div>
<div id="testSymmetricPredict6"></div>
<div id="testSymmetricPredict7"></div>
<div id="testSymmetricPredict8"></div>
<div id="testSymmetricPredict9"></div>
<h2>testBalancedPredict:</h2>
<div id="testBalancedPredict1"></div>
<div id="testBalancedPredict2"></div>
<div id="testBalancedPredict3"></div>
<div id="testBalancedPredict4"></div>
<div id="testBalancedPredict5"></div>
<div id="testBalancedPredict6"></div>
<div id="testBalancedPredict7"></div>
<div id="testBalancedPredict8"></div>
<div id="testBalancedPredict9"></div>
</body>
</html>