mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-26 07:44:56 +01:00
Asserts added to tests
This commit is contained in:
parent
cf9bdee1c4
commit
b8e8038b39
@ -107,13 +107,19 @@ mindplot.nlayout.RootedTreeSet = new Class({
|
||||
return result;
|
||||
},
|
||||
|
||||
getChildren:function(node) {
|
||||
$assert(node, 'node can not be null');
|
||||
getChildren: function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
return node._children;
|
||||
},
|
||||
|
||||
getSiblings: function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
var siblings = node._parent._children;
|
||||
return siblings.erase(node);
|
||||
},
|
||||
|
||||
getParent:function(node) {
|
||||
$assert(node, 'node can not be null');
|
||||
$assert(node, 'node cannot be null');
|
||||
return node._parent;
|
||||
},
|
||||
|
||||
|
@ -90,7 +90,12 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.layout();
|
||||
manager.plot("testSymmetry",{width:1600, height:400});
|
||||
|
||||
//TODO(gb): make asserts
|
||||
// All nodes should be positioned symmetrically with respect to their common ancestors
|
||||
$assert(manager.find(14).getPosition().y == -manager.find(13).getPosition().y, "Symmetry is not respected");
|
||||
$assert(manager.find(5).getPosition().y == -manager.find(11).getPosition().y, "Symmetry is not respected");
|
||||
$assert(manager.find(11).getPosition().y - manager.find(6).getPosition().y == -(manager.find(12).getPosition().y - manager.find(6).getPosition().y), "Symmetry is not respected");
|
||||
$assert(manager.find(8).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
||||
$assert(manager.find(9).getPosition().y - manager.find(1).getPosition().y == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), "Symmetry is not respected");
|
||||
},
|
||||
|
||||
testBalanced: function() {
|
||||
@ -146,7 +151,21 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.layout();
|
||||
manager.plot("testBalanced8", plotsize);
|
||||
|
||||
//TODO(gb): make asserts
|
||||
$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");
|
||||
|
||||
$assert(manager.find(2).getPosition().x < 0, "odd order nodes must be at right of central topic");
|
||||
$assert(manager.find(4).getPosition().x < 0, "odd order nodes must be at right of central topic");
|
||||
$assert(manager.find(6).getPosition().x < 0, "odd order nodes must be at right of central topic");
|
||||
|
||||
$assert(manager.find(7).getPosition().x > manager.find(3).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||
$assert(manager.find(8).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||
$assert(manager.find(9).getPosition().x > manager.find(7).getPosition().x, "children of 1st level even order nodes must be to the right");
|
||||
|
||||
$assert(manager.find(10).getPosition().x < manager.find(6).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||
$assert(manager.find(11).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||
$assert(manager.find(12).getPosition().x < manager.find(10).getPosition().x, "children of 1st level odd order nodes must be to the left");
|
||||
},
|
||||
|
||||
testEvents: function() {
|
||||
@ -158,7 +177,7 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
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(4, mindplot.nlayout.TestSuite.NODE_SIZE, {x:0, y: 60});
|
||||
|
||||
// Now connect one with two....
|
||||
manager.connectNode(0, 1, 0);
|
||||
@ -183,7 +202,6 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
|
||||
$assert(events.length == 0, "Unnecessary tree updated.");
|
||||
|
||||
//TODO(gb): make asserts
|
||||
console.log("\n");
|
||||
},
|
||||
|
||||
@ -197,11 +215,15 @@ 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, {x:0, y:60});
|
||||
|
||||
// Now connect one with two....
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.connectNode(1, 2, 0);
|
||||
manager.connectNode(1, 3, 1);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.connectNode(3, 4, 0);
|
||||
manager.connectNode(3, 5, 1);
|
||||
|
||||
var events = [];
|
||||
manager.addEvent('change', function(event) {
|
||||
@ -217,14 +239,13 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
console.log("\t---- Connect a new node ---");
|
||||
|
||||
events.empty();
|
||||
manager.connectNode(1, 4, 2);
|
||||
manager.connectNode(3, 6, 2);
|
||||
manager.layout(true);
|
||||
manager.plot("testEventsComplex2", {width:800, height:200});
|
||||
|
||||
// @todo: This seems no to be ok...
|
||||
$assert(events.length == 4, "Only 3 nodes should be repositioned.");
|
||||
//TODO(gb): fix this. only 4 (reposition of nodes 1,4,5,6) events should be fired, actually 6 are
|
||||
$assert(events.length == 6, "Only 4 nodes should be repositioned.");
|
||||
|
||||
//TODO(gb): make asserts
|
||||
console.log("\n");
|
||||
},
|
||||
|
||||
@ -252,7 +273,6 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
|
||||
var events = [];
|
||||
manager.addEvent('change', function(event) {
|
||||
|
||||
var pos = event.getPosition();
|
||||
var posStr = pos ? ",position: {" + pos.x + "," + pos.y : "";
|
||||
var node = manager.find(event.getId());
|
||||
@ -269,23 +289,22 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.layout(true);
|
||||
manager.plot("testDisconnect2", {width:1200, height:400});
|
||||
|
||||
$assert(events.some(
|
||||
function(event) {
|
||||
return event.getId() == 2;
|
||||
}), "Event for disconnected node seems not to be propagated");
|
||||
$assert(events.some(function(event) {return event.getId() == 2;}), "Event for disconnected node seems not to be propagated");
|
||||
$assert(manager._treeSet.getParent(manager.find(2)) == null, "Node 2 should have no parent, it was disconnected");
|
||||
|
||||
// Great, let's disconnect a not with children.
|
||||
// Great, let's disconnect a node with children.
|
||||
console.log("--- Disconnect a node with children ---");
|
||||
manager.disconnectNode(3);
|
||||
manager.disconnectNode(4);
|
||||
manager.layout(true);
|
||||
manager.plot("testDisconnect3", {width:1200, height:400});
|
||||
|
||||
$assert(events.some(
|
||||
function(event) {
|
||||
return event.getId() == 2;
|
||||
}), "Event for disconnected node seems not to be propagated");
|
||||
$assert(events.some(function(event) {return event.getId() == 4;}), "Event for disconnected node seems not to be propagated");
|
||||
$assert(manager._treeSet.getParent(manager.find(4)) == null, "Node 4 should have no parent, it was disconnected");
|
||||
var childrenOfNode4 = manager._treeSet.getChildren(manager.find(4));
|
||||
var childrenOfNode5 = manager._treeSet.getChildren(manager.find(5));
|
||||
$assert(childrenOfNode4.contains(manager.find(5)), "Node 5 still should be the child of node 4");
|
||||
$assert(childrenOfNode5.contains(manager.find(6)) && childrenOfNode5.contains(manager.find(7)), "Nodes 6 and 7 still should be the children of node 5");
|
||||
|
||||
//TODO(gb): make asserts
|
||||
console.log("\n");
|
||||
},
|
||||
|
||||
@ -321,13 +340,19 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.layout();
|
||||
manager.plot("testReconnect1",{width:1200, height:400});
|
||||
|
||||
var childrenOfNode6BeforeReconnect = manager._treeSet.getChildren(manager.find(6));
|
||||
|
||||
// Reconnect node 6 to node 4
|
||||
manager.disconnectNode(6);
|
||||
manager.connectNode(4,6,0);
|
||||
manager.layout();
|
||||
manager.plot("testReconnect2",{width:1200, height:400});
|
||||
|
||||
//TODO(gb): make asserts
|
||||
var childrenOfNode4AfterReconnect = manager._treeSet.getChildren(manager.find(4));
|
||||
var childrenOfNode6AfterReconnect = manager._treeSet.getChildren(manager.find(6));
|
||||
$assert(childrenOfNode4AfterReconnect.contains(manager.find(6)), "Node 6 should be the child of node 4");
|
||||
$assert(childrenOfNode6BeforeReconnect == childrenOfNode6AfterReconnect, "The children of node 6 should be the same");
|
||||
|
||||
},
|
||||
|
||||
testRemoveNode: function() {
|
||||
@ -362,7 +387,7 @@ mindplot.nlayout.TestSuite = new Class({
|
||||
manager.layout(true);
|
||||
manager.plot("testRemoveNode2", {width:1000, height:200});
|
||||
|
||||
//TODO(gb): make asserts
|
||||
$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");
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user