internal static void AssertPossibleValuesAtSquare(Coordinate coord, int[] possibleValues, ExactCoverGraph graph) { var square = graph.GetAllPossibilitiesAt(coord); Assert.NotNull(square); var foundValues = new List <int>(); for (int valueIndex = 0; valueIndex < square.Length; ++valueIndex) { var possibleValue = square[valueIndex]; if (possibleValue is null) { continue; } int value = graph.AllPossibleValues[valueIndex]; if (possibleValue.State == NodeState.UNKNOWN) { foundValues.Add(value); Assert.True( possibleValues.Contains(value), $"Unexpected possible value {value} found at {coord}. Expected: {string.Join(',', possibleValues)}."); } else { Assert.False( possibleValues.Contains(value), $"Missing possible value {value} at {coord}. Expected: {string.Join(',', possibleValues)}."); } } Assert.True( possibleValues.Length == foundValues.Count, $"Found {foundValues.Count} possible values when expected {possibleValues.Length} at {coord}. Expected {string.Join(',', possibleValues)}, found: {string.Join(',', foundValues)}."); }
public void GetAllPossibilitiesAt_ForUnsetCoordinate_ReturnsExpectedPossibilities() { var puzzle = new Puzzle(4); ExactCoverGraph graph = ExactCoverGraph.Create(puzzle); var possibilities = graph.GetAllPossibilitiesAt(new Coordinate()); Assert.NotNull(possibilities); Assert.Equal(puzzle.Size, possibilities !.Length); for (int i = 0; i < puzzle.Size; ++i) { Assert.NotNull(possibilities[i]); Assert.Equal(i, possibilities[i] !.Index); } }
internal static void AssertNoPossibleValuesAtSquare(Coordinate coord, ExactCoverGraph graph) { var square = graph.GetAllPossibilitiesAt(coord); if (square is not null) { for (int valueIndex = 0; valueIndex < square.Length; ++valueIndex) { var possibleValue = square[valueIndex]; if (possibleValue is not null) { Assert.Equal(NodeState.DROPPED, possibleValue.State); } } } }