Skip to content

Commit 7cd1b46

Browse files
committed
Code cleanup, reduced duplication.
1 parent 0cacc6e commit 7cd1b46

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

SimpleSudokuSolver.Tests/Strategy/LockedCandidatesPointingTests.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,6 @@ public void LockedCandidatesPointingInColumnTest()
3636
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[8, 0].CanBe, 3);
3737
}
3838

39-
[Test]
40-
public void LockedCandidatesPointingInRowTest()
41-
{
42-
// From: https://sudoku9x9.com/locked_candidates.html, transposed
43-
var sudoku = new[,]
44-
{
45-
{ 0,0,0,0,0,0,0,0,0 },
46-
{ 1,0,5,0,0,0,0,0,0 },
47-
{ 2,0,6,0,0,0,0,0,0 },
48-
{ 0,0,0,0,0,0,0,0,0 },
49-
{ 0,0,0,0,0,0,0,0,0 },
50-
{ 0,3,0,0,0,0,0,0,0 },
51-
{ 0,0,0,0,0,0,0,0,0 },
52-
{ 0,0,0,0,0,0,0,0,0 },
53-
{ 0,0,0,0,0,0,0,0,0 }
54-
};
55-
56-
var sudokuPuzzle = new SudokuPuzzle(sudoku);
57-
SolveUsingStrategy(sudokuPuzzle, _strategy);
58-
59-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 3].CanBe, 3);
60-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 4].CanBe, 3);
61-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 5].CanBe, 3);
62-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 6].CanBe, 3);
63-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 7].CanBe, 3);
64-
CollectionAssert.DoesNotContain(sudokuPuzzle.Cells[0, 8].CanBe, 3);
65-
}
66-
6739
[Test]
6840
public void LockedCandidatesPointingTest1()
6941
{

SimpleSudokuSolver/Strategy/LockedCandidatesClaiming.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,8 @@ private IEnumerable<Tuple<Cell, int>> GetCellCandidatePairsWhichAppearOnlyInSing
9191
foreach (var item in candidateValuesWhichAppearOnlyInSingleBlock)
9292
{
9393
// We could return all the cells, but just one is enough to eliminate other candidates
94-
var cellOrNull = cellsWithNoValue.Where(x => x.CanBe.Contains(item)).FirstOrDefault();
95-
if (cellOrNull != null)
96-
{
97-
result.Add(new Tuple<Cell, int>(cellOrNull, item));
98-
}
94+
var cell = cellsWithNoValue.First(x => x.CanBe.Contains(item));
95+
result.Add(new Tuple<Cell, int>(cell, item));
9996
}
10097

10198
return result;

0 commit comments

Comments
 (0)