Ejemplo n.º 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)
		}
	}
}
Ejemplo n.º 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())
}
Ejemplo n.º 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)
		}
	}
}