private void OnSingleButtonFragmentClick(Object sender, EventArgs e) { SingleButtonFragment singleButtonFragment = this.FragmentManager.FindFragmentByTag("button_fragment") as SingleButtonFragment; SudokuView sudokuView = this.View.FindViewById <SudokuView>(Resource.Id.sudoku_view); String addText = this.Resources.GetString(Resource.String.add_button_text); String removeText = this.Resources.GetString(Resource.String.remove_button_text); String playText = this.Resources.GetString(Resource.String.play_button_text); if (singleButtonFragment.Text == addText) { SudokuGenerator.AddNumbers(this.ViewModel.Sudoku); sudokuView.Update(); this.ViewModel.ButtonText = singleButtonFragment.Text = removeText; } else if (singleButtonFragment.Text == removeText) { SudokuGenerator.RemoveNumbers(this.ViewModel.Sudoku); sudokuView.Update(); this.ViewModel.ButtonText = singleButtonFragment.Text = playText; } else if (singleButtonFragment.Text == playText) { this.Stop(); FragmentTransaction ft = this.FragmentManager.BeginTransaction(); ft.Remove(singleButtonFragment); ft.Commit(); this.Activity.Intent.PutExtra("action", (int)ActionType.Play); this.Activity.Intent.Extras.PutInt("action", (int)ActionType.Play); ActionType action = (ActionType)this.Activity.Intent.Extras.GetInt("action", (int)ActionType.None); this.ViewModel.ButtonText = null; this.Start(); } }
public void TestRemoveNumbers() { Assert.ThrowsException <ArgumentNullException>(() => SudokuGenerator.RemoveNumbers(null)); SudokuPuzzle sudoku = SudokuGenerator.AddNumbers(SudokuPuzzleTest.Size, SudokuPuzzleTest.Difficulty); Console.WriteLine(sudoku); SudokuPuzzle original = (SudokuPuzzle)sudoku.Clone(); SudokuGenerator.RemoveNumbers(sudoku); Console.WriteLine(sudoku); SudokuSolver.RecursiveSolve(sudoku); Assert.AreEqual(original, sudoku); }
public void TestProperties() { int blockSize = (int)Math.Sqrt(this.Sudoku.Size); Assert.AreEqual(blockSize, this.Sudoku.BlockSize); Assert.IsFalse(this.Sudoku.IsComplete); SudokuSolver.RecursiveSolve(this.Sudoku); Assert.IsTrue(this.Sudoku.IsComplete); Random random = new Random(); int row = random.Next(SudokuPuzzle.MaximumSupportedSize), column = random.Next(SudokuPuzzle.MaximumSupportedSize); this.Sudoku[row, column] = 0; Assert.IsFalse(this.Sudoku.IsComplete); Assert.ThrowsException <ArgumentOutOfRangeException>(() => this.Sudoku[-1, -1]); Assert.ThrowsException <ArgumentException>(() => this.Sudoku[SudokuPuzzle.MaximumSupportedSize, SudokuPuzzle.MaximumSupportedSize]); Assert.ThrowsException <ArgumentOutOfRangeException>(() => this.Sudoku[0, 0] = -1); Assert.ThrowsException <ArgumentException>(() => this.Sudoku[0, 0] = SudokuPuzzle.MaximumSupportedSize + 1); SudokuGenerator.RemoveNumbers(this.Sudoku); const int NUMBER = 0; for (int i = 0; i < this.Sudoku.Size; i++) { for (int j = 0; j < this.Sudoku.Size; j++) { if (this.Sudoku.CheckReadOnly(i, j)) { Assert.ThrowsException <SudokuCellReadOnlyException>(() => this.Sudoku[i, j] = NUMBER); } else { try { this.Sudoku[i, j] = NUMBER; } catch (Exception ex) { Assert.Fail($"Threw exception: {ex}"); } } } } }
public void TestCheck() { SudokuGenerator.AddNumbers(this.Sudoku); Assert.IsTrue(this.Sudoku.Check()); SudokuGenerator.RemoveNumbers(this.Sudoku); Assert.IsFalse(this.Sudoku.Check()); SudokuSolver.RecursiveSolve(this.Sudoku); Assert.IsTrue(this.Sudoku.Check()); Random random = new Random(); int row, column; do { row = random.Next(this.Sudoku.Size); column = random.Next(this.Sudoku.Size); } while (this.Sudoku.CheckReadOnly(row, column)); int number = this.Sudoku[row, column]; this.Sudoku[row, column] = 0; Assert.IsFalse(this.Sudoku.Check()); this.Sudoku[row, column] = number; Assert.IsTrue(this.Sudoku.Check()); }