//[TestMethod()] public void TestSimpleUnlabelledDAG() { // Sets up a simple test case with a graph that looks like this: // 0 - Node (vertexIndex - label) // / \ // 1 - Node 2 - Node DAG simpleDAG = new DAG(0, 3); // First do all the initializations related to the nodes of the graph. // Create the nodes. DAG.Node parentNode = simpleDAG.GetRoot(); DAG.Node childNode; // Add the first child. childNode = simpleDAG.MakeNodeInLayer(1, 1); simpleDAG.AddRelation(childNode, parentNode); // Add the second child. childNode = simpleDAG.MakeNodeInLayer(2, 1); simpleDAG.AddRelation(childNode, parentNode); // Initialize the all invariants. simpleDAG.InitializeWithStringLabels(new string[] { "Node", "Node", "Node" }); // Canonize DAG by a simple Hopcroft-Tarjan sweep. int[] nodeInvariants = { 0, 0, 0 }; int[] vertexInvariants = { 1, 2, 2 }; TestInvariants( nodeInvariants, vertexInvariants, simpleDAG.CopyInvariants()); simpleDAG.UpdateNodeInvariants(DAG.Direction.Down); int[] nodeInvariantsAfterDown = { 1, 0, 0 }; int[] vertexInvariantsAfterDown = { 1, 2, 2 }; TestInvariants(nodeInvariantsAfterDown, vertexInvariantsAfterDown, simpleDAG.CopyInvariants()); simpleDAG.ComputeVertexInvariants(); int[] nodeInvariantsAfterComputeVertexInv = { 1, 0, 0 }; int[] vertexInvariantsAfterComputeVertexInv = { 2, 1, 1 }; TestInvariants(nodeInvariantsAfterComputeVertexInv, vertexInvariantsAfterComputeVertexInv, simpleDAG.CopyInvariants()); simpleDAG.UpdateNodeInvariants(DAG.Direction.Up); int[] nodeInvariantsAfterUp = { 1, 1, 1 }; int[] vertexInvariantsAfterUp = { 2, 1, 1 }; TestInvariants(nodeInvariantsAfterUp, vertexInvariantsAfterUp, simpleDAG.CopyInvariants()); string simpleDAGString = simpleDAG.ToString(); string expected = "[0 Node ([], [1,2])]\n[1 Node ([0], []), " + "2 Node ([0], [])]\n"; Assert.AreEqual(expected, simpleDAGString); }