sudoku-funpark/solver/setWorkload_test.go

73 lines
1.8 KiB
Go

package solver
import (
"testing"
"gitea.ligthert.net/golang/sudoku-funpark/controller"
"gitea.ligthert.net/golang/sudoku-funpark/outputter"
)
// Function to test the setWorkload function.
func TestSetWorkload(t *testing.T) {
// Create a new Solver struct.
solver := Solver{}
// Create outputter struct.
outp := outputter.Outputter{}
// Set the output type to human.
outp.OutputType = "short"
// Set the outputter of the solver to the outputter.
solver.Outp = &outp
// Create a controller struct.
controller := controller.Controller{}
// Set the controller of the solver to the controller.
solver.Controller = &controller
// Execute the loadBlocks function.
solver.LoadBlocks()
// Provide controller.row1 with a value.
// This is the row that will be used in the findBlocks function.
controller.Row1 = "769104802"
// Fill the other rows with values.
solver.row2s = []string{"769104802"}
solver.row3s = []string{"769104802"}
solver.row4s = []string{"769104802"}
solver.row5s = []string{"769104802"}
solver.row6s = []string{"769104802"}
solver.row7s = []string{"769104802"}
solver.row8s = []string{"769104802"}
solver.row9s = []string{"769104802"}
// Call the findBlocks function with the row and the slice of rows.
solver.findBlocks(&controller.Row1, &solver.row1s)
// Divide the work between two agents.
solver.Controller.Split = 2
// Set the part of the workload that the first agent will do.
solver.Controller.Part = 1
// Call the splitWorkload function.
agents := solver.splitWorkload()
// Run the setWorkload function.
solver.setWorkload(agents)
// Check if the solver.row1s slice is as expected.
if len(solver.row1s) != 1 {
t.Errorf("Expected 1, got %v", len(solver.row1s))
}
// Check if the solver.Iter value is as expected.
if solver.Iter != 1 {
t.Errorf("Expected 9, got %v", solver.Iter)
}
}