示例#1
0
        public static SeatBlock Build(int rows, int columns, int blockIndex, int totalBlocks)
        {
            var block = new SeatBlock
            {
                TotalRows  = rows,
                RowWidth   = columns,
                BlockIndex = blockIndex
            };

            var seats = new List <Seat>();

            for (int i = 0; i < block.TotalRows; i++)    //i = row
            {
                for (int j = 0; j < block.RowWidth; j++) //j = column
                {
                    seats.Add(new Seat
                    {
                        Row    = i,
                        Column = j,
                        Type   = GetSeatType(j, columns, blockIndex, totalBlocks)
                    });
                }
            }

            block.Seats = seats;
            return(block);
        }
        public void Should_get_right_seat()
        {
            var seats = new List <Seat>
            {
                new Seat {
                    Column = 0, Row = 0, Type = SeatType.Window, Guest = null
                },
                new Seat {
                    Column = 1, Row = 0, Type = SeatType.Middle, Guest = null
                },
                new Seat {
                    Column = 2, Row = 0, Type = SeatType.Aisle, Guest = 2
                },
                new Seat {
                    Column = 0, Row = 1, Type = SeatType.Window, Guest = null
                },
                new Seat {
                    Column = 1, Row = 1, Type = SeatType.Middle, Guest = null
                },
                new Seat {
                    Column = 2, Row = 1, Type = SeatType.Aisle, Guest = null
                }
            };

            var seatBlock = new SeatBlock
            {
                BlockIndex = 0,
                RowWidth   = 3,
                TotalRows  = 2,
                Seats      = seats
            };

            var seat = GuestSeatAllocator.AllocateBestSeat(new[] { seatBlock });

            Assert.IsNotNull(seat);
            Assert.Equals(seat.Row, 1);
            Assert.Equals(seat.Column, 2);
        }