public void FindDuplicateConnections_MultipleConnections_CorrectCount() { Graph graph = new Graph(); var n1 = new ExampleNode(); var n2 = new ExampleNode(); var n3 = new ExampleNode(); var n4 = new ExampleNode(); var conn1 = new ExampleConnection(); var conn2 = new ExampleConnection(); var conn3 = new ExampleConnection(); graph.Add(n1); graph.Add(n2); graph.Add(n3); graph.Add(n4); graph.AddConnection(n1, n2, conn1); graph.AddConnection(n1, n3, conn1); graph.AddConnection(n1, n4, conn1); graph.AddConnection(n2, n3, conn2); graph.AddConnection(n3, n2, conn2); graph.AddConnection(n3, n4, conn3); var dupList = graph.FindDuplicateConnections(); Assert.AreEqual(2, dupList.Count); }
public void FindDuplicateConnections_MultipleDistinctDuplicates_ReturnsAll() { Graph graph = new Graph(); var n1 = new ExampleNode(); var n2 = new ExampleNode(); var n3 = new ExampleNode(); var n4 = new ExampleNode(); var conn1 = new ExampleConnection(); var conn2 = new ExampleConnection(); var conn3 = new ExampleConnection(); graph.Add(n1); graph.Add(n2); graph.Add(n3); graph.Add(n4); graph.AddConnection(n1, n2, conn1); graph.AddConnection(n1, n3, conn1); graph.AddConnection(n1, n4, conn1); graph.AddConnection(n2, n3, conn2); graph.AddConnection(n3, n2, conn2); var dupList = graph.FindDuplicateConnections(); var conn1List = dupList.Find(tuple => ReferenceEquals(tuple.Item1, conn1)).Item2; var conn2List = dupList.Find(tuple => ReferenceEquals(tuple.Item1, conn2)).Item2; CollectionAssert.AreEquivalent( new List <(Node, Node)>() { (n1, n2), (n1, n3), (n1, n4), }, conn1List ); CollectionAssert.AreEquivalent( new List <(Node, Node)>() { (n2, n3), (n3, n2), }, conn2List ); }
public void CreateConnection_Connection_Succeed() { //arrange GraphSystem graphSystem = new GraphSystem(); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); Node node1 = graphSystem.graph.Nodes[0]; Node node2 = graphSystem.graph.Nodes[1]; Connection connection = new ExampleConnection(); //act graphSystem.graph.AddConnection(node1, node2, connection); //assert Assert.AreEqual(connection, graphSystem.graph.GetDirectedConnection(node1, node2)); }
public void SanityCheck_Duplicates_ReturnsTrue() { Graph graph = new Graph(); var n1 = new ExampleNode(); var n2 = new ExampleNode(); var n3 = new ExampleNode(); var conn = new ExampleConnection(); graph.Add(n1); graph.Add(n2); graph.Add(n3); graph.AddConnection(n1, n2, conn); graph.AddConnection(n1, n3, conn); Assert.IsTrue(graph.SanityCheckConnections()); }
public void GetConnections_ConnectionList_Success() { //arrange GraphSystem graphSystem = new GraphSystem(); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty); Node node1 = graphSystem.graph.Nodes[0]; Node node2 = graphSystem.graph.Nodes[1]; Node node3 = graphSystem.graph.Nodes[2]; Node node4 = graphSystem.graph.Nodes[3]; Node node5 = graphSystem.graph.Nodes[4]; Connection c1, c2, c3, c4; c1 = new ExampleConnection(); c2 = new ExampleConnection(); c3 = new ExampleConnection(); c4 = new ExampleConnection(); graphSystem.graph.AddConnection(node1, node2, c1); graphSystem.graph.AddConnection(node1, node3, c2); graphSystem.graph.AddConnection(node1, node4, c3); graphSystem.graph.AddConnection(node1, node5, c4); //act List <(Connection, Node)> connectionList = new List <(Connection, Node)>(); connectionList.Add((c1, node2)); connectionList.Add((c2, node3)); connectionList.Add((c3, node4)); connectionList.Add((c4, node5)); List <(Connection, Node)> getConnectionsList = graphSystem.graph.GetOutgoingConnections(node1); //assert CollectionAssert.AreEquivalent(connectionList, getConnectionsList); }