Skip to content

Commit d097f3c

Browse files
committed
Fixed issues in code reported by Codacy.
1 parent e705850 commit d097f3c

File tree

9 files changed

+31
-25
lines changed

9 files changed

+31
-25
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SimpleSudokuSolver
22

3-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/607feb9c1fd2454997e89ba592c345c4)](https://app.codacy.com/app/kurtanr/SimpleSudokuSolver?utm_source=github.com&utm_medium=referral&utm_content=kurtanr/SimpleSudokuSolver&utm_campaign=Badge_Grade_Settings)
43
[![Build](https://img.shields.io/appveyor/ci/kurtanr/SimpleSudokuSolver.svg)](https://ci.appveyor.com/project/kurtanr/SimpleSudokuSolver)
54
[![Codecov](https://img.shields.io/codecov/c/gh/kurtanr/SimpleSudokuSolver)](https://codecov.io/gh/kurtanr/SimpleSudokuSolver)
5+
[![Codacy grade](https://img.shields.io/codacy/grade/607feb9c1fd2454997e89ba592c345c4)](https://app.codacy.com/app/kurtanr/SimpleSudokuSolver)
66
[![Nuget](https://img.shields.io/nuget/v/SimpleSudokuSolver.svg?color=green)](https://www.nuget.org/packages/SimpleSudokuSolver/)
77
[![License](https://img.shields.io/github/license/kurtanr/SimpleSudokuSolver.svg)](https://github.com/kurtanr/SimpleSudokuSolver/blob/master/LICENSE)
88

@@ -17,12 +17,12 @@ Repository contains tests for the library and a UI which uses the library and ca
1717
</p>
1818

1919
Out of the well known [Sudoku Solving Techniques](https://sudoku9x9.com/sudoku_solving_techniques_9x9.html), the solver currently implements:
20-
* Hidden Single
21-
* Naked Single
22-
* Locked Candidates
23-
* Naked Pair
24-
* Naked Triple
25-
* Naked Quad
26-
* Hidden Pair
27-
* Hidden Triple
28-
* Hidden Quad
20+
* Hidden Single
21+
* Naked Single
22+
* Locked Candidates
23+
* Naked Pair
24+
* Naked Triple
25+
* Naked Quad
26+
* Hidden Pair
27+
* Hidden Triple
28+
* Hidden Quad

SimpleSudokuSolver.Tests/Model/SudokuPuzzleTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void ApplyValidSingleStepSolutionTest()
236236
Assert.That(sudokuPuzzle.Steps.Count, Is.EqualTo(2));
237237
Assert.That(sudokuPuzzle.NumberOfSteps, Is.EqualTo(2));
238238
Assert.That(sudokuPuzzle.Steps.Last().Strategy, Is.EqualTo(strategyWhichFindsResult.StrategyName));
239-
Assert.That(sudokuPuzzle.Cells[4,7].Value, Is.EqualTo(5));
239+
Assert.That(sudokuPuzzle.Cells[4, 7].Value, Is.EqualTo(5));
240240
Assert.That(sudokuPuzzle.Steps.Last().SolutionDescription, Is.Not.Empty);
241241
}
242242

@@ -286,7 +286,7 @@ public void UndoSingleStepSolutionsWhichReturnsEliminations_UndoesEliminations_T
286286
Assert.That(step.Result, Is.Null);
287287
Assert.That(step.Strategy, Is.EqualTo(strategyWhichReducesCandidates.StrategyName));
288288
Assert.That(step.SolutionDescription, Is.Not.Empty);
289-
CollectionAssert.AreEqual(sudokuPuzzle.Cells[4, 7].CanBe, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
289+
CollectionAssert.AreEqual(sudokuPuzzle.Cells[4, 7].CanBe, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
290290
}
291291

292292
[Test]

SimpleSudokuSolver.Tests/SingleStepSolutionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void CandidateEqualityTest()
1616
Assert.That(null != candidate);
1717
Assert.That(candidate == otherCandidate);
1818
Assert.That(candidate.Equals(otherCandidate));
19+
Assert.That(candidate.Equals((object)otherCandidate));
1920
Assert.That(candidate.GetHashCode() == otherCandidate.GetHashCode());
2021

2122
var rowDiffers = new SingleStepSolution.Candidate(0, 2, 3);

SimpleSudokuSolver.UI/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private SudokuPuzzle OnLoadGame()
4545

4646
private void OnSaveGame(SudokuPuzzle sudokuPuzzle)
4747
{
48-
var saveFileDialog = new SaveFileDialog()
48+
var saveFileDialog = new SaveFileDialog
4949
{
5050
Filter = _dialogFilter
5151
};

SimpleSudokuSolver.UI/ViewModel/CellViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SimpleSudokuSolver.Model;
2-
using System;
32
using System.ComponentModel;
43

54
namespace SimpleSudokuSolver.UI.ViewModel
@@ -48,7 +47,7 @@ public string Value
4847
get { return Cell.Value != 0 ? Cell.Value.ToString() : string.Empty; }
4948
}
5049

51-
public CellViewModel(Cell cell, bool showTooltip = false)
50+
public CellViewModel(Cell cell, bool showTooltip)
5251
{
5352
Cell = cell;
5453
ShowTooltip = showTooltip;

SimpleSudokuSolver/DefaultSolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SimpleSudokuSolver
66
/// <summary>
77
/// Default sudoku solver.
88
/// </summary>
9-
public partial class DefaultSolver : ISudokuSolver
9+
public class DefaultSolver : ISudokuSolver
1010
{
1111
private SudokuPuzzle _sudokuPuzzleAfterFailedSolveSingleStep;
1212
private readonly BasicElimination _basicElimination = new BasicElimination();

SimpleSudokuSolver/PuzzleProviders/SudokuFilePuzzleProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ public SudokuFilePuzzleProvider(string filePath)
5858
private int[] GetRowElements(string row)
5959
{
6060
var separators = new[] { ",", " ", "\t" };
61+
var rowWithSeparators = row;
6162

6263
// if there are no separators, add them
6364
if (!separators.Any(x => row.Contains(x)))
6465
{
65-
row = Regex.Replace(row, ".{1}", "$0,");
66+
rowWithSeparators = Regex.Replace(rowWithSeparators, ".{1}", "$0,");
6667
}
6768

68-
return row.Split(separators, StringSplitOptions.RemoveEmptyEntries)
69+
return rowWithSeparators.Split(separators, StringSplitOptions.RemoveEmptyEntries)
6970
.Where(x => !string.IsNullOrWhiteSpace(x.Trim()))
7071
.Select(x => int.Parse(x.Trim()))
7172
.ToArray();

SimpleSudokuSolver/SingleStepSolution.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Text;
34

45
namespace SimpleSudokuSolver
@@ -13,7 +14,7 @@ public class SingleStepSolution
1314
/// <summary>
1415
/// Contains value and zero-based row and column index of the cell.
1516
/// </summary>
16-
public class Candidate
17+
public class Candidate : IEquatable<Candidate>
1718
{
1819
public Candidate(int indexOfRow, int indexOfColumn, int value)
1920
{
@@ -66,10 +67,15 @@ public Candidate(int indexOfRow, int indexOfColumn, int value)
6667

6768
public override bool Equals(object obj)
6869
{
69-
return obj is Candidate candidate &&
70-
IndexOfRow == candidate.IndexOfRow &&
71-
IndexOfColumn == candidate.IndexOfColumn &&
72-
Value == candidate.Value;
70+
return Equals(obj as Candidate);
71+
}
72+
73+
public bool Equals(Candidate other)
74+
{
75+
return other != null &&
76+
IndexOfRow == other.IndexOfRow &&
77+
IndexOfColumn == other.IndexOfColumn &&
78+
Value == other.Value;
7379
}
7480

7581
public override int GetHashCode()

SimpleSudokuSolver/Strategy/LockedCandidates.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public SingleStepSolution SolveSingleStep(SudokuPuzzle sudokuPuzzle)
2525
{
2626
var blockCells = block.Cells.OfType<Cell>();
2727
var cellsWithValue = blockCells.Where(x => x.HasValue).ToArray();
28-
var cellsWithNoValue = blockCells.Where(x => !x.HasValue).ToArray();
2928
var possibleCellValuesInBlock = sudokuPuzzle.PossibleCellValues.Except(
3029
cellsWithValue.Select(x => x.Value)).ToArray();
3130

0 commit comments

Comments
 (0)