public void TestAreSameSortedMergedVertex() { UGraph graph = GetGraphObject(); ContractibleGraph cGraph = new ContractibleGraph(graph); LinkedList <Vertex> vertices1 = new LinkedList <Vertex>(); vertices1.AddLast(new LinkedListNode <Vertex>(graph.Vertices[0])); vertices1.AddLast(new LinkedListNode <Vertex>(graph.Vertices[1])); vertices1.AddLast(new LinkedListNode <Vertex>(graph.Vertices[2])); LinkedList <Vertex> vertices2 = new LinkedList <Vertex>(); vertices2.AddLast(new LinkedListNode <Vertex>(graph.Vertices[0])); vertices2.AddLast(new LinkedListNode <Vertex>(graph.Vertices[1])); Assert.AreEqual(false, cGraph.AreSameSortedMergedVertex(vertices1, vertices2)); }
public void TestContractEdge() { UGraph graph = GetGraphObject(); ContractibleGraph cGraph = new ContractibleGraph(graph); ContractibleEdge cEdge = new ContractibleEdge(); cEdge.Head = new LinkedList <Vertex>(); cEdge.Head.AddLast(graph.Vertices[0]); cEdge.Head.AddLast(graph.Vertices[2]); cEdge.Head.AddLast(graph.Vertices[4]); cEdge.Tail = new LinkedList <Vertex>(); cEdge.Tail.AddLast(graph.Vertices[1]); cEdge.Tail.AddLast(graph.Vertices[3]); cEdge.Tail.AddLast(graph.Vertices[5]); bool result = true; LinkedList <Vertex> sortedMergedVertex = cGraph.GetSortedMergedVertex(cEdge); if (sortedMergedVertex.Count == 6) { int prevVertexLabel = sortedMergedVertex.First.Value.Label; foreach (Vertex v in sortedMergedVertex) { if (v.Label < prevVertexLabel) { result = false; break; } prevVertexLabel = v.Label; } } else { result = false; } Assert.AreEqual(true, result); }
public void TestContractEdgeAndDeleteSelfLoops() { UGraph graph = GetGraphObject(); ContractibleGraph cGraph = new ContractibleGraph(graph); Edge originalEdgeContracted = cGraph.ContractibleEdges.First.Value.OriginalEdge; //Test after 1 contraction cGraph.ContractEdgeAndDeleteSelfLoops(cGraph.ContractibleEdges.First.Value); bool result = true; if (cGraph.ContractibleEdges.Count != 13) { result = false; } else { int count = 0; foreach (ContractibleEdge ce in cGraph.ContractibleEdges) { //fails if edge being contracted is still present if (ce.OriginalEdge == originalEdgeContracted) { result = false; break; } //Check no self loops - Note that both head and tails are sorted if (ce.Head.Count == ce.Tail.Count) { LinkedListNode <Vertex> tailCurrNode = ce.Tail.First, headCurrNode = ce.Head.First; bool areEndsDiff = false; for (int i = 0; i < ce.Tail.Count; i++) { if (tailCurrNode.Value.Label != headCurrNode.Value.Label) { areEndsDiff = true; break; } } if (!areEndsDiff) { result = false; break; } } //Check for edges [(1,2),3],[(1,2),4], [1,2 //Check for (1,2),3 - 2 in no if ((ce.OriginalEdge.Head.Label == 1 && ce.OriginalEdge.Tail.Label == 3) || (ce.OriginalEdge.Head.Label == 3 && ce.OriginalEdge.Tail.Label == 1) || (ce.OriginalEdge.Head.Label == 3 && ce.OriginalEdge.Tail.Label == 2) || (ce.OriginalEdge.Head.Label == 2 && ce.OriginalEdge.Tail.Label == 3)) { if ((ce.Head.Count == 2 && ce.Head.Contains(cGraph.OriginalGraph.Vertices[0]) && ce.Head.Contains(cGraph.OriginalGraph.Vertices[1]) && ce.Tail.Count == 1 && ce.Tail.Contains(cGraph.OriginalGraph.Vertices[2])) || (ce.Tail.Count == 2 && ce.Tail.Contains(cGraph.OriginalGraph.Vertices[0]) && ce.Tail.Contains(cGraph.OriginalGraph.Vertices[1]) && ce.Head.Count == 1 && ce.Head.Contains(cGraph.OriginalGraph.Vertices[2]))) { count = count + 1; } } } if (result == false || (result == true && count != 2)) { result = false; } } Assert.AreEqual(true, result); }