package mood

import (
	"sort"
	"testing"
)

func TestOf(t *testing.T) {
	cases := []struct {
		name string
		in   []string
		want []string
	}{
		{"synonyms collapse", []string{"sad", "melancholy", "melancholic"}, []string{"melancholic"}},
		{"case + whitespace", []string{" CHILL ", "Mellow"}, []string{"chill"}},
		{"multiple buckets", []string{"energetic", "dark"}, []string{"dark", "energetic"}},
		{"genre-only → none", []string{"rock", "shoegaze", "post-punk"}, nil},
		{"empty", nil, nil},
	}
	for _, c := range cases {
		got := Of(c.in)
		sort.Strings(got)
		want := append([]string(nil), c.want...)
		sort.Strings(want)
		if len(got) != len(want) {
			t.Errorf("%s: Of(%v) = %v, want %v", c.name, c.in, got, want)
			continue
		}
		for i := range got {
			if got[i] != want[i] {
				t.Errorf("%s: Of(%v) = %v, want %v", c.name, c.in, got, want)
				break
			}
		}
	}
}

func TestOf_Dedupes(t *testing.T) {
	// Three tags mapping to the same bucket yield one entry.
	if got := Of([]string{"chill", "mellow", "relaxed"}); len(got) != 1 || got[0] != "chill" {
		t.Errorf("Of dedupe = %v, want [chill]", got)
	}
}
