package encoding

import "testing"

func TestCellRoundTrip(t *testing.T) {
	for letter := range byte(26) {
		c := Cell(letter, false)
		if IsEmpty(c) {
			t.Errorf("Cell(%d,false) reports empty", letter)
		}
		if IsBlank(c) {
			t.Errorf("Cell(%d,false) reports blank", letter)
		}
		if got := Letter(c); got != letter {
			t.Errorf("Letter(Cell(%d,false)) = %d", letter, got)
		}

		b := Cell(letter, true)
		if !IsBlank(b) {
			t.Errorf("Cell(%d,true) not blank", letter)
		}
		if got := Letter(b); got != letter {
			t.Errorf("Letter(Cell(%d,true)) = %d, want %d", letter, got, letter)
		}
	}
}

func TestEmpty(t *testing.T) {
	if !IsEmpty(Empty) {
		t.Error("IsEmpty(Empty) = false")
	}
	if IsEmpty(Cell(0, false)) {
		t.Error("IsEmpty(Cell('a')) = true")
	}
	// 'a' (index 0) must not collide with empty.
	if Cell(0, false) == Empty {
		t.Error("Cell('a') collides with Empty")
	}
}
