~bonbon/gmcts

gmcts/comparable_test.go -rw-r--r-- 1.1 KiB
f7bd5ecabonbon move v2.0.0 changes to v2 folder 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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{})
}