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

            var         puzzleCopy = new Puzzle(puzzle);
            ISudokuRule ruleCopy   = rule.CopyWithNewReference(puzzleCopy);
            int         val        = 4;
            var         coord      = new Coordinate(1, 1);

            ruleCopy.Update(coord, val, new CoordinateTracker(puzzle.Size));
            Assert.NotEqual(rule.GetPossibleValues(coord), ruleCopy.GetPossibleValues(coord));

            puzzleCopy[coord] = val;
            var secondCoord  = new Coordinate(2, 2);
            int secondVal    = 2;
            var coordTracker = new CoordinateTracker(puzzle.Size);

            ruleCopy.Update(secondCoord, secondVal, coordTracker);
            var originalCoordTracker = new CoordinateTracker(puzzle.Size);

            rule.Update(secondCoord, secondVal, originalCoordTracker);
            Assert.Equal(
                new HashSet <Coordinate> {
                new Coordinate(3, 3)
            },
                new HashSet <Coordinate>(coordTracker.GetTrackedCoords().ToArray()));
            Assert.Equal(
                new HashSet <Coordinate> {
                new Coordinate(1, 1), new Coordinate(3, 3)
            },
                new HashSet <Coordinate>(originalCoordTracker.GetTrackedCoords().ToArray()));
        }
예제 #2
0
        public void CopyWithNewReference_CreatesDeepCopy()
        {
            var puzzle = new Puzzle(new int?[, ] {
                { 1, null /* 4 */, null /* 3 */, 2 },
                { null /* 2 */, 3, null /* 1 */, null /* 4 */ },
                { null /* 4 */, null /* 1 */, 2, 3 },
                { null /* 3 */, null /* 2 */, 4, 1 }
            });
            var rule = new BoxUniquenessRule(puzzle, _GetAllPossibleValues(puzzle.Size), false);

            var         puzzleCopy = new Puzzle(puzzle);
            ISudokuRule ruleCopy   = rule.CopyWithNewReference(puzzleCopy);
            int         val        = 3;
            var         coord      = new Coordinate(3, 0);

            ruleCopy.Update(coord, val, new CoordinateTracker(puzzle.Size));
            Assert.NotEqual(rule.GetPossibleValues(coord), ruleCopy.GetPossibleValues(coord));

            puzzleCopy[coord] = val;
            var secondCoord  = new Coordinate(3, 1);
            int secondVal    = 2;
            var coordTracker = new CoordinateTracker(puzzle.Size);

            ruleCopy.Update(secondCoord, secondVal, coordTracker);
            var originalCoordTracker = new CoordinateTracker(puzzle.Size);

            rule.Update(secondCoord, secondVal, originalCoordTracker);
            Assert.Equal(
                new HashSet <Coordinate> {
                new Coordinate(2, 0), new Coordinate(2, 1)
            },
                new HashSet <Coordinate>(coordTracker.GetTrackedCoords().ToArray()));
            Assert.Equal(
                new HashSet <Coordinate> {
                new Coordinate(2, 0), new Coordinate(2, 1), new Coordinate(3, 0)
            },
                new HashSet <Coordinate>(originalCoordTracker.GetTrackedCoords().ToArray()));
        }