splitWorkload_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // Test the splitWorkload function.
  8. func TestSplitWorkload(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 = "human"
  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. // Call the findBlocks function with the row and the slice of rows.
  27. solver.findBlocks(&controller.Row1, &solver.row1s)
  28. // Divide the work between two agents.
  29. solver.Controller.Split = 2
  30. // Call the splitWorkload function.
  31. agents := solver.splitWorkload()
  32. // Check if the agents slice is as expected.
  33. if agents[0] != 1 || agents[1] != 1 {
  34. t.Errorf("Expected [1, 1], got %v", agents)
  35. }
  36. }