public void ToString_Formatting() { Position position = new Position(43, -31); Assert.AreEqual("43 -31", position.ToString()); }
public void Constructor_WithourParameters_RowShouldBeZero() { Position position = new Position(); Assert.AreEqual(0, position.Row); }
public void Constructor_WithoutParameters_ColumnShouldBeZero() { Position position = new Position(); Assert.AreEqual(0, position.Column); }
public void Constructor_WhenColumnIs5() { Position position = new Position(3, 5); Assert.AreEqual(5, position.Column); }
public void Constructor_WhenRowIs5() { Position position = new Position(5, 3); Assert.AreEqual(5, position.Row); }
private bool TryFindEmptyCell(out Position emptyCell) { emptyCell = new Position(0, 0); for (int i = 0; i < this.Dimension; ++i) { for (int j = 0; j < this.Dimension; ++j) { if (this.matrix[i, j] == Matrix.EmptyCell) { emptyCell.Row = i; emptyCell.Column = j; return true; } } } return false; }
private void VisitCell(Position position) { this.matrix[position.Row, position.Column] = this.nextCellValue; this.nextCellValue++; }
private bool IsInsideBoundaries(Position position) { return position.Row < this.Dimension && position.Column < this.Dimension && position.Row >= 0 && position.Column >= 0; }
private bool IsEmptyCell(Position position) { return this.matrix[position.Row, position.Column] == Matrix.EmptyCell; }
private bool HasEmptyNeighbour(Position position) { foreach (var direction in this.coordinatesOfDirection) { Position neighbor = this.GetNeighborCell(position, direction.Key); if (this.IsInsideBoundaries(neighbor) && this.IsEmptyCell(neighbor)) { return true; } } return false; }
private Position GetNeighborCell(Position position, Direction direction) { Position neighbor = new Position(); Position directionCoordinates = this.coordinatesOfDirection[direction]; neighbor.Row = position.Row + directionCoordinates.Row; neighbor.Column = position.Column + directionCoordinates.Column; return neighbor; }
private Direction GetFirstClockwiseEmptyCell(Position position, Direction direction) { Position neighbor = this.GetNeighborCell(position, direction); Direction neighborDirection = direction; while (!this.IsInsideBoundaries(neighbor) || !this.IsEmptyCell(neighbor)) { neighborDirection = this.GetClockwiseRotatedDirection(neighborDirection); neighbor = this.GetNeighborCell(position, neighborDirection); } return neighborDirection; }