Day 16: Part 2

Signed-off-by: James Griffin <james@unsupervised.ca>
This commit is contained in:
2020-12-16 12:35:36 -04:00
parent b633408e52
commit 86b00e46a4
5 changed files with 200 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ func Test_ticket_loading(t *testing.T) {
t.Fail()
}
}
func Test_ticket_scanerror(t *testing.T) {
ts := ticketScanner{}
if err := ts.load("sample.txt"); err != nil {
@@ -38,3 +38,45 @@ func Test_ticket_scanerror(t *testing.T) {
t.Fail()
}
}
func Test_ticket_fieldDetection(t *testing.T) {
ts := ticketScanner{}
if err := ts.load("sample2.txt"); err != nil {
t.Log(err.Error())
t.FailNow()
}
ts.scanValid()
if len(ts.valid) != 3 {
t.Logf("Expected 3 valid tickets, got %d", len(ts.valid))
t.FailNow()
}
ts.determineFields()
if len(ts.fields) != 3 || ts.fields[0] != "row" || ts.fields[1] != "class" || ts.fields[2] != "seat" {
t.Logf("Expected row, class, seat but got %v", ts.fields)
t.Fail()
}
}
func Test_ticket_product(t *testing.T) {
ts := ticketScanner{}
if err := ts.load("sample3.txt"); err != nil {
t.Log(err.Error())
t.FailNow()
}
ts.scanValid()
if len(ts.valid) != 3 {
t.Logf("Expected 3 valid tickets, got %d", len(ts.valid))
t.FailNow()
}
ts.determineFields()
p := ts.fieldProduct("departure")
if p != 132 {
t.Logf("Expected 132 got %d", p)
t.Fail()
}
}