ChangeMode() public méthode

public ChangeMode ( Mode mode ) : void
mode Mode
Résultat void
Exemple #1
0
        public void ShouldClearPotentialsWhenGameIsRecreated()
        {
            // Given a cell with some numbers in
            var cell = new Cell(new CellId(-1, -1));
            cell.ChangeMode(Mode.PlayGame);
            cell.RequestToggleNumber(6);
            cell.RequestToggleNumber(7);
            cell.RequestToggleNumber(8);

            // When we start a new game
            cell.ChangeMode(Mode.NewGame);

            // Then the cell should be cleared
            Assert.IsEmpty(cell.Potentials);
        }
Exemple #2
0
 protected IList<Cell> CreateCellsWithActuals(params int[] actuals)
 {
     return actuals.Select(i =>
                               {
                                   var cell = new Cell(new CellId(i, -1));
                                   cell.ChangeMode(Mode.PlayGame);
                                   cell.RequestToggleNumber(i);
                                   return cell;
                               }).ToList();
 }
Exemple #3
0
        public void ShouldClearFixedNumbersWhenGameIsRecreated()
        {
            // Given a cell with a fixed number in
            var cell = new Cell(new CellId(-1, -1));
            cell.RequestToggleNumber(8);
            cell.ChangeMode(Mode.PlayGame);

            // When we create a new game
            cell.ChangeMode(Mode.NewGame);

            // Then it should have emptied
            Assert.Null(cell.Actual);

            // When we start the game again
            cell.ChangeMode(Mode.PlayGame);

            // Then it should still not be fixed
            Assert.IsFalse(cell.Fixed);
        }
Exemple #4
0
 protected IList<Cell> CreateNineEmptyCellsInPlay()
 {
     var cells = new List<Cell>();
     for(int i = 0; i < 9; i++)
     {
         var cell = new Cell(new CellId(0, i));
         cell.ChangeMode(Mode.PlayGame);
         cells.Add(cell);
     }
     return cells;
 }
Exemple #5
0
        public void ShouldFixTheNumberIfItHasAnActualWhenGameIsStarted()
        {
            // Given a cell is created and an actual is added
            var cell = new Cell(new CellId(-1, -1));
            cell.RequestToggleNumber(3);

            // When the mode is changed to playing the game
            cell.ChangeMode(Mode.PlayGame);

            // Then the cell should be fixed with that number
            Assert.IsTrue(cell.Fixed);
            Assert.AreEqual(3, cell.Actual);
        }
Exemple #6
0
        public void ShouldBeAbleToCopyItselfWithTheSamePotentialsActualsAndMode()
        {
            // Given a cell with some potentials
            var cell = new Cell(new CellId(-1, -1));
            cell.ChangeMode(Mode.PlayGame);
            cell.RemovePotential(6);
            cell.RemovePotential(7);

            // When we copy the cell
            var copy = cell.Copy();

            // Then the copy should have the same potentials
            Assert.AreEqual(new int[]{1, 2, 3, 4, 5, 8, 9}.ToList(), cell.Potentials);

            // And be in the same mode
            copy.RequestToggleNumber(5);
            Assert.AreEqual(new int[]{1, 2, 3, 4, 8, 9}.ToList(), cell.Potentials);
        }
Exemple #7
0
        public void ShouldHavePotentialsIfMoreThanOneNumberToggled()
        {
            // Given a cell is created and the game is started
            var cell = new Cell(new CellId(-1, -1));
            cell.ChangeMode(Mode.PlayGame);

            // When one number is toggled
            cell.RequestToggleNumber(1);

            // Then it should be an actual
            Assert.AreEqual(1, cell.Actual);
            Assert.IsEmpty(cell.Potentials.ToList());

            // When a second number is toggled
            cell.RequestToggleNumber(2);

            // Then they should be potentials
            Assert.AreEqual(2, cell.Potentials.Count());
            Assert.AreEqual(1, cell.Potentials.First());
            Assert.AreEqual(2, cell.Potentials.ElementAt(1));
            Assert.Null(cell.Actual);
        }
Exemple #8
0
        public void ShouldRemoveNumbersWhenToggledTwice()
        {
            // Given a cell with a few numbers in
            var cell = new Cell(new CellId(-1, -1));
            cell.ChangeMode(Mode.PlayGame);
            cell.RequestToggleNumber(3);
            cell.RequestToggleNumber(4);
            cell.RequestToggleNumber(5);

            // When we toggle again
            cell.RequestToggleNumber(5);

            // Then it should remove the number
            Assert.False(cell.Potentials.Contains(5));
        }
Exemple #9
0
        public void ShouldNotAllowFixedNumbersToBeToggled()
        {
            // Given a fixed number
            var cell = new Cell(new CellId(-1, -1));
            cell.RequestToggleNumber(3);
            cell.ChangeMode(Mode.PlayGame);

            // When we toggle the number
            cell.RequestToggleNumber(5);

            // Then nothing should change
            Assert.AreEqual(3, cell.Actual);
            Assert.IsEmpty(cell.Potentials);
        }