~bonbon/gmcts

838143eea24d4514dfce127bb0d6ea30396851da — bonbon 1 year, 6 months ago b588a96
add tests for state/action comparability
1 files changed, 55 insertions(+), 0 deletions(-)

A comparable_test.go
A comparable_test.go => comparable_test.go +55 -0
@@ 0,0 1,55 @@
package gmcts

import "testing"

//comparableState tests the comparable action requirement of gmcts, as
//the GetActions method returns a noncomparable action.
type comparableState struct{}

//nonComparableState tests the comparable state requirement of gmcts.
type nonComparableState struct {
	comparableState
	_ []int
}

func (n comparableState) GetActions() []Action {
	return []Action{nonComparableState{}}
}

func (n comparableState) ApplyAction(a Action) (Game, error) {
	return n, nil
}

func (n comparableState) IsTerminal() bool {
	return true
}

func (n comparableState) Player() Player {
	return 0
}

func (n comparableState) Winners() []Player {
	return nil
}

func TestNonComparableState(t *testing.T) {
	//Calling NewMCTS should panic, as the nonComparableState is, as
	//the name suggests, not comparable.
	defer func() {
		if r := recover(); r == nil {
			t.FailNow()
		}
	}()
	NewMCTS(nonComparableState{})
}

func TestNonComparableAction(t *testing.T) {
	//Calling NewMCTS should panic, as the actions from comparableState
	//are not comparable.
	defer func() {
		if r := recover(); r == nil {
			t.FailNow()
		}
	}()
	NewMCTS(comparableState{})
}