findBlocks_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package solver
  2. import (
  3. "slices"
  4. "testing"
  5. "gitea.ligthert.net/golang/sudoku-funpark/controller"
  6. "gitea.ligthert.net/golang/sudoku-funpark/outputter"
  7. )
  8. // TestfindBlocks tests the findBlocks function.
  9. // It defines the solver struct
  10. // and calls the findBlocks function with a row and a slice of rows.
  11. // It then checks if the slice of rows is as expected.
  12. func TestFindBlocks(t *testing.T) {
  13. // Create a new Solver struct.
  14. solver := Solver{}
  15. // Create outputter struct.
  16. outp := outputter.Outputter{}
  17. // Set the output type to human.
  18. outp.OutputType = "human"
  19. // Set the outputter of the solver to the outputter.
  20. solver.Outp = &outp
  21. // Create a controller struct.
  22. controller := controller.Controller{}
  23. // Set the controller of the solver to the controller.
  24. solver.Controller = &controller
  25. // Execute the loadBlocks function.
  26. solver.LoadBlocks()
  27. // Provide controller.row1 with a value.
  28. // This is the row that will be used in the findBlocks function.
  29. controller.Row1 = "769104802"
  30. // Call the findBlocks function with the row and the slice of rows.
  31. solver.findBlocks(&controller.Row1, &solver.row1s)
  32. // A slice with the expected results.
  33. expected := []string{"769154832", "769134852"}
  34. // Check if the slice of rows1 is same as expected variable.
  35. if slices.Equal(solver.row1s, expected) {
  36. t.Errorf("Expected %v, got %v", expected, solver.row1s)
  37. }
  38. }