setWorkload_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // Function to test the setWorkload function.
  8. func TestSetWorkload(t *testing.T) {
  9. // Create a new Solver struct.
  10. solver := Solver{}
  11. // Create outputter struct.
  12. outp := outputter.Outputter{}
  13. // Set the output type to human.
  14. outp.OutputType = "short"
  15. // Set the outputter of the solver to the outputter.
  16. solver.Outp = &outp
  17. // Create a controller struct.
  18. controller := controller.Controller{}
  19. // Set the controller of the solver to the controller.
  20. solver.Controller = &controller
  21. // Execute the loadBlocks function.
  22. solver.LoadBlocks()
  23. // Provide controller.row1 with a value.
  24. // This is the row that will be used in the findBlocks function.
  25. controller.Row1 = "769104802"
  26. // Fill the other rows with values.
  27. solver.row2s = []string{"769104802"}
  28. solver.row3s = []string{"769104802"}
  29. solver.row4s = []string{"769104802"}
  30. solver.row5s = []string{"769104802"}
  31. solver.row6s = []string{"769104802"}
  32. solver.row7s = []string{"769104802"}
  33. solver.row8s = []string{"769104802"}
  34. solver.row9s = []string{"769104802"}
  35. // Call the findBlocks function with the row and the slice of rows.
  36. solver.findBlocks(&controller.Row1, &solver.row1s)
  37. // Divide the work between two agents.
  38. solver.Controller.Split = 2
  39. // Set the part of the workload that the first agent will do.
  40. solver.Controller.Part = 1
  41. // Call the splitWorkload function.
  42. agents := solver.splitWorkload()
  43. // Run the setWorkload function.
  44. solver.setWorkload(agents)
  45. // Check if the solver.row1s slice is as expected.
  46. if len(solver.row1s) != 1 {
  47. t.Errorf("Expected 1, got %v", len(solver.row1s))
  48. }
  49. // Check if the solver.Iter value is as expected.
  50. if solver.Iter != 1 {
  51. t.Errorf("Expected 9, got %v", solver.Iter)
  52. }
  53. }