public void WhenRequestingBoardWithSingleShipTheShipHasNoHoles() { var subject = new BoardFactory(); var output = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 } }); var shipFields = output.Keys .Select(p => new { x = (int)p[0], y = int.Parse(p.Substring(1)) }) .OrderBy(p => p.x) .ThenBy(p => p.y) .ToList(); var previous = shipFields[0]; shipFields.RemoveAt(0); foreach (var point in shipFields) { var isXContinous = (previous.x) == (point.x - 1); var isYContinous = (previous.y) == (point.y - 1); previous = point; (isXContinous || isYContinous).ShouldBe(true); } }
public void WhenRequestingBoardWithSingleShipTwiceItHasRandomPosition() { var subject = new BoardFactory(); var outputFirst = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 } }); var outputSecond = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 } }); outputFirst.Keys.First().ShouldNotBe(outputSecond.Keys.First()); }
public void WhenRequestingBoardWithoutShipsEmptyBoardIsReturned() { var subject = new BoardFactory(); var output = subject.BuildBoard(new List <Ship>()); output.Count.ShouldBe(0); }
static void Main(string[] args) { string defFilePath = args[0]; if (IsPathValid(defFilePath)) { try { string[] lines = File.ReadAllLines(defFilePath); BoardFactory brdFactory = new BoardFactory(); Board board = brdFactory.BuildBoard(lines[0]); RoomFactory rmFactory = new RoomFactory(); for (int w = 0; w <= board.Width - 1; w++) { for (int h = 0; h <= board.Height - 1; h++) { Room rm = rmFactory.BuildRoom(w, h); board.Rooms.Add(rm); } } MirrorFactory mrFactory = new MirrorFactory(); int i = 2; string line = lines[i]; while (line != "-1") { Mirror mirror = mrFactory.BuildMirror(line); i++; line = lines[i]; board.AddMirror(mirror); } LaserFactory laserFactory = new LaserFactory(); Laser laser = laserFactory.BuildLaser(lines[lines.Count() - 2]); board.SetLaserDirection(laser); string exitConditions = board.FindExit(laser); Console.WriteLine($" Dimensions of Board: {board.Width}, {board.Height}\n Laser Starting Position {laser.XLoc}, {laser.YLoc}\n Laser Exit is at {exitConditions}"); } catch (Exception ex) { Console.WriteLine($"Error Occurred! Exception: {ex.Message} \nStackTrace\n: {ex.StackTrace}"); } } else { Console.WriteLine("File is not found or is invalid. Please select a new file."); } }
public void WhenRequestingBoardWithSingleShipItNeverIsOutsideOfBoundries() { var subject = new BoardFactory(); var boardSize = 10; var output = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 } }, boardSize); output.Keys.ShouldAllBe(p => int.Parse(p.Substring(1)) <= boardSize); output.Keys.ShouldAllBe(p => (p[0] - 96) <= boardSize); }
public void WhenRequestingBoardWithSingleShipBoardHasFieldsForEachFieldWithShipAndAllFieldsAreTheSameShip() { var subject = new BoardFactory(); var output = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 } }); output.Count.ShouldBe(5); var first = output.Values.First(); output.Values.ShouldAllBe(x => x == first); }
public void WhenRequestingBoardWithThreeShipsItReturnsBoardWithAllShips() { var subject = new BoardFactory(); var boardSize = 10; var output = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 }, new Ship { Length = 4 }, new Ship { Length = 4 } }, boardSize); output.Count.ShouldBe(13); }
public void WhenRequestingBoardWithThreeShipsItReturnsBoardWithAllShips() { var subject = new BoardFactory(); var boardSize = 10; var output = subject.BuildBoard(new List <Ship> { new Ship { Length = 5 }, new Ship { Length = 4 }, new Ship { Length = 4 } }, boardSize); output.Count.ShouldBe(13); //Testing If They overlap is not neccessary as data structures enforce it }