예제 #1
0
        public void GetSetNeighbors_WithAnyVariable_ReturnsSetVariablesInRowColumnAndSquare()
        {
            // Arrange
            var grid     = new SudokuGrid(EmptyGrid());
            var variable = grid[8, 8];

            var expectedVariables = new Variable[]
            {
                grid[8, 3],                 // same row
                grid[1, 8],                 // same column
                grid[7, 7],                 // same square
                grid[8, 6]                  // same row and square
            };

            foreach (var neighbor in expectedVariables)
            {
                neighbor.Value = 2;
            }

            // Act
            var setNeighbors = new List <Variable>(grid.GetSetNeighbors(variable));

            // Assert
            CollectionAssert.AreEquivalent(expectedVariables, setNeighbors);
        }
예제 #2
0
        public void GetSetNeighbors_VariableIsSet_ReturnsVariableWithNeighbors()
        {
            // Arrange
            var grid     = new SudokuGrid(EmptyGrid());
            var variable = grid[6, 1];

            variable.Value = 4;

            var neighbors = new Variable[]
            {
                grid[6, 6],                 // same row
                grid[2, 1],                 // same column
                grid[7, 0],                 // same square
                grid[6, 0]                  // same row and square
            };

            foreach (var neighbor in neighbors)
            {
                neighbor.Value = 7;
            }

            // Act
            var setNeighbors = new List <Variable>(grid.GetSetNeighbors(variable));

            // Assert
            CollectionAssert.DoesNotContain(setNeighbors, variable);
        }
예제 #3
0
        public void GetSetNeighbors_WithNullVariable_ThrowsArgumentNullException()
        {
            // Arrange
            var grid = new SudokuGrid(AnyInitialValues());

            // Act
            Action action = () =>
            {
                grid.GetSetNeighbors(null);
            };

            // Assert
            Assert.ThrowsException <ArgumentNullException>(action);
        }