-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_quienesquien.py
222 lines (199 loc) · 7.68 KB
/
test_quienesquien.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
import pytest
from pyswip import Prolog
prolog = Prolog()
prolog.consult('src/quienesquien.pl')
@pytest.mark.levantar
def test_levantar_tablero():
'''
?- levantar_tablero(Tablero).
Tablero = [max, susan, tom, sam, anne, robert, anita, bill, bernard|...].
'''
query = list(prolog.query("levantar_tablero(Tablero)."))
# devuelve una lista de diccionarios,
# clave variable, valor propuestas de prolog
# print(pregunta)
#
# [{'Tablero': ['max', 'susan', 'tom', 'sam', 'anne', 'robert', 'anita',
# bill', 'bernard', 'alfred', 'frans', 'george', 'david', 'paul', 'joe',
# philip', 'peter', 'alex', 'eric', 'richard', 'charles', 'claire', 'maria',
# herman']}]
tablero = query[0]['Tablero']
assert tablero == ['max', 'susan', 'tom', 'sam', 'anne', 'robert',
'anita', 'bill', 'bernard', 'alfred', 'frans',
'george', 'david', 'paul', 'joe', 'philip',
'peter', 'alex', 'eric', 'richard', 'charles',
'claire', 'maria', 'herman']
@pytest.mark.bbdd
def test_personaje():
'''
?- personaje(tom /_).
false.
'''
isPersonaje = list(prolog.query("personaje(tom)."))
assert not isPersonaje
@pytest.mark.bbdd
def test_personajes():
'''
?- personaje(P /_).
P = herman ;
P = maria ;
P = claire ;
P = alfred ;
P = charles.
'''
query = list(prolog.query("personaje(P / _)."))
personajes = [respuesta['P'] for respuesta in query]
assert personajes == ['herman', 'maria', 'claire', 'charles',
'richard', 'eric', 'alex', 'peter',
'philip', 'joe', 'paul', 'david',
'george', 'frans', 'alfred', 'bernard',
'bill', 'anita', 'robert', 'anne',
'sam', 'tom', 'susan', 'max']
@pytest.mark.tiene
def test_tiene():
'''
?- tiene(maria, sombrero).
true ;
'''
tiene = bool(list(prolog.query("tiene(maria, sombrero).")))
assert tiene
@pytest.mark.tiene
def test_tiene_c_instancias():
'''
?- tiene(maria, C)
[{'C': 'mujer'}, {'C': 'pelo_largo'}, {'C': 'sombrero'}, {'C': 'pendientes'},
{'C': 'pelo_castaño'}, {'C': 'ojos_marrones'}, {'C': 'boca_pequeña'},
{'C': 'cejas_finas'}, {'C': 'nariz_pequeña'}]
'''
query = list(prolog.query("tiene(maria, C)."))
caracteristicas = [respuesta['C'] for respuesta in query]
assert caracteristicas == ['mujer', 'pelo_largo', 'sombrero',
'pendientes', 'pelo_castaño', 'ojos_marrones',
'boca_pequeña', 'cejas_finas', 'nariz_pequeña']
@pytest.mark.caracteristicas
def test_caracteristicas_personaje():
'''
?- caracteristicas(maria, C).
C = [mujer, pelo_largo, sombrero, pendientes,
pelo_castaño, ojos_marrones, boca_pequeña,
cejas_finas, nariz_pequeña].
'''
query = list(prolog.query("caracteristicas(maria, C)."))
caracteristicas = query[0]['C']
assert caracteristicas == ['mujer', 'pelo_largo', 'sombrero', 'pendientes',
'pelo_castaño', 'ojos_marrones', 'boca_pequeña',
'cejas_finas', 'nariz_pequeña']
@pytest.mark.objetivo
def test_es_objetivo():
'''
? - test([maria], maria).
maria Acertaste!
true .
'''
isGoal = list(prolog.query("test([maria], maria)"))
assert isGoal
@pytest.mark.objetivo
def test_no_es_objetivo():
'''
? - test([herman], maria).
Loose!
false.
'''
isGoal = list(prolog.query("test([herman], maria)."))
assert not isGoal
@pytest.mark.f_sucesora
@pytest.mark.bajar
def test_bajar_personaje():
'''
Salvar a los personajes con la caracteristica por la que preguntas.
?- bajar(sombrero, [maria, claire, herman], Supervivientes).
Supervivientes = [maria, claire] ;
'''
query = list(prolog.query("bajar(sombrero, [maria, claire, herman], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire']
@pytest.mark.f_sucesora
@pytest.mark.bajar
def test_bajar_personajes_sin_caracteristica():
'''
?- bajar(bigote, [maria, claire, herman], Supervivientes).
Supervivientes = [] ;
'''
query = list(prolog.query("bajar(bigote, [maria, claire, herman], S)."))
supervivientes = query[0]['S']
assert supervivientes == []
@pytest.mark.f_sucesora
@pytest.mark.bajar
def test_salvar_personajes_con_caracteristica():
'''
?- bajar(sombrero, [maria, claire, eric], Supervivientes).
Supervivientes = [maria, claire, eric] ;
'''
query = list(prolog.query("bajar(sombrero, [maria, claire, eric], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire', 'eric']
@pytest.mark.f_sucesora
@pytest.mark.bajar_not
def test_salvar_personajes_sin_caracteristica():
'''
?- bajar_not(bigote, [maria, claire, herman], Supervivientes).
Supervivientes = [maria, claire, herman] .
'''
query = list(prolog.query("bajar_not(bigote, [maria, claire, herman], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire', 'herman']
@pytest.mark.f_sucesora
@pytest.mark.bajar_not
def test_bajar_personajes_con_caracteristica():
'''
?- bajar_not(sombrero, [maria, claire, eric], Supervivientes).
Supervivientes = [maria, claire, herman] .
'''
query = list(prolog.query("bajar_not(sombrero, [maria, claire, eric], S)."))
supervivientes = query[0]['S']
assert supervivientes == []
@pytest.mark.f_sucesora
@pytest.mark.bajar
@pytest.mark.bajar_not
def test_f_sucesora_bajar_personajes_sin_rasgo_en_objetivo():
'''
?- f_sucesora(sombrero, [sombrero, bigote, gafas], [maria, claire, herman, alex], S).
S = [maria, claire] ;
'''
query = list(prolog.query("f_sucesora(sombrero, [sombrero, bigote, gafas], [maria, claire, herman, alex], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire']
query = list(prolog.query("f_sucesora(bigote, [sombrero, bigote, gafas], [maria, claire, herman, alex], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['alex']
@pytest.mark.f_sucesora
@pytest.mark.bajar
@pytest.mark.bajar_not
def test_f_sucesora_viven_personajes_sin_rasgo_no_objetivo():
'''
f_sucesora(mofletes, [sombrero, bigote, gafas], [maria, claire, herman, eric], S).
S = [maria, claire, herman, eric] ;
?- f_sucesora(gorra, [sombrero, bigote, gafas], [maria, claire, herman, eric], S).
S = [maria, claire, herman] ;
'''
query = list(prolog.query("f_sucesora(mofletes, [sombrero, bigote, gafas], [maria, claire, herman, eric], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire', 'herman', 'eric']
query = list(prolog.query("f_sucesora(gorra, [sombrero, bigote, gafas], [maria, claire, herman, eric], S)."))
supervivientes = query[0]['S']
assert supervivientes == ['maria', 'claire', 'herman']
@pytest.mark.add_not
def test_add_lista_a_lista_sin_repetidos():
'''
?- add_not([sombrero, mujer], [gorra, gafas, bigote], L).
L = [mujer, sombrero, gorra, gafas, bigote] ;
'''
query = list(prolog.query("add_not([sombrero, mujer], [gorra, gafas, bigote], L)."))
L = query[0]['L']
assert L == ['mujer', 'sombrero', 'gorra', 'gafas', 'bigote']
query = list(prolog.query("add_not([gorra, gafas], [gorra, gafas, bigote], L)."))
L = query[0]['L']
assert L == ['gorra', 'gafas', 'bigote']
query = list(prolog.query("add_not([gorra, gafas, sombrero, mujer], [gorra, gafas, bigote], L)."))
L = query[0]['L']
assert L == ['mujer', 'sombrero', 'gorra', 'gafas', 'bigote']