コード例 #1
0
        public void UpdateAndRevert_WithDuplicatePossibleValue()
        {
            var p = new Puzzle(
                new int?[][] {
                new int?[] { 1, null /* 2 */, null /* 3 */, 2 },
                new int?[] { null /* 2 */, null /* 3 */, 1, null /* 2 */ },
                new int?[] { null /* 2 */, null /* 1 */, null /* 2 */, null /* 3 */ },
                new int?[] { 3, 2, 2, 1 },
            }, new int[] { 1, 2, 2, 3 });
            var puzzle = new PuzzleWithPossibleValues(p);
            var rule   = new MaxCountPerRowRule();

            Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues));
            var coordTracker = new CoordinateTracker(puzzle.Size);

            rule.Update(new Coordinate(1, 0), 2, coordTracker);
            Assert.Equal(new BitVector(0b1100), rule.GetPossibleValues(new Coordinate(1, 0)));
            rule.Update(new Coordinate(1, 3), 2, coordTracker);
            Assert.Equal(new BitVector(0b1000), rule.GetPossibleValues(new Coordinate(1, 0)));

            rule.Revert(new Coordinate(1, 3), 2, coordTracker);
            Assert.Equal(new BitVector(0b1100), rule.GetPossibleValues(new Coordinate(1, 0)));
            rule.Revert(new Coordinate(1, 0), 2, coordTracker);
            Assert.Equal(new BitVector(0b1100), rule.GetPossibleValues(new Coordinate(1, 0)));
        }
コード例 #2
0
        public void Revert_RevertsSpecifiedRow()
        {
            var p = new Puzzle(
                new int?[][] {
                new int?[] { 1, null /* 2 */, null /* 3 */, 2 },
                new int?[] { null /* 2 */, null /* 3 */, 1, null /* 2 */ },
                new int?[] { null /* 2 */, null /* 1 */, null /* 2 */, null /* 3 */ },
                new int?[] { 3, 2, 2, 1 },
            }, new int[] { 1, 2, 2, 3 });
            var puzzle = new PuzzleWithPossibleValues(p);
            var rule   = new MaxCountPerRowRule();

            Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues));
            IList <BitVector> initialPossibleValuesByRow = _GetPossibleValuesByRow(puzzle.Size, rule);
            var updatedCoordTracker  = new CoordinateTracker(puzzle.Size);
            var revertedCoordTracker = new CoordinateTracker(puzzle.Size);
            var coord = new Coordinate(1, 1);
            int val   = 3;

            rule.Update(coord, val, updatedCoordTracker);

            rule.Revert(coord, val, revertedCoordTracker);

            Assert.Equal(
                updatedCoordTracker.TrackedCoords.ToArray(),
                revertedCoordTracker.TrackedCoords.ToArray());
            for (int row = 0; row < initialPossibleValuesByRow.Count; row++)
            {
                Assert.Equal(
                    initialPossibleValuesByRow[row],
                    rule.GetMissingValuesForRow(row));
            }
        }