package engine

import (
	"errors"
	"testing"
)

func TestSetupBagEnglish(t *testing.T) {
	bag, err := SetupBag(VariantEnglish)
	if err != nil {
		t.Fatalf("SetupBag: %v", err)
	}
	// English Scrabble: 98 lettered tiles + 2 blanks = 100.
	if len(bag) != 100 {
		t.Fatalf("bag size = %d, want 100", len(bag))
	}
	blanks, aCount := 0, 0
	for _, tl := range bag {
		switch {
		case tl.Blank:
			blanks++
			if tl.Rank != BlankRank {
				t.Errorf("blank rank = %d, want %d", tl.Rank, BlankRank)
			}
			if tl.Letter != blankLetter {
				t.Errorf("blank letter = %q, want %q", tl.Letter, blankLetter)
			}
		case tl.Letter == "a":
			aCount++
			if tl.Rank != 0 {
				t.Errorf("'a' rank = %d, want 0 (closest to A)", tl.Rank)
			}
		}
	}
	if blanks != 2 {
		t.Errorf("blanks = %d, want 2", blanks)
	}
	if aCount != 9 {
		t.Errorf("'a' count = %d, want 9", aCount)
	}
}

func TestSetupBagUnknownVariant(t *testing.T) {
	if _, err := SetupBag(Variant(99)); !errors.Is(err, ErrUnknownVariant) {
		t.Fatalf("err = %v, want ErrUnknownVariant", err)
	}
}
