Beispiel #1
0
func TestInitSolverBadInput(t *testing.T) {
	cases := negativeTestCases()
	for i, testCase := range cases {
		sut, _ := sudoku.InitSolver(testCase.input)
		if sut != nil {
			t.Errorf("InitSolver given corrupted grid %v (testCase %v) \nshould return nil", testCase.input, i)
		}
	}
}
Beispiel #2
0
func main() {
	input := readGrid(os.Stdin)
	solver, err := sudoku.InitSolver(input)
	if err != nil || !solver.Solve() {
		fmt.Println("Couldn't solve given sudoku: ", err)
		return
	}
	sudoku.PrintReadableGrid(solver.GetSolution())
}
Beispiel #3
0
func TestSolvePositive(t *testing.T) {
	cases := positiveTestCases()
	for _, testCase := range cases {
		sut, _ := sudoku.InitSolver(testCase.input)
		if !sut.Solve() {
			t.Errorf("Sudoku didn't solved but solution was expected for %v", testCase.input)
		}
		result := sut.GetSolution()
		if result != testCase.correct {
			t.Errorf("Solver returned wrong value from Solve.\nExpected:\n %v\nGot:\n %v", testCase.correct, result)
		}
	}
}