public void CopyWithNewReferences_WithoutIMissingBoxValuesTracker_Throws()
        {
            var puzzle = new Puzzle(new int?[, ] {
                { null /* 1 */, null /* 4 */, 3, 2 },
                { null /* 2 */, null /* 3 */, null /* 1 */, 4 },
                { null /* 4 */, null /* 1 */, 2, 3 },
                { 3, null /* 2 */, 4, 1 }
            });
            var possibleValues = new PossibleValues(puzzle);
            var boxRule        = new BoxUniquenessRule(puzzle, possibleValues.AllPossible, false);
            var ruleKeeper     = new DynamicRuleKeeper(puzzle, possibleValues, new List <ISudokuRule> {
                boxRule
            });
            var heuristic = new UniqueInBoxHeuristic(
                puzzle, possibleValues, boxRule);

            var puzzleCopy                  = new Puzzle(puzzle);
            var possibleValuesCopy          = new PossibleValues(possibleValues);
            var ruleKeeperWithoutBoxTracker = new DynamicRuleKeeper(puzzleCopy, possibleValuesCopy,
                                                                    new List <ISudokuRule> {
                new ColumnUniquenessRule(puzzleCopy, possibleValues.AllPossible),
            });

            Assert.Throws <ArgumentException>(() => heuristic.CopyWithNewReferences(
                                                  puzzleCopy, possibleValuesCopy, ruleKeeperWithoutBoxTracker.GetRules()));
        }
        public void CopyWithNewReferences_CreatesDeepCopy()
        {
            var puzzle = new PuzzleWithPossibleValues(new int?[][] {
                new int?[] { null /* 1 */, null /* 4 */, 3, 2 },
                new int?[] { null /* 2 */, null /* 3 */, null /* 1 */, 4 },
                new int?[] { null /* 4 */, null /* 1 */, 2, 3 },
                new int?[] { 3, null /* 2 */, 4, 1 }
            });
            var ruleKeeper = new StandardRuleKeeper();

            Assert.True(ruleKeeper.TryInit(puzzle));
            var heuristic = new UniqueInBoxHeuristic(
                (IMissingBoxValuesTracker)ruleKeeper.GetRules()[0]);

            Assert.True(heuristic.TryInitFor(puzzle));

            var puzzleCopy     = new PuzzleWithPossibleValues(puzzle);
            var ruleKeeperCopy = (StandardRuleKeeper)ruleKeeper.CopyWithNewReferences(
                puzzleCopy);
            IHeuristic heuristicCopy = heuristic.CopyWithNewReferences(
                puzzleCopy, ruleKeeperCopy.GetRules());

            var       coord = new Coordinate(1, 1);
            BitVector originalPossibleValues = puzzle.GetPossibleValues(coord);

            Assert.Equal(originalPossibleValues, puzzleCopy.GetPossibleValues(coord));
            heuristicCopy.UpdateAll();
            Assert.Equal(originalPossibleValues, puzzle.GetPossibleValues(coord));
            Assert.NotEqual(originalPossibleValues, puzzleCopy.GetPossibleValues(coord));
        }
        public void CopyWithNewReferences_CreatesDeepCopy()
        {
            var puzzle = new Puzzle(new int?[, ] {
                { null /* 1 */, null /* 4 */, 3, 2 },
                { null /* 2 */, null /* 3 */, null /* 1 */, 4 },
                { null /* 4 */, null /* 1 */, 2, 3 },
                { 3, null /* 2 */, 4, 1 }
            });
            var possibleValues = new PossibleValues(puzzle);
            var ruleKeeper     = new StandardRuleKeeper(puzzle, possibleValues);
            var heuristic      = new UniqueInBoxHeuristic(
                puzzle, possibleValues, (IMissingBoxValuesTracker)ruleKeeper.GetRules()[0]);

            var puzzleCopy         = new Puzzle(puzzle);
            var possibleValuesCopy = new PossibleValues(possibleValues);
            var ruleKeeperCopy     = (StandardRuleKeeper)ruleKeeper.CopyWithNewReferences(
                puzzleCopy, possibleValuesCopy);
            ISudokuHeuristic heuristicCopy = heuristic.CopyWithNewReferences(
                puzzleCopy, possibleValuesCopy, ruleKeeperCopy.GetRules());

            var       coord = new Coordinate(1, 1);
            BitVector originalPossibleValues = possibleValues[coord];

            Assert.Equal(originalPossibleValues, possibleValuesCopy[coord]);
            heuristicCopy.UpdateAll();
            Assert.Equal(originalPossibleValues, possibleValues[coord]);
            Assert.NotEqual(originalPossibleValues, possibleValuesCopy[coord]);
        }
        public void CopyWithNewReferences_WithoutIMissingBoxValuesTracker_Throws()
        {
            var puzzle = new PuzzleWithPossibleValues(new int?[][] {
                new int?[] { null /* 1 */, null /* 4 */, 3, 2 },
                new int?[] { null /* 2 */, null /* 3 */, null /* 1 */, 4 },
                new int?[] { null /* 4 */, null /* 1 */, 2, 3 },
                new int?[] { 3, null /* 2 */, 4, 1 }
            });
            var ruleKeeper = new StandardRuleKeeper();

            Assert.True(ruleKeeper.TryInit(puzzle));
            var heuristic = new UniqueInBoxHeuristic(
                (IMissingBoxValuesTracker)ruleKeeper.GetRules()[0]);

            Assert.True(heuristic.TryInitFor(puzzle));

            var puzzleCopy = new PuzzleWithPossibleValues(puzzle);
            var ruleKeeperWithoutBoxTracker = new DynamicRuleKeeper(new IRule[] {
                new ColumnUniquenessRule(),
            });

            Assert.Throws <ArgumentException>(() => heuristic.CopyWithNewReferences(
                                                  puzzleCopy, ruleKeeperWithoutBoxTracker.GetRules()));
        }