LoadBlocks_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // This function will test the loadBlocks function.
  8. // Starts off by creating a new Solver struct.
  9. // Then it will execute the loadBlocks function.
  10. // Check if there are 9! blocks loaded.
  11. // Check if the first block is "123456789".
  12. // check if the last block is "987654321".
  13. func TestLoadBlocks(t *testing.T) {
  14. // Do all the necesarry steps to initialize the solver.
  15. solver := Solver{}
  16. outp := outputter.Outputter{}
  17. outp.OutputType = "short"
  18. solver.Outp = &outp
  19. controller := controller.Controller{}
  20. solver.Controller = &controller
  21. solver.LoadBlocks()
  22. // Check if there are 9! blocks loaded.
  23. if len(solver.Controller.Blocks) != 362880 {
  24. t.Error("Expected 362880, got", len(solver.Controller.Blocks))
  25. }
  26. // Check if the first block is "123456789".
  27. if solver.Controller.Blocks[0] != "123456789" {
  28. t.Error("Expected 123456789, got", solver.Controller.Blocks[0])
  29. }
  30. // Check if the last block is "987654321".
  31. if solver.Controller.Blocks[362879] != "987654321" {
  32. t.Error("Expected 987654321, got", solver.Controller.Blocks[362879])
  33. }
  34. }