Beispiel #1
0
        public void EmptySeatDoesntHavePlayerPlaying()
        {
            //Arrange
            var s = new SeatInfo();

            //Act
            var res = s.HasPlayerPlaying();

            //Assert
            Assert.AreEqual(false, res);
        }
Beispiel #2
0
        public void SeatWithPlayingPlayerHasPlayerPlaying()
        {
            //Arrange
            var s = new SeatInfo {
                Player = new PlayerInfo {
                    State = PlayerStateEnum.Playing
                }
            };

            //Act
            var res = s.HasPlayerPlaying();

            //Assert
            Assert.AreEqual(true, res);
        }
Beispiel #3
0
        public void SeatWithNonePlayerDoesntHavePlayerPlaying()
        {
            //Arrange
            var s = new SeatInfo {
                Player = new PlayerInfo {
                    State = PlayerStateEnum.None
                }
            };

            //Act
            var res = s.HasPlayerPlaying();

            //Assert
            Assert.AreEqual(false, res);
        }
Beispiel #4
0
        /// <summary>
        /// Get the seat of the next playing player after a specifc seat
        /// </summary>
        /// <param name="seats">Seat collection</param>
        /// <param name="seat">Specifc seat</param>
        /// <returns>Seat of the next playing player</returns>
        public static SeatInfo SeatOfPlayingPlayerNextTo(this IEnumerable <SeatInfo> seats, SeatInfo seat)
        {
            var arrSeats = seats.ToArray();
            Queue <SeatInfo> seatsBefore = new Queue <SeatInfo>();
            Queue <SeatInfo> seatsAfter  = new Queue <SeatInfo>();
            bool             foundMe     = false;

            foreach (SeatInfo s in arrSeats)
            {
                if (!foundMe)
                {
                    seatsBefore.Enqueue(s);
                }
                else
                {
                    seatsAfter.Enqueue(s);
                }

                if (s == seat)
                {
                    foundMe = true;
                }
            }

            while (seatsBefore.Any())
            {
                seatsAfter.Enqueue(seatsBefore.Dequeue());
            }

            while (seatsAfter.Any())
            {
                SeatInfo s = seatsAfter.Dequeue();
                if (s.HasPlayerPlaying())
                {
                    return(s);
                }
            }

            return(null);
        }