Esempio n. 1
0
func TestFloatDecoder_Empty(t *testing.T) {
	var dec tsm1.FloatDecoder
	if err := dec.SetBytes([]byte{}); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if dec.Next() {
		t.Fatalf("exp next == false, got true")
	}
}
Esempio n. 2
0
func BenchmarkFloatDecoder(b *testing.B) {
	s := tsm1.NewFloatEncoder()
	for _, tt := range TwoHoursData {
		s.Push(tt.v)
	}
	s.Finish()
	bytes, err := s.Bytes()
	if err != nil {
		b.Fatalf("unexpected error: %v", err)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		var it tsm1.FloatDecoder
		if err := it.SetBytes(bytes); err != nil {
			b.Fatalf("unexpected error creating float decoder: %v", err)
		}

		for j := 0; j < len(TwoHoursData); it.Next() {
			j++
		}
	}
}
Esempio n. 3
0
func Test_FloatEncoder_Quick(t *testing.T) {
	quick.Check(func(values []float64) bool {

		expected := values
		if values == nil {
			expected = []float64{}
		}

		// Write values to encoder.
		enc := tsm1.NewFloatEncoder()
		for _, v := range values {
			enc.Push(v)
		}
		enc.Finish()

		// Read values out of decoder.
		got := make([]float64, 0, len(values))
		b, err := enc.Bytes()
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}

		var dec tsm1.FloatDecoder
		if err := dec.SetBytes(b); err != nil {
			t.Fatal(err)
		}
		for dec.Next() {
			got = append(got, dec.Values())
		}

		// Verify that input and output values match.
		if !reflect.DeepEqual(expected, got) {
			t.Fatalf("mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", expected, got)
		}

		return true
	}, nil)
}
Esempio n. 4
0
func TestFloatEncoder_SimilarFloats(t *testing.T) {
	s := tsm1.NewFloatEncoder()
	want := []float64{
		6.00065e+06,
		6.000656e+06,
		6.000657e+06,

		6.000659e+06,
		6.000661e+06,
	}

	for _, v := range want {
		s.Push(v)
	}

	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	for _, w := range want {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		if w != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}
Esempio n. 5
0
func TestFloatEncoder_Roundtrip(t *testing.T) {
	s := tsm1.NewFloatEncoder()
	for _, p := range TwoHoursData {
		s.Push(p.v)
	}
	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	for _, w := range TwoHoursData {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		// t.Logf("it.Values()=(%+v, %+v)\n", time.Unix(int64(tt), 0), vv)
		if w.v != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w.v)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}
Esempio n. 6
0
func TestFloatEncoder_Simple(t *testing.T) {
	// Example from the paper
	s := tsm1.NewFloatEncoder()

	s.Push(12)
	s.Push(12)
	s.Push(24)

	// extra tests

	// floating point masking/shifting bug
	s.Push(13)
	s.Push(24)

	// delta-of-delta sizes
	s.Push(24)
	s.Push(24)
	s.Push(24)

	s.Finish()

	b, err := s.Bytes()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	var it tsm1.FloatDecoder
	if err := it.SetBytes(b); err != nil {
		t.Fatalf("unexpected error creating float decoder: %v", err)
	}

	want := []float64{
		12,
		12,
		24,

		13,
		24,

		24,
		24,
		24,
	}

	for _, w := range want {
		if !it.Next() {
			t.Fatalf("Next()=false, want true")
		}
		vv := it.Values()
		if w != vv {
			t.Errorf("Values()=(%v), want (%v)\n", vv, w)
		}
	}

	if it.Next() {
		t.Fatalf("Next()=true, want false")
	}

	if err := it.Error(); err != nil {
		t.Errorf("it.Error()=%v, want nil", err)
	}
}