private void btnSolve_Click(object sender, EventArgs e) { int numQueens = 0; if (!Int32.TryParse(cbNumQueens.Text, out numQueens)) { return; } btnSolve.Enabled = false; progressBar1.Visible = true; ClearPointValues(); _max = 0; Task.Factory.StartNew(() => { TimeSpan elapsed; elapsed = Time(() => NQueensSolver.Sequential(numQueens)); SetPoint(_serial, elapsed.TotalSeconds); elapsed = Time(() => NQueensSolver.Parallel(numQueens)); SetPoint(_parallel, elapsed.TotalSeconds); }, TaskCreationOptions.AttachedToParent).ContinueWith(t => { progressBar1.Visible = false; btnSolve.Enabled = true; if (t.IsFaulted) { MessageBox.Show(t.Exception.ToString()); } }, CancellationToken.None, TaskContinuationOptions.AttachedToParent, _uiScheduler); }
public void SolvesNQueensPuzzle(int numberOfQueensAndSize, int solutionsAmount, IList <IList <string> > expectedBoards = null) { IList <IList <string> > result = NQueensSolver.SolveNQueens(numberOfQueensAndSize); Assert.Equal(solutionsAmount, result.Count); if (expectedBoards == null) { return; } for (int resultIdx = 0; resultIdx < expectedBoards.Count; resultIdx++) { for (int rowIdx = 0; rowIdx < expectedBoards[resultIdx].Count; rowIdx++) { result[resultIdx][rowIdx].Should().Be(expectedBoards[resultIdx][rowIdx]); } } }