hackathon/question/q01/q01_test.go

60 lines
1.1 KiB
Go

package q01
import (
"fmt"
"strconv"
"strings"
"testing"
"github.com/hhhapz/codequest/models"
"github.com/hhhapz/codequest/question"
)
func TestQ01(t *testing.T) {
u := &models.User{
ID: "7",
}
q := question.QuestionByID("directions")
raw := q.Generate(u)
input := strings.Split(raw, "\n")
fmt.Println(raw)
res := total(solveP1(input))
fmt.Println(solveP1(input))
fmt.Println(solveP2(input))
if !q.Validate(u, question.Part1, strconv.Itoa(res)) {
t.Errorf("Expected question 1 part 1(%v) to be correct!", res)
}
res = total(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")
}
if t.Failed() {
t.Logf("Input:\n%v", raw)
}
}
func TestQ01Idempotent(t *testing.T) {
q := question.QuestionByID("directions")
u1 := &models.User{ID: "1"}
raw1 := q.Generate(u1)
u2 := &models.User{ID: "2"}
_ = q.Generate(u2)
raw2 := q.Generate(u1)
if raw1 != raw2 {
t.Errorf("Expected raw1 and raw2 to be the same")
}
}