package tsdb

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestCompareLabels(t *testing.T) {
	cases := []struct {
		a, b []Label
		res  int
	}{
		{
			a:   []Label{},
			b:   []Label{},
			res: 0,
		},
		{
			a:   []Label{{"a", ""}},
			b:   []Label{{"a", ""}, {"b", ""}},
			res: -1,
		},
		{
			a:   []Label{{"a", ""}},
			b:   []Label{{"a", ""}},
			res: 0,
		},
		{
			a:   []Label{{"aa", ""}, {"aa", ""}},
			b:   []Label{{"aa", ""}, {"ab", ""}},
			res: -1,
		},
		{
			a:   []Label{{"aa", ""}, {"abb", ""}},
			b:   []Label{{"aa", ""}, {"ab", ""}},
			res: 1,
		},
	}
	for _, c := range cases {
		// Use constructor to ensure sortedness.
		a, b := NewLabels(c.a...), NewLabels(c.b...)

		require.Equal(t, c.res, compareLabels(a, b))
	}
}