public void Revert_RevertsSpecifiedDiagonal()
        {
            var puzzle = new Puzzle(new int?[, ] {
                { 1, null, null, 4 },
                { null, null, 3, 2 },
                { 2, null, null, null },
                { null, null, null, null }
            });
            var rule = new DiagonalUniquenessRule(puzzle, _GetAllPossibleValues(puzzle.Size));

            BitVector[,] initialPossibles = _GetPossibleValues(puzzle.Size, rule);
            var updatedCoordTracker = new CoordinateTracker(puzzle.Size);
            var coord = new Coordinate(2, 2);
            int val   = 4;

            rule.Update(in coord, val, updatedCoordTracker);

            var revertedCoordTracker = new CoordinateTracker(puzzle.Size);

            rule.Revert(coord, val, revertedCoordTracker);

            Assert.Equal(
                revertedCoordTracker.GetTrackedCoords().ToArray(),
                updatedCoordTracker.GetTrackedCoords().ToArray());
            for (int row = 0; row < puzzle.Size; row++)
            {
                for (int col = 0; col < puzzle.Size; col++)
                {
                    Assert.Equal(
                        initialPossibles[row, col],
                        rule.GetPossibleValues(new Coordinate(row, col)));
                }
            }
        }
        public void Revert_OnNonDiagonal_DoesNothing()
        {
            var puzzle = new Puzzle(new int?[, ] {
                { 1, null, null, 4 },
                { null, null, 3, 2 },
                { 2, null, null, null },
                { null, null, null, null }
            });
            var rule = new DiagonalUniquenessRule(puzzle, _GetAllPossibleValues(puzzle.Size));

            BitVector[,] previousPossibles = _GetPossibleValues(puzzle.Size, rule);

            var coordTracker = new CoordinateTracker(puzzle.Size);
            var coord        = new Coordinate(0, 1);
            int val          = 2;

            rule.Update(in coord, val, new CoordinateTracker(puzzle.Size));

            rule.Revert(coord, val, coordTracker);

            Assert.Equal(0, coordTracker.NumTracked);
            for (int row = 0; row < puzzle.Size; row++)
            {
                for (int col = 0; col < puzzle.Size; col++)
                {
                    Assert.Equal(
                        previousPossibles[row, col],
                        rule.GetPossibleValues(new Coordinate(row, col)));
                }
            }
        }
Esempio n. 3
0
        public void Revert_WithoutAffectedCoordsList_RevertsSpecifiedDiagonal()
        {
            var puzzle = new PuzzleWithPossibleValues(new int?[][] {
                new int?[] { 1, null, null, 4 },
                new int?[] { null, null, 3, 2 },
                new int?[] { 2, null, null, null },
                new int?[] { null, null, null, null }
            });
            var rule = new DiagonalUniquenessRule();

            Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues));
            BitVector[,] initialPossibles = _GetPossibleValues(puzzle.Size, rule);
            var coord = new Coordinate(2, 1);
            int val   = 1;

            rule.Update(in coord, val, new CoordinateTracker(puzzle.Size));

            rule.Revert(coord, val);

            for (int row = 0; row < puzzle.Size; row++)
            {
                for (int col = 0; col < puzzle.Size; col++)
                {
                    Assert.Equal(
                        initialPossibles[row, col],
                        rule.GetPossibleValues(new Coordinate(row, col)));
                }
            }
        }