@@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user