2021-12-21 10:18:12 +07:00
|
|
|
package q01
|
|
|
|
|
|
|
|
import (
|
2022-04-28 23:31:09 +07:00
|
|
|
"fmt"
|
2021-12-21 10:18:12 +07:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hhhapz/codequest/models"
|
|
|
|
"github.com/hhhapz/codequest/question"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestQ01(t *testing.T) {
|
|
|
|
u := &models.User{
|
2022-04-28 23:31:09 +07:00
|
|
|
ID: "7",
|
2021-12-21 10:18:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
q := question.QuestionByID("directions")
|
|
|
|
|
|
|
|
raw := q.Generate(u)
|
|
|
|
input := strings.Split(raw, "\n")
|
|
|
|
|
2022-04-28 23:31:09 +07:00
|
|
|
fmt.Println(raw)
|
2021-12-21 10:18:12 +07:00
|
|
|
res := total(solveP1(input))
|
2022-04-28 23:31:09 +07:00
|
|
|
fmt.Println(solveP1(input))
|
|
|
|
fmt.Println(solveP2(input))
|
|
|
|
|
2021-12-21 10:18:12 +07:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|