public SquarePlacement Select(Square[] allSquares, int size)
        {
            var placements  = _findAvailableSquarePlacements.For(allSquares, size);
            var randomIndex = _random.Next(0, placements.Length);

            return(placements[randomIndex]);
        }
Ejemplo n.º 2
0
        public WhenSelect()
        {
            _gridSquares         = CreateGridSquares();
            _availablePlacements = Substitute.For <IFindAvailableSquarePlacements>();
            _squarePlacements    = new List <SquarePlacement>()
            {
                new SquarePlacement(_gridSquares.Take(5).ToArray()),
                new SquarePlacement(_gridSquares.Skip(5).Take(5).ToArray()),
                new SquarePlacement(_gridSquares.Skip(10).Take(5).ToArray()),
                new SquarePlacement(_gridSquares.Skip(15).Take(5).ToArray()),
                new SquarePlacement(_gridSquares.Skip(20).Take(5).ToArray())
            };
            _availablePlacements.For(_gridSquares, 5).Returns(_squarePlacements.ToArray());

            // Returns 0, 2, 3, 3 with this seed
            _random = Substitute.For <Random>(1);

            _selector = new RandomPlacementSelector(_availablePlacements, _random);
        }