func TestMemStore(t *testing.T) {
	var tests = []struct {
		metric   string
		t        int32
		count    uint64
		from     int32
		until    int32
		expected []float64
	}{
		{"foo", 120, 1, 119, 123, []float64{math.NaN(), 1}},
		{"foo", 120, 3, 119, 123, []float64{math.NaN(), 3}},
		{"foo", 121, 4, 119, 123, []float64{math.NaN(), 3, 4}},
		{"foo", 125, 4, 119, 125, []float64{math.NaN(), 3, 4, math.NaN(), math.NaN(), math.NaN(), 4}},
		{"foo", 129, 9, 125, 129, []float64{4, math.NaN(), math.NaN(), math.NaN(), 9}},
		{"foo", 124, 4, 120, 129, []float64{3, 4, math.NaN(), math.NaN(), 4, 4, math.NaN(), math.NaN(), math.NaN(), 9}},
		{"foo", 118, 12, 118, 129, []float64{24, math.NaN()}},
		{"foo", 130, 10, 0, 0, nil},
		{"foo", 131, 11, 0, 0, nil},
		{"foo", 128, 4, 127, 131, []float64{math.NaN(), 4, 9, 10, 11}},
		{"bar", 182, 11, 120, 240, []float64{math.NaN(), 11}},
		{"bar", 245, 22, 120, 240, []float64{11, 22}},
		{"bar", 305, 33, 120, 300, []float64{22, 33}},
	}
	w := NewWhisper(100, 10, 120, TrigramCutoff(1))
	var fooid MetricID = math.MaxUint32
	for _, tt := range tests {
		w.Set(tt.t, tt.metric, tt.count)
		if fooid == math.MaxUint32 {
			fooid, _ = w.l.Find("foo")
		}
		if tt.expected != nil {
			r := w.Fetch(tt.metric, tt.from, tt.until)
			if !nearlyEqual(r.Values, tt.expected) {
				t.Errorf("got %#v , want %#v\n", r.Values, tt.expected)
			}
		}
	}
	if _, ok := w.l.Find("foo"); ok {
		t.Errorf("foo not pruned from known keys")
	}
	w.Set(305, "baz", 1)
	bazid, ok := w.l.Find("baz")
	if !ok || bazid != fooid {
		t.Errorf("`baz` did not reuse fooid: got (%v,%v), want %v", bazid, ok, fooid)
	}
}
tests for memory-backed carbon store
package mwhisper
import (
	"math"
	"reflect"
	"testing"
)