示例#1
0
        public void TestCheckConnectedForceState(
            [Values(2, 4)] int columns,
            [Values(2, 4)] int rows)
        {
            var pf = new Playfield(columns, rows);

            for (int c = 0; c < columns; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    pf.GetCell(c, r).State = Cell.States.White;
                }
            }
            pf.GetCell(columns - 1, rows - 1).State = Cell.States.WhiteJeweledBoth;

            var cs = new Playfield.CheckState(columns, rows);

            Assert.IsFalse(pf.CheckConnected(pf.GetCell(0, 0), 1, cs));
            cs.Predicate = c => { if (c.State == Cell.States.WhiteJeweledBoth)
                                  {
                                      cs.FoundJewel = true;
                                  }
                                  return(c.IsWhite); };
            Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs));
            Assert.IsTrue(cs.FoundJewel);
        }
示例#2
0
        public void TestCheckConnectedNotConnected(
            [Values(2, 4, 10)] int columns,
            [Values(2, 4, 10)] int rows)
        {
            var pf = new Playfield(columns, rows);

            for (int c = 0; c < columns - 1; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    pf.GetCell(c, r).State = Cell.States.Black;
                }
            }

            for (int r = 0; r < rows; r++)
            {
                pf.GetCell(columns - 1, r).State = Cell.States.White;
            }

            var cs = new Playfield.CheckState(columns, rows, c => c.IsBlack);

            for (int c = 0; c < columns - 1; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    Assert.IsFalse(pf.CheckConnected(pf.GetCell(c, r), columns - 1, cs));
                }
            }
        }
示例#3
0
        public void TestCheckConnectedIsConnectedUp(
            [Values(2, 4)] int columns,
            [Values(2, 4)] int rows)
        {
            var pf = new Playfield(columns, rows);

            for (int r = 0; r < rows; r++)
            {
                pf.GetCell(0, r).State = Cell.States.Black;
            }
            for (int c = 1; c < columns; c++)
            {
                pf.GetCell(c, rows - 1).State = Cell.States.Black;
            }
            var cs = new Playfield.CheckState(columns, rows, c => c.State == pf.GetCell(0, 0).State);

            Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs));
        }
示例#4
0
        public void TestCheckConnectedIsConnected(
            [Values(2, 4)] int columns,
            [Values(2, 4)] int rows)
        {
            var pf = new Playfield(columns, rows);

            pf.GetCell(0, 1).State = Cell.States.White;
            pf.GetCell(1, 1).State = Cell.States.White;

            for (int i = 0; i < columns; i++)
            {
                pf.GetCell(i, 0).State = Cell.States.Black;
            }

            var cs = new Playfield.CheckState(columns, rows, c => c.IsBlack);

            Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs));
        }
示例#5
0
        public void TestCheckConnectedBackwardsConnected(
            [Values(4)] int columns,
            [Values(4)] int rows)
        {
            var pf = new Playfield(columns, rows);

            for (int r = 0; r < rows; r++)
            {
                pf.GetCell(0, r).State = Cell.States.Black;
            }
            for (int c = 1; c < columns; c++)
            {
                pf.GetCell(c, rows - 1).State = Cell.States.Black;
            }
            var cellToCheck = pf.GetCell(2, 1);

            cellToCheck.State = Cell.States.Black;
            var cs = new Playfield.CheckState(columns, rows, c => c.State == cellToCheck.State);

            Assert.IsFalse(pf.CheckConnected(cellToCheck, columns - 1, cs));
        }