-
Notifications
You must be signed in to change notification settings - Fork 0
/
Teste.py
272 lines (256 loc) · 10.6 KB
/
Teste.py
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
'''
###########################################################################
# #
# Fichier: Teste.py #
# Fait par: Guillaume Hamel-Gagné #
# Travail Finale: (Tron light cycle) #
# Dernière fois modifier: 28 May 2015 #
# #
# Afin de faire les testes il faut mettre #
# en commentaire game_intro() et #
# gameloop(gameDisplay) dans le fichier #
# Tron.py sinon le jeu sera lancé #
# #
###########################################################################
'''
import Tron
"""Les fonctions ci-dessous
n'on pas été tester, car il est difficile de
tester quand ce que sa retourne est une
classe comme une surface ou une image ou
un dictionnaire ayant besoin de variable
que l'on a automatiquement avec des fonctions
de pygame en lanceant le jeu.
orienterImage(img, direction)
toucheJoueur(event, direction,position_change, diminution, joueur)
text_object(text, color, size)
dictSprite(info)
dictTerrain(fenetre)
dictInfo(terrain)
-Tron.py
gestionLongueur(motoTab,longueurMoto, diminution)
"""
def testeChoixCouleur():
fonctionnel = True
chiffre = 1
cleInconnu = "abcdfz"
liste = [1]
couleurFonctionnel = "cyan"
try:
Tron.ChoixCouleur(chiffre)
except KeyError:
print("Fonctionnel")
else:
print("La fonction ChoixCouleur accepte les chiffres")
fonctionnel = False
try:
Tron.ChoixCouleur(cleInconnu)
except KeyError:
print("Fonctionnel")
else:
print("La fonction ChoixCouleur accepte une clé inconnu")
fonctionnel = False
try:
Tron.ChoixCouleur(liste)
except TypeError:
print("Fonctionnel")
else:
print("La fonction ChoixCouleur accepte les listes.")
fonctionnel = False
if fonctionnel:
try:
Tron.ChoixCouleur(couleurFonctionnel)
except KeyError:
print("La fonction ChoixCouleur ne fonctionne pas.")
else:
print("La fonction ChoixCouleur fonctionne entièrement.")
def testeMemeDiviseur():
fonctionnel = True
lettre = "a"
liste = ["a"]
donner = 418
base = 20
try:
Tron.memeDiviseur(lettre,base)
except TypeError:
print("Fonctionnel")
else:
print("La fonction memeDiviseur prend des strings pour la donner")
fonctionnel = False
try:
Tron.memeDiviseur(donner,lettre)
except TypeError:
print("Fonctionnel")
else:
print("La fonction memeDiviseur prend des strings pour la base")
fonctionnel = False
try:
Tron.memeDiviseur(liste,base)
except TypeError:
print("Fonctionnel")
else:
print("La fonction memeDiviseur prend des listes")
fonctionnel = False
if fonctionnel:
bonneRep = 400
if Tron.memeDiviseur(donner,base) == bonneRep:
print("La fonction memeDiviseur fonctionne entièrement.")
else:
print("La fonction memeDiviseur ne donne pas ce qu'elle doit.")
def testeSortieMap():
fonctionnel = True
positionX = 100
positionY = 200
lettre = "a"
liste = ["a"]
try:
Tron.sortieMap(lettre,positionY)
except TypeError:
print("Fonctionnel")
else:
print("""La fonction sortieMap prend des strings
pour l'une des positions""")
fonctionnel = False
try:
Tron.sortieMap(liste,positionY)
except TypeError:
print("Fonctionnel")
else:
print("La fonction sortieMap prend des listes")
fonctionnel = False
if fonctionnel:
if not Tron.sortieMap(positionX,positionY) and Tron.sortieMap(-40,0):
print("La fonction sortieMap fonctionne entièrement.")
else:
print("""La fonction sortieMap ne voit pas si
les coordonners sont hors ou dans la zone de jeu.""")
def testeCollisionJoueur():
fonctionnel = True
tabJoueur1 = [[999.0, 570.0, 'gauche', ''], [990.0, 570.0, 'gauche', ''],
[990, 570, 'haut', ''], [990, 560, 'haut', ''],
[990, 550, 'haut', ''], [990, 540, 'haut', ''],
[990, 530, 'haut', ''], [990, 520, 'haut', ''],
[990, 510, 'haut', ''], [990, 500, 'haut', ''],
[990, 490, 'droite', 'haut'], [999, 490, 'droite', ''],
[1008, 490, 'droite', ''], [1017, 490, 'droite', ''],
[1026, 490, 'droite', ''], [1035, 490, 'droite', ''],
[1044, 490, 'droite', ''], [1053, 490, 'droite', ''],
[1062, 490, 'haut', 'droite'], [1062, 480, 'haut', '']]
tabJoueur2 = [[1035.0, 570.0, 'droite', ''], [1044.0, 570.0, 'droite', ''],
[1044, 570, 'droite', ''], [1053, 570, 'droite', ''],
[1062, 570, 'droite', ''], [1071, 570, 'droite', ''],
[1080, 570, 'haut', 'droite'], [1080, 560, 'haut', ''],
[1080, 550, 'haut', ''], [1080, 540, 'gauche', ''],
[1071, 540, 'gauche', ''], [1062, 540, 'gauche', ''],
[1053, 540, 'gauche', ''], [1044, 540, 'gauche', ''],
[1035, 540, 'gauche', ''], [1026, 540, 'gauche', ''],
[1017, 540, 'gauche', ''], [1008, 540, 'gauche', ''],
[999, 540, 'gauche', ''], [990, 540, 'gauche', '']]
chiffre = 1
lettre = "a"
try:
Tron.collisionJoueur(chiffre,tabJoueur2)
except TypeError:
print("Fonctionnel")
else:
print("""La fonction collisionJoueur ne fonctionne pas.
Elle prend des chiffres.""")
fonctionnel = False
if fonctionnel:
if Tron.collisionJoueur(tabJoueur1,tabJoueur2) == "autre" \
and Tron.collisionJoueur(tabJoueur2,tabJoueur1) == "joueur":
print("La fonction collisionJoueur fonctionne entièrement.")
else:
print("La fonction ne donne pas les bonnes valeurs.")
def testeGestionCollisionJoueur():
fonctionnel = True
tabJoueur1 = [[999.0, 570.0, 'gauche', ''], [990.0, 570.0, 'gauche', ''],
[990, 570, 'haut', ''], [990, 560, 'haut', ''],
[990, 550, 'haut', ''], [990, 540, 'haut', ''],
[990, 530, 'haut', ''], [990, 520, 'haut', ''],
[990, 510, 'haut', ''], [990, 500, 'haut', ''],
[990, 490, 'droite', 'haut'], [999, 490, 'droite', ''],
[1008, 490, 'droite', ''], [1017, 490, 'droite', ''],
[1026, 490, 'droite', ''], [1035, 490, 'droite', ''],
[1044, 490, 'droite', ''], [1053, 490, 'droite', ''],
[1062, 490, 'haut', 'droite'], [1062, 480, 'haut', '']]
tabJoueur2 = [[1035.0, 570.0, 'droite', ''], [1044.0, 570.0, 'droite', ''],
[1044, 570, 'droite', ''], [1053, 570, 'droite', ''],
[1062, 570, 'droite', ''], [1071, 570, 'droite', ''],
[1080, 570, 'haut', 'droite'], [1080, 560, 'haut', ''],
[1080, 550, 'haut', ''], [1080, 540, 'gauche', ''],
[1071, 540, 'gauche', ''], [1062, 540, 'gauche', ''],
[1053, 540, 'gauche', ''], [1044, 540, 'gauche', ''],
[1035, 540, 'gauche', ''], [1026, 540, 'gauche', ''],
[1017, 540, 'gauche', ''], [1008, 540, 'gauche', ''],
[999, 540, 'gauche', ''], [990, 540, 'gauche', '']]
chiffre = 1
lettre = "a"
try:
Tron.gestionCollisionJoueur(chiffre,tabJoueur2)
except TypeError:
print("Fonctionnel")
else:
print("""La fonction gestionCollisionJoueur ne fonctionne pas.
Elle prend des chiffres.""")
fonctionnel = False
try:
Tron.gestionCollisionJoueur(lettre,tabJoueur2)
except (TypeError, IndexError):
print("Fonctionnel")
else:
print("""La fonction gestionCollisionJoueur ne fonctionne pas.
Elle prend des strings.""")
fonctionnel = False
if fonctionnel:
if Tron.gestionCollisionJoueur(tabJoueur1,tabJoueur2)[1]:
print("La fonction gestionCollisionJoueur fonctionne entièrement")
else:
print("""La fonction gestionCollisionJoueur ne donne pas
ce qu'elle devrait.""")
def testeGestionLongueur():
fonctionnel = True
motoTab = [[1035.0, 570.0, 'droite', ''], [1044.0, 570.0, 'droite', ''],
[1044, 570, 'droite', ''], [1053, 570, 'droite', ''],
[1062, 570, 'droite', ''], [1071, 570, 'droite', ''],
[1080, 570, 'haut', 'droite'], [1080, 560, 'haut', ''],
[1080, 550, 'haut', ''], [1080, 540, 'gauche', ''],
[1071, 540, 'gauche', ''], [1062, 540, 'gauche', ''],
[1053, 540, 'gauche', ''], [1044, 540, 'gauche', ''],
[1035, 540, 'gauche', ''], [1026, 540, 'gauche', ''],
[1017, 540, 'gauche', ''], [1008, 540, 'gauche', ''],
[999, 540, 'gauche', ''], [990, 540, 'gauche', '']]
longueurMoto = 5
diminution = 1
lettre = "a"
try:
Tron.gestionLongueur(motoTab,longueurMoto,lettre)
except ValueError:
print("Fonctionnel")
else:
print("""La fonction gestionLongueur ne fonctionne pas.
Elle prend un string en troisième argument.""")
fonctionnel = False
try:
Tron.gestionLongueur(motoTab,lettre,diminution)
except TypeError:
print("Fonctionnel")
else:
print("""La fonction gestionLongueur ne fonctionne pas.
Elle prend un string en deuxième argument.""")
fonctionnel = False
if fonctionnel:
motoTab, longueur = Tron.gestionLongueur(motoTab,
longueurMoto,
diminution)
if len(motoTab) == longueur:
print("La fonction gestionLongueur fonctionne entièrement.")
else:
print("""La fonction gestionLongueur ne donne pas
la réponse attendu""")
testeChoixCouleur()
testeMemeDiviseur()
testeSortieMap()
testeCollisionJoueur()
testeGestionCollisionJoueur()
testeGestionLongueur()