public void TestNextRevertion() { DirectionVector direction = new DirectionVector(); for (int i = 0; i < DirectionVector.DirectionsCount; i++) { direction.Next(); } Assert.AreEqual(direction.Dx == 1 && direction.Dy == 1, true, "Direction Next doesn't reverts correctly!"); }
static bool CalculateNextDirectionIfPossible( int[,] arr, Position position , DirectionVector currentDirection) { int nextX; int nextY; int arraySize = arr.GetLength(0); for (int i = 0; i < DirectionVector.DirectionsCount; i++) { nextX = position.X + currentDirection.Dx; nextY = position.Y + currentDirection.Dy; if (IsInRange(arraySize, nextX, nextY) && arr[nextX, nextY] == 0) { return true; } currentDirection.Next(); } return false; }
static bool CalculateNextDirectionIfPossible(int[,] arr, Position position, DirectionVector currentDirection) { int nextX; int nextY; int arraySize = arr.GetLength(0); for (int i = 0; i < DirectionVector.DirectionsCount; i++) { nextX = position.X + currentDirection.Dx; nextY = position.Y + currentDirection.Dy; if (IsInRange(arraySize, nextX, nextY) && arr[nextX, nextY] == 0) { return(true); } currentDirection.Next(); } return(false); }
public static int[,] CalculateMatrix(int arraySize) { int[,] matrix = new int[arraySize, arraySize]; int maxValue = arraySize * arraySize; Position position = new Position(); DirectionVector direction = new DirectionVector(); for (int value = 1; value <= maxValue; value++) { matrix[position.X, position.Y] = value; if (CalculateNextDirectionIfPossible(matrix, position, direction)) { position.X += direction.Dx; position.Y += direction.Dy; } else { FindCellToStartFrom(matrix, position); direction.Reset(); } } return matrix; }
public static int[,] CalculateMatrix(int arraySize) { int[,] matrix = new int[arraySize, arraySize]; int maxValue = arraySize * arraySize; Position position = new Position(); DirectionVector direction = new DirectionVector(); for (int value = 1; value <= maxValue; value++) { matrix[position.X, position.Y] = value; if (CalculateNextDirectionIfPossible(matrix, position, direction)) { position.X += direction.Dx; position.Y += direction.Dy; } else { FindCellToStartFrom(matrix, position); direction.Reset(); } } return(matrix); }
public void TestNext() { DirectionVector direction = new DirectionVector(); direction.Next(); Assert.AreEqual(direction.Dx == 1 && direction.Dy == 0, true, "Direction Next doesn't work correctly!"); }
public void TestInitialization() { DirectionVector direction = new DirectionVector(); Assert.AreEqual(direction.Dx == 1 && direction.Dy == 1, true, "Direction Reset() doesn't work correctly!"); }