package rules

import "testing"

func sumCounts(c []int) int {
	s := 0
	for _, v := range c {
		s += v
	}
	return s
}

func TestRussianScrabble(t *testing.T) {
	rs := RussianScrabble()
	if err := rs.Validate(); err != nil {
		t.Fatal(err)
	}
	if rs.Size() != 33 {
		t.Errorf("alphabet size %d, want 33", rs.Size())
	}
	if n := sumCounts(rs.Counts); n != 102 || n+rs.Blanks != 104 {
		t.Errorf("bag = %d letters + %d blanks, want 102+2=104", n, rs.Blanks)
	}
	if rs.Bingo != 50 {
		t.Errorf("bonus %d, want 50", rs.Bingo)
	}
	if rs.Premium(7, 7) != DW {
		t.Errorf("centre premium %d, want DW", rs.Premium(7, 7))
	}
	if rs.Values[6] != 3 || rs.Counts[6] != 1 { // ё
		t.Errorf("ё = value %d count %d, want 3/1", rs.Values[6], rs.Counts[6])
	}
}

func TestErudit(t *testing.T) {
	rs := Erudit()
	if err := rs.Validate(); err != nil {
		t.Fatal(err)
	}
	if rs.Size() != 33 {
		t.Errorf("alphabet size %d, want 33", rs.Size())
	}
	if n := sumCounts(rs.Counts); n != 128 || n+rs.Blanks != 131 {
		t.Errorf("bag = %d letters + %d blanks, want 128+3=131", n, rs.Blanks)
	}
	if rs.Bingo != 15 {
		t.Errorf("bonus %d, want 15", rs.Bingo)
	}
	if rs.Center != 7*15+7 {
		t.Errorf("centre index %d, want %d", rs.Center, 7*15+7)
	}
	if rs.Premium(7, 7) != None {
		t.Errorf("centre premium %d, want None (Эрудит centre does not double)", rs.Premium(7, 7))
	}
	if rs.Counts[6] != 0 { // ё has no tile
		t.Errorf("ё count %d, want 0", rs.Counts[6])
	}
	if rs.Premium(0, 0) != TW {
		t.Errorf("corner premium %d, want TW (board otherwise standard)", rs.Premium(0, 0))
	}
}
