Example #1
0
        public void Generates_valid_ship_when_ship_position_exceeds_board_size()
        {
            // Ship at (7, 7) won't be created. Only (3, 3) will be created.
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(7, 7, 3, 3));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var existingShip = new HorizontalBattleship(new Position(1, 1));
            var ships        = service.GenerateShips(destroyerShipFactory, 1, new[] { existingShip });

            Assert.That(ships, Has.One.Items);

            Assert.That(ships[0].StartPosition, Is.EqualTo(new Position(3, 3)));
        }
Example #2
0
        public void Generates_valid_ship_when_ship_already_exists()
        {
            // Starting point of both ships is (1, 1) so they must overlaps.
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(1, 1, 4, 4));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var existingShip = new HorizontalBattleship(new Position(1, 1));
            var ships        = service.GenerateShips(destroyerShipFactory, 1, new[] { existingShip });

            Assert.That(ships, Has.One.Items);

            Assert.That(ships[0].StartPosition, Is.EqualTo(new Position(4, 4)));
        }