public void Constructor_PassedListOfKnownAndUnknownSquares_NeverSetsAnyWhiteSquares() { var partiallyComplete = new PartiallyCompleteGroup(2, "1."); var initialWhiteBits = partiallyComplete.GetWhiteSquares(); Assert.That(initialWhiteBits.Count, Is.EqualTo(0)); }
public void Constructor_PassedListOfUnknownSquares_CreatesGroupWithNoKnownBlackSquares() { var partiallyComplete = new PartiallyCompleteGroup(2, ".."); var initialBlackBits = partiallyComplete.GetBlackSquares(); Assert.That(initialBlackBits.Count, Is.EqualTo(0)); }
public ISolvedSquaresResult SolveSquares(IPartiallyCompleteGroup partiallyCompleteForGroup) { var filteredCombinations = this.FilterCombinations(partiallyCompleteForGroup); if (filteredCombinations.Count == 0) { return new CantBeSolvedResult(); } if (filteredCombinations.Count == 1) { return new SolvedSquares.SolvedSquaresResult(filteredCombinations.First()); } var partiallyComplete = new PartiallyCompleteGroup(filteredCombinations.First()); foreach (var possibleCombination in filteredCombinations) { partiallyComplete = partiallyComplete.Merge(new PartiallyCompleteGroup(possibleCombination)); } if (partiallyComplete.Equals(partiallyCompleteForGroup)) { return new NothingSolvedThisRoundResult(partiallyCompleteForGroup); } return new PartiallySolvedSquaresResult(partiallyComplete); }
public void SetBlack_WhenSquareIsAlreadyBlack_AppliesNoChange() { var partiallyComplete = new PartiallyCompleteGroup(10, "1."); var initialBlackSquares = partiallyComplete.GetBlackSquares(); var squareIndex = 0; partiallyComplete.SetSquareBlack(squareIndex); var blackBits = partiallyComplete.GetBlackSquares(); Assert.That(blackBits, Is.EqualTo(initialBlackSquares)); }
public void SetBlack_WhenNoSquaresAreBlack_SetsUnknownBitToKnown() { var partiallyComplete = new PartiallyCompleteGroup(10, ".."); var squareIndex = 0; partiallyComplete.SetSquareBlack(squareIndex); var blackBits = partiallyComplete.GetBlackSquares(); Assert.That(blackBits.Count, Is.EqualTo(1)); Assert.That(blackBits.First(), Is.EqualTo(squareIndex)); }
public void Constructor_MapsColumnValuesToRows() { var c1 = new PartiallyCompleteGroup(2, "11"); var c2 = new PartiallyCompleteGroup(2, "11"); var r1 = new PartiallyCompleteGroup(2, ".."); var r2 = new PartiallyCompleteGroup(2, ".."); var grid = new GridPartialSolution( new List<IPartiallyCompleteGroup>() { r1, r2 }, new List<IPartiallyCompleteGroup>() { c1, c2 }); for (int rowId = 0; rowId < 2; rowId++) { var row = grid.GetRow(rowId); Assert.That(row.GetBlackSquares().Count, Is.EqualTo(2)); } }
public void Constructor_MapsRowValuesToColumns() { var r1 = new PartiallyCompleteGroup(2, "11"); var r2 = new PartiallyCompleteGroup(2, "11"); var c1 = new PartiallyCompleteGroup(2, ".."); var c2 = new PartiallyCompleteGroup(2, ".."); var grid = new GridPartialSolution( new List<IPartiallyCompleteGroup>() { r1, r2 }, new List<IPartiallyCompleteGroup>() { c1, c2 }); for (int columnId = 0; columnId < 2; columnId++) { var column = grid.GetColumn(columnId); Assert.That(column.GetBlackSquares().Count, Is.EqualTo(2)); } }
public PartiallyCompleteGroup Merge(PartiallyCompleteGroup other) { var blacks = this.blackBits & other.blackBits; var whites = this.whiteBits & other.whiteBits; return new PartiallyCompleteGroup(blacks, whites); }
public PartiallySolvedSquaresResult(PartiallyCompleteGroup partiallyComplete) { this.partiallyComplete = partiallyComplete; }