-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculations_test.go
192 lines (183 loc) · 6.3 KB
/
calculations_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//nolint:dupl // This file contains tests for multiple functions that are similar
package tests
import (
"github.com/K0ntr4/pokemonBattleAdvisor/src"
"testing"
)
func TestRankPokemonMoves(t *testing.T) {
testCases := []struct {
name string
pokemon pokemonbattleadvisor.Pokemon
enemy pokemonbattleadvisor.Pokemon
expectedIndex int
expectedValue float64
}{
{
name: "Super effective move but no damage, best move is false-swipe",
pokemon: pokemonbattleadvisor.Pokemon{
Moves: []pokemonbattleadvisor.Move{
{Name: "low-kick", Type: "fighting", Damage: 0.0, Accuracy: 1.0},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.0},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 1.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.7},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"dark", "ice"},
},
expectedIndex: 1,
expectedValue: 1.0,
},
{
name: "Super effective move with damage, best move is low-kick",
pokemon: pokemonbattleadvisor.Pokemon{
Moves: []pokemonbattleadvisor.Move{
{Name: "low-kick", Type: "fighting", Damage: 80.0, Accuracy: 1.0},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.0},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 1.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.7},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"dark", "ice"},
},
expectedIndex: 0,
expectedValue: 4.0,
},
{
name: "All moves are not very effective, best move is blizzard",
pokemon: pokemonbattleadvisor.Pokemon{
Moves: []pokemonbattleadvisor.Move{
{Name: "low-kick", Type: "fighting", Damage: 75.0, Accuracy: 1.0},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.0},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 1.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.7},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"electric"},
},
expectedIndex: 3,
expectedValue: 1.0,
},
}
for _, tc := range testCases {
testCase := tc
t.Run(testCase.name, func(t *testing.T) {
var result = pokemonbattleadvisor.RankPokemonMoves(&testCase.pokemon, &testCase.enemy)
if result[0].MoveIndex != testCase.expectedIndex {
t.Errorf("Expected index: %d, got: %d", testCase.expectedIndex, result[0].MoveIndex)
}
if result[0].Eff != testCase.expectedValue {
t.Errorf("Expected value: %f, got: %f", testCase.expectedValue, result[0].Eff)
}
})
}
}
func TestBestPokemonMoveAndShouldSwitch(t *testing.T) {
testCases := []struct {
name string
team []pokemonbattleadvisor.Pokemon
enemy pokemonbattleadvisor.Pokemon
expectedParty int
expectedMove int
expectedValue bool
}{
{
name: "Best pokemon against enemy dark and ice is second party member with first move",
team: []pokemonbattleadvisor.Pokemon{
{
Moves: []pokemonbattleadvisor.Move{
{Name: "poison-jab", Type: "poison", Damage: 80.0, Accuracy: 1.00},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.00},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 100.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.70},
},
},
{
Moves: []pokemonbattleadvisor.Move{
{Name: "moonblast", Type: "fairy", Damage: 95.0, Accuracy: 1.00},
{Name: "flash", Type: "normal", Damage: 0.0, Accuracy: 1.0},
{Name: "flamethrower", Type: "fire", Damage: 90.0, Accuracy: 1.00},
{Name: "double-slap", Type: "normal", Damage: 15.0, Accuracy: 0.85},
},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"dark", "ice"},
},
expectedParty: 1,
expectedMove: 0,
expectedValue: true,
},
{
name: "Best pokemon against enemy electric is first party member with first move",
team: []pokemonbattleadvisor.Pokemon{
{
Moves: []pokemonbattleadvisor.Move{
{Name: "poison-jab", Type: "poison", Damage: 80.0, Accuracy: 1.00},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.00},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 100.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.70},
},
},
{
Moves: []pokemonbattleadvisor.Move{
{Name: "moonblast", Type: "fairy", Damage: 95.0, Accuracy: 1.00},
{Name: "flash", Type: "normal", Damage: 0.0, Accuracy: 1.0},
{Name: "flamethrower", Type: "fire", Damage: 90.0, Accuracy: 1.00},
{Name: "double-slap", Type: "normal", Damage: 15.0, Accuracy: 0.85},
},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"electric"},
},
expectedParty: 0,
expectedMove: 0,
expectedValue: false,
},
{
name: "Best pokemon against enemy electric is second party member with first move",
team: []pokemonbattleadvisor.Pokemon{
{
Moves: []pokemonbattleadvisor.Move{
{Name: "moonblast", Type: "fairy", Damage: 95.0, Accuracy: 1.00},
{Name: "flash", Type: "normal", Damage: 0.0, Accuracy: 1.0},
{Name: "flamethrower", Type: "fire", Damage: 90.0, Accuracy: 1.00},
{Name: "double-slap", Type: "normal", Damage: 15.0, Accuracy: 0.85},
},
},
{
Moves: []pokemonbattleadvisor.Move{
{Name: "brick-break", Type: "fighting", Damage: 75.0, Accuracy: 1.00},
{Name: "false-swipe", Type: "normal", Damage: 40.0, Accuracy: 1.00},
{Name: "hail", Type: "ice", Damage: 0.0, Accuracy: 100.0},
{Name: "blizzard", Type: "ice", Damage: 110.0, Accuracy: 0.70},
},
},
},
enemy: pokemonbattleadvisor.Pokemon{
Types: []string{"electric"},
},
expectedParty: 0,
expectedMove: 0,
expectedValue: false,
},
}
for _, tc := range testCases {
testCase := tc
t.Run(testCase.name, func(t *testing.T) {
actualParty, actualMove, actualValue := pokemonbattleadvisor.BestPokemonMoveAndShouldSwitch(&testCase.team, &testCase.enemy)
if actualParty != testCase.expectedParty {
t.Errorf("Expected party: %d, got: %d", testCase.expectedParty, actualParty)
}
if actualMove != testCase.expectedMove {
t.Errorf("Expected move: %d, got: %d", testCase.expectedMove, actualMove)
}
if actualValue != testCase.expectedValue {
t.Errorf("Expected value: %t, got: %t", testCase.expectedValue, actualValue)
}
})
}
}