renderHumanReadable_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package export
  2. import (
  3. "strings"
  4. "testing"
  5. "gitea.ligthert.net/golang/sudoku-funpark/controller"
  6. "gitea.ligthert.net/golang/sudoku-funpark/outputter"
  7. )
  8. // This function will test the renderHumanReadable function.
  9. // Starts off by creating a new Export struct.
  10. // Creates a new Controller struct.
  11. // Adds a solution to the Controller struct.
  12. // Then it will execute the renderHumanReadable function.
  13. // Check if the output is a string.
  14. func TestRenderHumanReadable(t *testing.T) {
  15. // Create a new Export struct.
  16. export := Export{}
  17. // Create a new Controller struct.
  18. // Set output type to "human".
  19. outp := outputter.Outputter{}
  20. outp.OutputType = "short"
  21. controller := controller.Controller{Outputter: &outp}
  22. export.Controller = &controller
  23. controller.Solutions = append(controller.Solutions, []string{"123456789", "987654321", "123456789", "987654321", "123456789", "987654321", "123456789", "987654321", "123456789"})
  24. // Execute the renderHumanReadable function.
  25. render := export.renderHumanReadable()
  26. expected := "\nSolution #1:\n╔═══════════╗\n║123│456│789╢\n║987│654│321╢\n║123│456│789╢\n╟───┼───┼───╢\n║987│654│321╢\n║123│456│789╢\n║987│654│321╢\n╟───┼───┼───╢\n║123│456│789╢\n║987│654│321╢\n║123│456│789╢\n╚═══════════╝\n"
  27. // Check if the output is a string and not empty.
  28. if render == "" {
  29. t.Error("Expected a non-empty string, got", render)
  30. }
  31. // Check if the output is a string.
  32. if strings.TrimSpace(render) != strings.TrimSpace(expected) {
  33. t.Error("Expected a string, got", render)
  34. }
  35. }