コード例 #1
0
 public void GivenIAddPieces(ActionSide side, string definition)
 {
     Assert.NotNull(_context.BoardState, "Board State has not been initialized.");
     _context.BoardState = StateSerializer.ParseSideV1(_context.BoardState, $"{(side == ActionSide.Red ? "R" : "B")}:{definition}");
     if (_context.ImageBehavior == BoardImageBehavior.EveryStep ||
         _context.ImageBehavior == BoardImageBehavior.EveryChange)
     {
         Console.WriteLine(_context.BoardState.ImageMarkdown());
     }
 }
コード例 #2
0
        public void ThenTheBoardHasPiecesMatching(ActionSide side, string definition)
        {
            Assert.NotNull(_context.BoardState, "Board State has not been initialized.");

            var sideRed   = side == ActionSide.Red;
            var testBoard = StateSerializer.ParseSideV1(StateManager.Create(), $"{(sideRed ? "R" : "B")}:{definition}");

            var sb = new StringBuilder();

            var successful = 0;

            foreach (var location in State.AllBoardLocations)
            {
                if (sideRed)
                {
                    if (!_context.BoardState[location].RedPiece() && !testBoard[location].RedPiece())
                    {
                        continue;
                    }
                }
                else
                {
                    if (!_context.BoardState[location].BluePiece() && !testBoard[location].BluePiece())
                    {
                        continue;
                    }
                }

                if ((_context.BoardState[location] & ~(Cell.Locked | Cell.CursePending)) !=
                    (testBoard[location] &= ~(Cell.Locked | Cell.CursePending)))
                {
                    sb.AppendLine(
                        $"At {location}: Expected {testBoard[location] & ~(Cell.Locked | Cell.CursePending)}, " +
                        $"Got {_context.BoardState[location] & ~(Cell.Locked | Cell.CursePending)}");
                }
                else
                {
                    successful++;
                }
            }

            Console.WriteLine($"Successfully validated {successful} {side} piece{(successful == 1 ? "" : "s")}.");

            if (sb.Length > 0)
            {
                Assert.Fail($"The following board locations had different contents than expected:\r\n{sb}");
            }
        }