package gps import ( "testing" testex "juju.net.nz/testex" ) func TestStrings(t *testing.T) { p := &Parser{fields: []string{"foo", "bar"}} if p.GetString(0) != "foo" { t.Error(); } if p.GetString(1) != "bar" { t.Error(); } if p.Err != nil { t.Error(); } // Empty string on missing field. if p.GetString(2) != "" { t.Error(); } if p.Err == nil { t.Error(); } } func TestFloat(t *testing.T) { p := &Parser{fields: []string{"123.4", "", "bar"}} if p.GetFloat(0) != 123.4 { t.Error(); } if p.Err != nil { t.Error(); } // Empty string is zero. if p.GetFloat(1) != 0 { t.Error(); } if p.Err != nil { t.Error(); } // Non-strings cause an error. if p.GetFloat(2) != 0 { t.Error(); } if p.Err == nil { t.Error(); } } func TestTime(t *testing.T) { p := &Parser{fields: []string{"170834.5"}} expect := 34.5 + 8*60 + 17*60*60 if p.GetTime(0) != expect { t.Error(); } if p.Err != nil { t.Error(); } } func TestLatLong(t *testing.T) { p := &Parser{fields: []string{"4124.8963", "N"}} expect := 41 + 24.8963/60 if !testex.Close(t, p.GetLatLong(0), expect) { t.Error(); } if p.Err != nil { t.Error(); } }