Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions testdata/csverror.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2018-01-01T10:00:00.0Z,1.0
2018-01-02T10:00:00.0Z
2018-01-02T10:00:00.0Z,2.0
3 changes: 3 additions & 0 deletions testdata/floaterror.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2018-01-01T10:00:00.0Z,1.0
2018-01-02T10:00:00.0Z,str
2018-01-02T10:00:00.0Z,2.0
44 changes: 44 additions & 0 deletions timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func TestTimeSeriesRead(t *testing.T) {
if record != 1.0 {
t.Errorf("unexpected record value %#v", record)
}

testtime = time.Date(2018, 1, 1, 11, 0, 0, 0, time.UTC)
record, err = ts.Lookup(testtime)
err, ok := err.(InvalidTimestamp)
if !ok {
t.Fatalf("expected InvalidTimestamp")
}
err.Error()
}

func TestTimeSeriesRead_DateOnly(t *testing.T) {
Expand All @@ -46,6 +54,42 @@ func TestTimeSeriesRead_DateOnly(t *testing.T) {
}
}

func TestTimeSeriesRead_Error(t *testing.T) {
ts := NewTimeSeries()
err := ts.Read("testdata/csverror.csv")
if err == nil {
t.Fatal("expected error")
}
length := len(ts.records)
if length != 1 {
t.Errorf("unexpected series length %v", length)
}
}

func TestTimeSeriesRead_DateError(t *testing.T) {
ts := NewTimeSeries()
err := ts.Read("testdata/dateerror.csv")
if err == nil {
t.Fatal("expected error")
}
length := len(ts.records)
if length != 1 {
t.Errorf("unexpected series length %v", length)
}
}

func TestTimeSeriesRead_FloatError(t *testing.T) {
ts := NewTimeSeries()
err := ts.Read("testdata/floaterror.csv")
if err == nil {
t.Fatal("expected error")
}
length := len(ts.records)
if length != 1 {
t.Errorf("unexpected series length %v", length)
}
}

func TestTimeSeriesWrite(t *testing.T) {
ts := NewTimeSeries()
if err := ts.Read("testdata/simple.csv"); err != nil {
Expand Down