public void TwoWayConnectionTest() { Connections c = new Connections(); c.AddConnectionTwoWay(0, 1); Assert.AreEqual(2, c.NumConnections); List <int> neighbours = c.GetNeighbours(0); Assert.AreEqual(1, neighbours.Count); Assert.IsTrue(neighbours.Contains(1)); Assert.IsFalse(neighbours.Contains(0)); neighbours = c.GetNeighbours(1); Assert.AreEqual(1, neighbours.Count); Assert.IsTrue(neighbours.Contains(0)); Assert.IsFalse(neighbours.Contains(1)); c.AddConnectionTwoWay(0, 2); Assert.AreEqual(4, c.NumConnections); neighbours = c.GetNeighbours(0); Assert.AreEqual(2, neighbours.Count); Assert.IsTrue(neighbours.Contains(1)); Assert.IsTrue(neighbours.Contains(2)); Assert.IsFalse(neighbours.Contains(0)); neighbours = c.GetNeighbours(2); Assert.AreEqual(1, neighbours.Count); Assert.IsTrue(neighbours.Contains(0)); Assert.IsFalse(neighbours.Contains(1)); Assert.IsFalse(neighbours.Contains(2)); }
public void GraphTwoWayTest() { // Test pathfinding when we set up a graph with some two-way connections AStar astar = new AStar(); Connections c = new Connections(); // Set up graph c.AddConnectionTwoWay(0, 1); c.AddConnectionTwoWay(1, 2); c.AddConnectionTwoWay(2, 3); c.AddConnectionTwoWay(4, 5); c.AddConnectionTwoWay(3, 6); c.AddConnectionTwoWay(2, 7); c.AddConnectionTwoWay(3, 7); List <int> path = new List <int>(); // These paths should exist: Assert.IsTrue(astar.PathExists(c, 0, 2, path)); Assert.IsTrue(astar.PathExists(c, 0, 1, path)); Assert.IsTrue(astar.PathExists(c, 0, 3, path)); Assert.IsTrue(astar.PathExists(c, 4, 5, path)); // These paths should not exist: Assert.IsFalse(astar.PathExists(c, 0, 5, path)); Assert.IsFalse(astar.PathExists(c, 3, 5, path)); // The connections in this Test are two-way, so paths DO exist going the other way Assert.IsTrue(astar.PathExists(c, 2, 0, path)); Assert.IsTrue(astar.PathExists(c, 1, 0, path)); Assert.IsTrue(astar.PathExists(c, 3, 0, path)); Assert.IsTrue(astar.PathExists(c, 5, 4, path)); }