|
@@ -7,19 +7,14 @@ import (
|
|
|
|
|
|
func TestSimulation_SimulateOneInitialWord(t *testing.T) {
|
|
func TestSimulation_SimulateOneInitialWord(t *testing.T) {
|
|
type fields struct {
|
|
type fields struct {
|
|
- Game *Game
|
|
|
|
- BestGuess string
|
|
|
|
- BestGuessRounds int
|
|
|
|
- SuccessCount int
|
|
|
|
- FailCount int
|
|
|
|
- TotalRounds int
|
|
|
|
|
|
+ Words []string
|
|
}
|
|
}
|
|
type args struct {
|
|
type args struct {
|
|
- game *Game
|
|
|
|
initialWord string
|
|
initialWord string
|
|
}
|
|
}
|
|
tests := []struct {
|
|
tests := []struct {
|
|
name string
|
|
name string
|
|
|
|
+ words []string
|
|
fields fields
|
|
fields fields
|
|
args args
|
|
args args
|
|
wantedLossCount int
|
|
wantedLossCount int
|
|
@@ -27,24 +22,9 @@ func TestSimulation_SimulateOneInitialWord(t *testing.T) {
|
|
wantedTotalRounds int
|
|
wantedTotalRounds int
|
|
}{
|
|
}{
|
|
{
|
|
{
|
|
- name: "simple game with no losses",
|
|
|
|
- fields: fields{
|
|
|
|
- Game: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "abb": {Word: "abb"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
|
|
+ name: "simple game with no losses",
|
|
|
|
+ words: []string{"aaa", "aab", "abb"},
|
|
args: args{
|
|
args: args{
|
|
- game: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "abb": {Word: "abb"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
initialWord: "aaa",
|
|
initialWord: "aaa",
|
|
},
|
|
},
|
|
wantedLossCount: 0,
|
|
wantedLossCount: 0,
|
|
@@ -52,28 +32,9 @@ func TestSimulation_SimulateOneInitialWord(t *testing.T) {
|
|
wantedTotalRounds: 5,
|
|
wantedTotalRounds: 5,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "simple failed game",
|
|
|
|
- fields: fields{
|
|
|
|
- Game: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "aac": {Word: "aac"},
|
|
|
|
- "aad": {Word: "aad"},
|
|
|
|
- "aae": {Word: "aae"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
|
|
+ name: "simple failed game",
|
|
|
|
+ words: []string{"aaa", "aab", "aac", "aad", "aae"},
|
|
args: args{
|
|
args: args{
|
|
- game: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "aac": {Word: "aac"},
|
|
|
|
- "aad": {Word: "aad"},
|
|
|
|
- "aae": {Word: "aae"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
initialWord: "aaa",
|
|
initialWord: "aaa",
|
|
},
|
|
},
|
|
wantedLossCount: 1,
|
|
wantedLossCount: 1,
|
|
@@ -83,25 +44,27 @@ func TestSimulation_SimulateOneInitialWord(t *testing.T) {
|
|
}
|
|
}
|
|
for _, tt := range tests {
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
+
|
|
|
|
+ game := &Game{}
|
|
|
|
+ game.Words = make(map[string]*Word)
|
|
|
|
+ for _, word := range tt.words {
|
|
|
|
+ game.Words[word] = &Word{Word: word}
|
|
|
|
+ }
|
|
|
|
+
|
|
s := Simulation{
|
|
s := Simulation{
|
|
- Game: tt.fields.Game,
|
|
|
|
- BestGuess: tt.fields.BestGuess,
|
|
|
|
- BestGuessRounds: tt.fields.BestGuessRounds,
|
|
|
|
- SuccessCount: tt.fields.SuccessCount,
|
|
|
|
- FailCount: tt.fields.FailCount,
|
|
|
|
- TotalRounds: tt.fields.TotalRounds,
|
|
|
|
|
|
+ Game: game,
|
|
}
|
|
}
|
|
- lossCount, maxRounds, totalRounds := s.SimulateOneInitialWord(tt.args.game, tt.args.initialWord)
|
|
|
|
- assert.Equalf(t, tt.wantedLossCount, lossCount, "loss count for %v => %v", tt.args.game, tt.args.initialWord)
|
|
|
|
- assert.Equalf(t, tt.wantedMaxRounds, maxRounds, "max rounds for %v => %v)", tt.args.game, tt.args.initialWord)
|
|
|
|
- assert.Equalf(t, tt.wantedTotalRounds, totalRounds, "total rounds for %v => %v)", tt.args.game, tt.args.initialWord)
|
|
|
|
|
|
+
|
|
|
|
+ lossCount, maxRounds, totalRounds := s.SimulateOneInitialWord(game, tt.args.initialWord)
|
|
|
|
+ assert.Equalf(t, tt.wantedLossCount, lossCount, "loss count for %v => %v", game, tt.args.initialWord)
|
|
|
|
+ assert.Equalf(t, tt.wantedMaxRounds, maxRounds, "max rounds for %v => %v)", game, tt.args.initialWord)
|
|
|
|
+ assert.Equalf(t, tt.wantedTotalRounds, totalRounds, "total rounds for %v => %v)", game, tt.args.initialWord)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
type fields struct {
|
|
type fields struct {
|
|
- Game *Game
|
|
|
|
BestGuess string
|
|
BestGuess string
|
|
BestGuessRounds int
|
|
BestGuessRounds int
|
|
SuccessCount int
|
|
SuccessCount int
|
|
@@ -109,12 +72,12 @@ func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
TotalRounds int
|
|
TotalRounds int
|
|
}
|
|
}
|
|
type args struct {
|
|
type args struct {
|
|
- simulatedGame *Game
|
|
|
|
- initialWord string
|
|
|
|
- answer string
|
|
|
|
|
|
+ initialWord string
|
|
|
|
+ answer string
|
|
}
|
|
}
|
|
tests := []struct {
|
|
tests := []struct {
|
|
name string
|
|
name string
|
|
|
|
+ words []string
|
|
fields fields
|
|
fields fields
|
|
args args
|
|
args args
|
|
won bool
|
|
won bool
|
|
@@ -122,15 +85,9 @@ func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
}{
|
|
}{
|
|
|
|
|
|
{
|
|
{
|
|
- name: "initial word is answer",
|
|
|
|
|
|
+ name: "initial word is answer",
|
|
|
|
+ words: []string{"aaa", "aab", "abb"},
|
|
args: args{
|
|
args: args{
|
|
- simulatedGame: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "abb": {Word: "abb"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
initialWord: "aaa",
|
|
initialWord: "aaa",
|
|
answer: "aaa",
|
|
answer: "aaa",
|
|
},
|
|
},
|
|
@@ -138,15 +95,9 @@ func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
numRounds: 1,
|
|
numRounds: 1,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "one guess to get answer",
|
|
|
|
|
|
+ name: "one guess to get answer",
|
|
|
|
+ words: []string{"aaa", "aab", "abb"},
|
|
args: args{
|
|
args: args{
|
|
- simulatedGame: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "abb": {Word: "abb"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
initialWord: "aaa",
|
|
initialWord: "aaa",
|
|
answer: "aab",
|
|
answer: "aab",
|
|
},
|
|
},
|
|
@@ -154,17 +105,9 @@ func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
numRounds: 2,
|
|
numRounds: 2,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- name: "one guess to get answer",
|
|
|
|
|
|
+ name: "one guess to get answer",
|
|
|
|
+ words: []string{"aaa", "aab", "aac", "aad", "aae"},
|
|
args: args{
|
|
args: args{
|
|
- simulatedGame: &Game{
|
|
|
|
- Words: map[string]*Word{
|
|
|
|
- "aaa": {Word: "aaa"},
|
|
|
|
- "aab": {Word: "aab"},
|
|
|
|
- "aac": {Word: "aac"},
|
|
|
|
- "aad": {Word: "aad"},
|
|
|
|
- "aae": {Word: "aae"},
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
initialWord: "aaa",
|
|
initialWord: "aaa",
|
|
answer: "aae",
|
|
answer: "aae",
|
|
},
|
|
},
|
|
@@ -174,10 +117,20 @@ func TestSimulation_SimulateOneGame(t *testing.T) {
|
|
}
|
|
}
|
|
for _, tt := range tests {
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
- s := Simulation{}
|
|
|
|
- got, got1 := s.SimulateOneGame(tt.args.simulatedGame, tt.args.initialWord, tt.args.answer)
|
|
|
|
- assert.Equalf(t, tt.won, got, "SimulateOneGame(%v, %v, %v)", tt.args.simulatedGame, tt.args.initialWord, tt.args.answer)
|
|
|
|
- assert.Equalf(t, tt.numRounds, got1, "SimulateOneGame(%v, %v, %v)", tt.args.simulatedGame, tt.args.initialWord, tt.args.answer)
|
|
|
|
|
|
+
|
|
|
|
+ game := &Game{}
|
|
|
|
+ game.Words = make(map[string]*Word)
|
|
|
|
+ for _, word := range tt.words {
|
|
|
|
+ game.Words[word] = &Word{Word: word}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ s := Simulation{
|
|
|
|
+ Game: game,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ got, got1 := s.SimulateOneGame(game, tt.args.initialWord, tt.args.answer)
|
|
|
|
+ assert.Equalf(t, tt.won, got, "SimulateOneGame(%v, %v, %v)", game, tt.args.initialWord, tt.args.answer)
|
|
|
|
+ assert.Equalf(t, tt.numRounds, got1, "SimulateOneGame(%v, %v, %v)", game, tt.args.initialWord, tt.args.answer)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|