Exemplo n.º 1
0
func Test_SeriesIDs_Equals( // Test comparing SeriesIDs for equality.
	t *testing.T) {
	ids1 := tsdb.SeriesIDs{1, 2, 3}
	ids2 := tsdb.SeriesIDs{1, 2, 3}
	ids3 := tsdb.SeriesIDs{4, 5, 6}

	if !ids1.Equals(ids2) {
		t.Fatal("expected ids1 == ids2")
	} else if ids1.Equals(ids3) {
		t.Fatal("expected ids1 != ids3")
	}
}
Exemplo n.º 2
0
// Test removing one set of SeriesIDs from another.
func Test_SeriesIDs_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{1, 2, 3, 7}
	ids2 := tsdb.SeriesIDs{1, 3, 4, 5, 6}
	exp := tsdb.SeriesIDs{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{1}
	ids2 = tsdb.SeriesIDs{1, 2}
	exp = tsdb.SeriesIDs{}
	got = ids1.Reject(ids2)

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

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