hackathon/question/q03/q03_test.go

51 lines
991 B
Go

package q03
import (
"strconv"
"strings"
"testing"
"github.com/hhhapz/codequest/models"
"github.com/hhhapz/codequest/question"
)
func TestQ03(t *testing.T) {
u := &models.User{
ID: "123",
}
q := question.QuestionByID("forestry")
raw := q.Generate(u)
t.Logf("INPUT:\n\n%s\n\n", raw)
input := make([][]int, 0, rows)
for _, row := range strings.Split(raw, "\n") {
s := make([]int, 0, cols)
for _, num := range strings.Split(row, "") {
n, _ := strconv.Atoi(num)
s = append(s, n)
}
input = append(input, s)
}
res := solveP1(input)
t.Logf("part 1 result: %d", res)
if !q.Validate(u, question.Part1, strconv.Itoa(res)) {
t.Errorf("Expected question 1 part 1(%v) to be correct!", res)
}
res = solveP2(input)
if !q.Validate(u, question.Part2, strconv.Itoa(res)) {
t.Errorf("Expected question 2 part 2(%v) to be correct!", res)
}
if q.Validate(u, question.Part1, "") {
t.Errorf("Expected bad input to be invalid")
}
t.Logf("Input:\n%v", raw)
}