public void GetPossibleRowValues_IsCorrect() { var puzzle = new Puzzle(new int?[, ] { { 1, null /* 4 */, null /* 3 */, 2 }, { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, { 3, 2, 4, 1 } }); var rule = new RowUniquenessRule(puzzle, _GetAllPossibleValues(puzzle.Size)); Assert.Equal(new BitVector(0b11000), rule.GetMissingValuesForRow(0)); Assert.Equal(new BitVector(0b11100), rule.GetMissingValuesForRow(1)); Assert.Equal(new BitVector(0b11110), rule.GetMissingValuesForRow(2)); Assert.Equal(new BitVector(0b00000), rule.GetMissingValuesForRow(3)); }
public void Revert_RevertsSpecifiedRow() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 } }); var rule = new RowUniquenessRule(); 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)); } }
public void GetPossibleRowValues_IsCorrect() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 } }); var rule = new RowUniquenessRule(); Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues)); Assert.Equal(new BitVector(0b11000), rule.GetMissingValuesForRow(0)); Assert.Equal(new BitVector(0b11100), rule.GetMissingValuesForRow(1)); Assert.Equal(new BitVector(0b11110), rule.GetMissingValuesForRow(2)); Assert.Equal(new BitVector(0b00000), rule.GetMissingValuesForRow(3)); }
private IList <BitVector> _GetPossibleValuesByRow(int numRows, RowUniquenessRule rule) { var possibleRowValues = new List <BitVector>(); for (int row = 0; row < numRows; row++) { possibleRowValues.Add(rule.GetMissingValuesForRow(row)); } return(possibleRowValues); }
public void Revert_WithoutAffectedList_RevertsSpecifiedRow() { var puzzle = new Puzzle(new int?[, ] { { 1, null /* 4 */, null /* 3 */, 2 }, { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, { 3, 2, 4, 1 } }); var rule = new RowUniquenessRule(puzzle, _GetAllPossibleValues(puzzle.Size)); IList <BitVector> initialPossibleValuesByRow = _GetPossibleValuesByRow(puzzle.Size, rule); var coord = new Coordinate(1, 1); int val = 3; rule.Update(coord, val, new CoordinateTracker(puzzle.Size)); rule.Revert(coord, val); for (int row = 0; row < initialPossibleValuesByRow.Count; row++) { Assert.Equal( initialPossibleValuesByRow[row], rule.GetMissingValuesForRow(row)); } }