validator_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package solver
  2. import (
  3. "testing"
  4. "gitea.ligthert.net/golang/sudoku-funpark/controller"
  5. "gitea.ligthert.net/golang/sudoku-funpark/outputter"
  6. )
  7. // This function will test the validator function.
  8. // It will create all the structs, and set required values
  9. // Load the blocks, populate the blocks, and then run the validator
  10. func TestValidator(t *testing.T) {
  11. // Do all the necesarry steps to initialize the solver.
  12. solver := Solver{}
  13. outp := outputter.Outputter{}
  14. outp.OutputType = "short"
  15. solver.Outp = &outp
  16. controller := controller.Controller{}
  17. solver.Controller = &controller
  18. solver.LoadBlocks()
  19. // Fill the slices of solver.rows with the following values:
  20. // [769154832 154832769 832769154 671945328 945328671 328671945 597416283 416283597 283597416]
  21. solver.row1s = []string{"769154832"}
  22. solver.row2s = []string{"154832769"}
  23. solver.row3s = []string{"832769154"}
  24. solver.row4s = []string{"671945328"}
  25. solver.row5s = []string{"945328671"}
  26. solver.row6s = []string{"328671945"}
  27. solver.row7s = []string{"597416283"}
  28. solver.row8s = []string{"416283597"}
  29. solver.row9s = []string{"283597416"}
  30. // Set the rows to validate
  31. rows1Index := 0
  32. rows2Index := 0
  33. rows3Index := 0
  34. rows4Index := 0
  35. rows5Index := 0
  36. rows6Index := 0
  37. rows7Index := 0
  38. rows8Index := 0
  39. rows9Index := 0
  40. // Run the validator
  41. solver.validator(rows1Index, rows2Index, rows3Index, rows4Index, rows5Index, rows6Index, rows7Index, rows8Index, rows9Index)
  42. // Check the number of solutions
  43. if len(controller.Solutions) != 1 {
  44. t.Errorf("Expected 1 solution, got %d", len(controller.Solutions))
  45. }
  46. }