v0.4.1
This commit is contained in:
1 parent
439cc20dcf
commit
722a49f6bc
14 files changed
+564
-283
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package rrd
|
||||
|
||||
import "testing"
|
||||
|
||||
func f(v float64) *float64 { return &v }
|
||||
|
||||
func TestDownsampleNoop(t *testing.T) {
|
||||
in := []Point{{T: 1, V: f(1)}, {T: 2, V: f(2)}, {T: 3, V: f(3)}}
|
||||
out := downsample(in, 10)
|
||||
if len(out) != len(in) {
|
||||
t.Fatalf("expected no-op for points <= target, got %d points", len(out))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownsampleAveragesBuckets(t *testing.T) {
|
||||
// 10 points, 0..9, bucketed down to 5: expect roughly paired averages.
|
||||
in := make([]Point, 10)
|
||||
for i := range in {
|
||||
in[i] = Point{T: int64(i), V: f(float64(i))}
|
||||
}
|
||||
out := downsample(in, 5)
|
||||
if len(out) != 5 {
|
||||
t.Fatalf("expected 5 points, got %d", len(out))
|
||||
}
|
||||
want := []float64{0.5, 2.5, 4.5, 6.5, 8.5}
|
||||
for i, pt := range out {
|
||||
if pt.V == nil {
|
||||
t.Fatalf("bucket %d: expected a value, got nil", i)
|
||||
}
|
||||
if *pt.V != want[i] {
|
||||
t.Errorf("bucket %d: got %v, want %v", i, *pt.V, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownsampleSkipsNulls(t *testing.T) {
|
||||
in := []Point{{T: 1, V: f(2)}, {T: 2, V: nil}, {T: 3, V: f(4)}, {T: 4, V: nil}}
|
||||
out := downsample(in, 1)
|
||||
if len(out) != 1 {
|
||||
t.Fatalf("expected 1 bucket, got %d", len(out))
|
||||
}
|
||||
if out[0].V == nil || *out[0].V != 3 {
|
||||
t.Fatalf("expected average of non-null values (3), got %v", out[0].V)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownsampleAllNullBucketStaysNull(t *testing.T) {
|
||||
in := []Point{{T: 1, V: nil}, {T: 2, V: nil}}
|
||||
out := downsample(in, 1)
|
||||
if len(out) != 1 {
|
||||
t.Fatalf("expected 1 bucket, got %d", len(out))
|
||||
}
|
||||
if out[0].V != nil {
|
||||
t.Fatalf("expected nil for an all-null bucket, got %v", *out[0].V)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user