sudoku-funpark/export/renderHumanReadable_test.go

46 lines
1.7 KiB
Go

package export
import (
"strings"
"testing"
"gitea.ligthert.net/golang/sudoku-funpark/controller"
"gitea.ligthert.net/golang/sudoku-funpark/outputter"
)
// This function will test the renderHumanReadable function.
// Starts off by creating a new Export struct.
// Creates a new Controller struct.
// Adds a solution to the Controller struct.
// Then it will execute the renderHumanReadable function.
// Check if the output is a string.
func TestRenderHumanReadable(t *testing.T) {
// Create a new Export struct.
export := Export{}
// Create a new Controller struct.
// Set output type to "human".
outp := outputter.Outputter{}
outp.OutputType = "short"
controller := controller.Controller{Outputter: &outp}
export.Controller = &controller
controller.Solutions = append(controller.Solutions, []string{"123456789", "987654321", "123456789", "987654321", "123456789", "987654321", "123456789", "987654321", "123456789"})
// Execute the renderHumanReadable function.
render := export.renderHumanReadable()
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"
// Check if the output is a string and not empty.
if render == "" {
t.Error("Expected a non-empty string, got", render)
}
// Check if the output is a string.
if strings.TrimSpace(render) != strings.TrimSpace(expected) {
t.Error("Expected a string, got", render)
}
}