-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder_test.go
128 lines (119 loc) · 2.41 KB
/
builder_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package go_carcassonne
import (
"encoding/json"
"testing"
bg "github.com/quibbble/go-boardgame"
"github.com/quibbble/go-boardgame/pkg/bgn"
"github.com/stretchr/testify/assert"
)
func Test_Builder_BGN(t *testing.T) {
builder := Builder{}
teams := []string{TeamA, TeamB}
carcassonne, err := builder.CreateWithBGN(&bg.BoardGameOptions{
Teams: teams,
MoreOptions: CarcassonneMoreOptions{
Seed: 123,
}})
if err != nil {
t.Error(err)
t.FailNow()
}
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamA,
ActionType: ActionPlaceTile,
MoreDetails: PlaceTileActionDetails{
X: 1,
Y: 0,
Tile: TileActionDetails{
Farm, Farm, Road, Road, NilStructure, false, false,
},
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamA,
ActionType: ActionPlaceToken,
MoreDetails: PlaceTokenActionDetails{
Pass: false,
X: 1,
Y: 0,
Type: Thief,
Side: SideLeft,
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
game := carcassonne.GetBGN()
carcassonneLoaded, err := builder.Load(game)
if err != nil {
t.Error(err)
t.FailNow()
}
expected, _ := json.Marshal(carcassonne)
actual, _ := json.Marshal(carcassonneLoaded)
assert.Equal(t, expected, actual)
}
func Test_Builder_Notations(t *testing.T) {
tags := map[string]string{
"Game": key,
"Teams": "TeamA, TeamB",
"Seed": "123",
}
tests := []struct {
name string
bgn *bgn.Game
shouldError bool
}{
{
name: "empty string should error",
bgn: &bgn.Game{},
shouldError: true,
},
{
name: "missing seed should error",
bgn: &bgn.Game{
Tags: map[string]string{
"Game": key,
"Teams": "TeamA, TeamB",
},
},
shouldError: true,
},
{
name: "should create a new game",
bgn: &bgn.Game{
Tags: tags,
},
shouldError: false,
},
{
name: "should create a new game and do actions",
bgn: &bgn.Game{
Tags: tags,
Actions: []bgn.Action{
{
TeamIndex: 0,
ActionKey: 'i',
Details: []string{"1", "0", "f", "f", "r", "r", "n", "f", "f"},
},
{
TeamIndex: 0,
ActionKey: 'o',
Details: []string{"f", "1", "0", "f", "lb"},
},
},
},
shouldError: false,
},
}
builder := Builder{}
for _, test := range tests {
_, err := builder.Load(test.bgn)
assert.Equal(t, test.shouldError, err != nil, test.name)
}
}