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
|
// ignore_for_file: no-magic-number, avoid-late-keyword
import 'package:test/test.dart';
import 'package:x_haven_server/core/commands/add_character_command.dart';
import 'package:x_haven_server/core/commands/add_monster_command.dart';
import 'package:x_haven_server/core/commands/add_standee_command.dart';
import 'package:x_haven_server/core/commands/change_stat_commands/change_max_health_command.dart';
import 'package:x_haven_server/core/enums.dart';
import 'package:x_haven_server/core/state/game_state.dart';
import 'package:x_haven_server/core/service_locator.dart';
import '../test_helpers.dart';
void main() {
setUpAll(() async {
await setUpGame();
});
late Character character;
late Monster monster;
late MonsterInstance monsterInstance;
setUp(() {
getIt<GameState>().clearList();
AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
AddMonsterCommand(
"Zealot",
1,
false,
gameState: getIt<GameState>(),
).execute();
AddStandeeCommand(
1,
null,
"Zealot",
MonsterType.normal,
false,
gameState: getIt<GameState>(),
).execute();
character =
getIt<GameState>().currentList.firstWhere((e) => e is Character)
as Character;
monster =
getIt<GameState>().currentList.firstWhere((e) => e is Monster)
as Monster;
monsterInstance = monster.monsterInstances.first;
});
group('ChangeMaxHealthCommand', () {
test('should increase a character\'s max health', () {
// Arrange
final initialMaxHealth = character.characterState.maxHealth;
final command = ChangeMaxHealthCommand(
5,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(character.characterState.maxHealth, initialMaxHealth + 5);
});
test('should decrease a character\'s max health', () {
// Arrange
final initialMaxHealth = character.characterState.maxHealth;
final command = ChangeMaxHealthCommand(
-2,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(character.characterState.maxHealth, initialMaxHealth - 2);
});
test('should lower current health if it exceeds new max health', () {
// Arrange
final initialHealth = character.characterState.health;
expect(initialHealth, equals(character.characterState.maxHealth));
final command = ChangeMaxHealthCommand(
-3,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(
character.characterState.health,
character.characterState.maxHealth,
);
});
test(
'should update current health when max health changes if they were equal',
() {
// Arrange
final command = ChangeMaxHealthCommand(
5,
character.id,
character.id,
gameState: getIt<GameState>(),
);
final initialHealth = character.characterState.health;
final initialMaxHealth = character.characterState.maxHealth;
expect(initialHealth, initialMaxHealth);
// Act
command.execute();
// Assert
expect(character.characterState.health, initialHealth + 5);
expect(character.characterState.maxHealth, initialMaxHealth + 5);
},
);
test('should not set max health to 0 or below', () {
// Arrange
final initialMaxHealth = character.characterState.maxHealth;
final command = ChangeMaxHealthCommand(
-100,
character.id,
character.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(character.characterState.maxHealth, initialMaxHealth);
});
test('should increase a monster instance\'s max health', () {
// Arrange
final initialMaxHealth = monsterInstance.maxHealth;
final command = ChangeMaxHealthCommand(
3,
monsterInstance.getId(),
monster.id,
gameState: getIt<GameState>(),
);
// Act
command.execute();
// Assert
expect(monsterInstance.maxHealth, initialMaxHealth + 3);
});
test('describe should return correct string for increasing max health', () {
final command = ChangeMaxHealthCommand(
5,
'Blinkblade',
'Blinkblade',
gameState: getIt<GameState>(),
);
expect(command.describe(), "Increase Blinkblade's max health");
});
test('describe should return correct string for decreasing max health', () {
final command = ChangeMaxHealthCommand(
-5,
'Blinkblade',
'Blinkblade',
gameState: getIt<GameState>(),
);
expect(command.describe(), "Decrease Blinkblade's max health");
});
});
}
|