private static void TestNeighbours(HexBoardNeighbours testBoard, Location testLoc, IEnumerable <Location[]> neighbourGroups) { TestOnBoard(testBoard, testLoc); foreach (Location[] neighbours in neighbourGroups) { Location neighbour2 = neighbours[0]; Location between1 = neighbours[1]; Location between2 = neighbours[2]; TestOnBoard(testBoard, neighbour2); TestOnBoard(testBoard, between1); TestOnBoard(testBoard, between2); // that the betweens are neighbours of start, end eand each other Assert.IsTrue(testBoard.AreNeighbours(between1, between2)); Assert.IsTrue(testBoard.AreNeighbours(testLoc, between1)); Assert.IsTrue(testBoard.AreNeighbours(testLoc, between2)); Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between1)); Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between2)); // but not neighbours of each other Assert.IsFalse(testBoard.AreNeighbours(testLoc, neighbour2)); } }
public void CreateTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsNotNull(testBoard); Assert.AreEqual(5, testBoard.BoardSize); }
private Location RandomNeighbour(Location loc) { HexBoardNeighbours neighbourFinder = new HexBoardNeighbours(this.BoardSize); Location[] neighbours = neighbourFinder.Neighbours(loc); return(this.RandomElement(neighbours)); }
private static void TestOnBoard(HexBoardNeighbours testBoard, Location neighbour) { Assert.IsTrue(testBoard.IsOnBoard(neighbour)); Assert.GreaterOrEqual(neighbour.X, 0); Assert.GreaterOrEqual(neighbour.Y, 0); Assert.Less(neighbour.X, testBoard.BoardSize); Assert.Less(neighbour.Y, testBoard.BoardSize); }
public void NeighboursOffTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Location inValue = new Location(5, 0); Location[][] outValue = testBoard.Neighbours2(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(0, outValue.Length); }
public void IsOnBoardFalseTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsFalse(testBoard.IsOnBoard(new Location(-1, -1))); Assert.IsFalse(testBoard.IsOnBoard(new Location(2, -1))); Assert.IsFalse(testBoard.IsOnBoard(new Location(0, 5))); Assert.IsFalse(testBoard.IsOnBoard(new Location(5, 0))); Assert.IsFalse(testBoard.IsOnBoard(new Location(-1, 5))); }
public void IsOnBoardTrueTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(5); Assert.IsTrue(testBoard.IsOnBoard(new Location(0, 0))); Assert.IsTrue(testBoard.IsOnBoard(new Location(2, 2))); Assert.IsTrue(testBoard.IsOnBoard(new Location(0, 4))); Assert.IsTrue(testBoard.IsOnBoard(new Location(4, 0))); Assert.IsTrue(testBoard.IsOnBoard(new Location(4, 4))); }
public void NeighboursNearEdgeTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(10); Location inValue = new Location(5, 1); Location[][] outValue = testBoard.Neighbours2(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(5, outValue.Length); TestNeighbours(testBoard, inValue, outValue); }
public void NeighboursEdgeTest() { HexBoardNeighbours testBoard = new HexBoardNeighbours(10); Location inValue = new Location(5, 0); Location[] outValue = testBoard.Neighbours(inValue); Assert.IsNotNull(outValue); Assert.AreEqual(4, outValue.Length); Assert.AreEqual(4, testBoard.NeighbourCount(inValue)); TestNeighbours(testBoard, inValue, outValue); }
private static void DoTestNeighbour(Cell cell, Cell neibCell, HexBoard board) { Assert.IsTrue(cell.Location.ManhattanDistance(neibCell.Location) < 3, "Neigbour is too far away"); var neighboursTest = new HexBoardNeighbours(BoardSize); Assert.IsTrue(neighboursTest.AreNeighbours(cell.Location, neibCell.Location)); // reflexive. If B is a neighbour of A, then B's neighbours must include A var neibs = board.Neighbours(neibCell); int index = Array.IndexOf(neibs, cell); Assert.IsTrue(index >= 0, "Cell is not neighbour's neighbour"); }
private static void TestNeighbours(HexBoardNeighbours testBoard, Location testLoc, IEnumerable <Location> neighbours) { TestOnBoard(testBoard, testLoc); Location offBoard = new Location(testBoard.BoardSize, testBoard.BoardSize - 1); foreach (Location neighbour in neighbours) { // check is on board TestOnBoard(testBoard, neighbour); // check that the cells are actuallly neighbours Assert.IsTrue(testBoard.AreNeighbours(testLoc, neighbour)); // not neighbours with off-board cell Assert.IsFalse(testBoard.AreNeighbours(testLoc, offBoard)); // not neighbours with self Assert.IsFalse(testBoard.AreNeighbours(testLoc, testLoc)); } }
private static void TestNeighbour2Triplet(Cell cell, Cell[] triplet) { Assert.AreEqual(3, triplet.Length); NoNullsInCellArray(triplet); var testBoard = new HexBoardNeighbours(BoardSize); var testLoc = cell.Location; var neighbour2 = triplet[0].Location; var between1 = triplet[1].Location; var between2 = triplet[2].Location; Assert.IsTrue(testBoard.AreNeighbours(between1, between2)); Assert.IsTrue(testBoard.AreNeighbours(testLoc, between1)); Assert.IsTrue(testBoard.AreNeighbours(testLoc, between2)); Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between1)); Assert.IsTrue(testBoard.AreNeighbours(neighbour2, between2)); // but not neighbours to each other Assert.IsFalse(testBoard.AreNeighbours(testLoc, neighbour2)); }