예제 #1
0
        public void Board_WhenGridGenerated_ReturnThirteenOccupiedSegments()
        {
            // Arrange
            var ships = new List <IShip> {
                new BattleShip(1), new Destroyer(2), new Destroyer(3)
            };
            var occupiedSegments = shipRandomiser.GetRandomisedShipCoordinates(ships).Count;

            // Act
            var result = gridGenerator.NumberOfOccupiedSegments;

            // Assert
            Assert.AreNotEqual(occupiedSegments, result);
        }
예제 #2
0
        private void UpdateSegmentationGridWithShips()
        {
            SortedDictionary <Coordinate, Segment> segments = shipRandomiser.GetRandomisedShipCoordinates(ships);

            segmentation.UpdateSegmentRange(segments);

            this.NumberOfOccupiedSegments = segmentation.GetSegments().Count(q => !q.Value.IsEmpty);
        }
예제 #3
0
        public void GetRandomisedShipCoordinates_GetNumberOfBattleships_ReturnOne()
        {
            // Arrange
            int          numberOfBattleships = 1;
            List <IShip> ships = new List <IShip> {
                new BattleShip(1), new Destroyer(2), new Destroyer(3)
            };

            // Act
            SortedDictionary <Coordinate, Segment> segments = shipRandomiser.GetRandomisedShipCoordinates(ships);

            // Make sure that the HashCodes are different
            IEnumerable <IShip> battleship = segments.Where(s => s.Value.Ship.ShipChar == BattleShipCode).Select(s => s.Value.Ship);
            int counter = battleship.GroupBy(q => q.GetHashCode()).Count();

            // Assert
            Assert.AreEqual(counter, numberOfBattleships);
        }