Esempio n. 1
0
// Test comparing SeriesIDs for equality.
func TestSeriesIDs_Equals(t *testing.T) {
	ids1 := tsdb.SeriesIDs([]uint64{1, 2, 3})
	ids2 := tsdb.SeriesIDs([]uint64{1, 2, 3})
	ids3 := tsdb.SeriesIDs([]uint64{4, 5, 6})

	if !ids1.Equals(ids2) {
		t.Fatal("expected ids1 == ids2")
	} else if ids1.Equals(ids3) {
		t.Fatal("expected ids1 != ids3")
	}
}
Esempio n. 2
0
// Test removing one set of SeriesIDs from another.
func TestSeriesIDs_Reject(t *testing.T) {
	// Test all branches of if-else, exit loop because of 'j < len(r)', and append remainder from left.
	ids1 := tsdb.SeriesIDs([]uint64{1, 2, 3, 7})
	ids2 := tsdb.SeriesIDs([]uint64{1, 3, 4, 5, 6})
	exp := tsdb.SeriesIDs([]uint64{2, 7})
	got := ids1.Reject(ids2)

	if !exp.Equals(got) {
		t.Fatalf("exp=%v, got=%v", exp, got)
	}

	// Test exit because of 'i < len(l)'.
	ids1 = tsdb.SeriesIDs([]uint64{1})
	ids2 = tsdb.SeriesIDs([]uint64{1, 2})
	exp = tsdb.SeriesIDs{}
	got = ids1.Reject(ids2)

	if !exp.Equals(got) {
		t.Fatalf("exp=%v, got=%v", exp, got)
	}
}
Esempio n. 3
0
// Test intersecting sets of SeriesIDs.
func TestSeriesIDs_Intersect(t *testing.T) {
	// Test swaping l & r, all branches of if-else, and exit loop when 'j < len(r)'
	ids1 := tsdb.SeriesIDs([]uint64{1, 3, 4, 5, 6})
	ids2 := tsdb.SeriesIDs([]uint64{1, 2, 3, 7})
	exp := tsdb.SeriesIDs([]uint64{1, 3})
	got := ids1.Intersect(ids2)

	if !exp.Equals(got) {
		t.Fatalf("exp=%v, got=%v", exp, got)
	}

	// Test exit for loop when 'i < len(l)'
	ids1 = tsdb.SeriesIDs([]uint64{1})
	ids2 = tsdb.SeriesIDs([]uint64{1, 2})
	exp = tsdb.SeriesIDs([]uint64{1})
	got = ids1.Intersect(ids2)

	if !exp.Equals(got) {
		t.Fatalf("exp=%v, got=%v", exp, got)
	}
}