54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package solver
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"gitea.ligthert.net/golang/sudoku-funpark/controller"
|
|
"gitea.ligthert.net/golang/sudoku-funpark/outputter"
|
|
)
|
|
|
|
// TestfindBlocks tests the findBlocks function.
|
|
// It defines the solver struct
|
|
// and calls the findBlocks function with a row and a slice of rows.
|
|
// It then checks if the slice of rows is as expected.
|
|
func TestFindBlocks(t *testing.T) {
|
|
|
|
// Create a new Solver struct.
|
|
solver := Solver{}
|
|
|
|
// Create outputter struct.
|
|
outp := outputter.Outputter{}
|
|
|
|
// Set the output type to human.
|
|
outp.OutputType = "human"
|
|
|
|
// 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"
|
|
|
|
// Call the findBlocks function with the row and the slice of rows.
|
|
solver.findBlocks(&controller.Row1, &solver.row1s)
|
|
|
|
// A slice with the expected results.
|
|
expected := []string{"769154832", "769134852"}
|
|
|
|
// Check if the slice of rows1 is same as expected variable.
|
|
if slices.Equal(solver.row1s, expected) {
|
|
t.Errorf("Expected %v, got %v", expected, solver.row1s)
|
|
}
|
|
|
|
}
|