15
15
import Solver , Initialise
16
16
import Transfer
17
17
18
+
18
19
class TestStringMethods (unittest .TestCase ):
20
+ # Empty animation profile for test case
21
+ animation_profile_test = {"objects" : {"default" : {},
22
+ "predefine" : {},
23
+ "custom" : {}},
24
+ "predicates_rules" : {},
25
+ "visual" : {},
26
+ "imageTable" : {"m_keys" : [],
27
+ "m_values" : []},
28
+ "cost_keyword" : None
29
+ }
19
30
20
31
# Initial test case
21
32
def test_upper (self ):
@@ -48,16 +59,16 @@ def test_planimation_process(self):
48
59
49
60
url_link = ''
50
61
51
- with open (os .path .abspath (os .path .dirname (__file__ )
52
- + '/test_files/' + 'domain_ap.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
62
+ with open (os .path .abspath (os .path .dirname (__file__ )
63
+ + '/test_files/' + 'domain_ap.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
53
64
animation_content = f .read ()
54
65
55
- with open (os .path .abspath (os .path .dirname (__file__ )
56
- + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
66
+ with open (os .path .abspath (os .path .dirname (__file__ )
67
+ + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
57
68
domain_content = f .read ().lower ()
58
-
59
- with open (os .path .abspath (os .path .dirname (__file__ )
60
- + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
69
+
70
+ with open (os .path .abspath (os .path .dirname (__file__ )
71
+ + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
61
72
problem_content = f .read ().lower ()
62
73
63
74
plan = Plan_generator .get_plan (domain_content , problem_content , url_link )
@@ -68,28 +79,30 @@ def test_planimation_process(self):
68
79
69
80
animation_profile = json .loads (Animation_parser .get_animation_profile (animation_content , object_list ))
70
81
71
- stages = get_stages (plan , problem_dic , problem_content , predicates_list )
82
+ stages = get_stages (plan , problem_dic , problem_content , predicates_list , animation_profile )
72
83
73
84
result = Solver .get_visualisation_dic (stages , animation_profile , plan ['result' ]['plan' ], problem_dic )
74
85
objects_dic = Initialise .initialise_objects (stages ["objects" ], animation_profile )
75
- final = Transfer .generate_visualisation_file (result , list (objects_dic .keys ()), animation_profile , plan ['result' ]['plan' ])
86
+ final = Transfer .generate_visualisation_file (result , list (objects_dic .keys ()), animation_profile ,
87
+ plan ['result' ]['plan' ])
76
88
77
- with open (os .path .abspath (os .path .dirname (__file__ )
78
- + '/test_files/' + "test.vfg" ), "w" ) as f :
89
+ with open (os .path .abspath (os .path .dirname (__file__ )
90
+ + '/test_files/' + "test.vfg" ), "w" ) as f :
79
91
json .dump (final , f )
80
92
81
- with open (os .path .abspath (os .path .dirname (__file__ )
82
- + '/test_files/' + "test.vfg" ), 'r' , encoding = 'utf-8-sig' ) as f :
93
+ with open (os .path .abspath (os .path .dirname (__file__ )
94
+ + '/test_files/' + "test.vfg" ), 'r' , encoding = 'utf-8-sig' ) as f :
83
95
output_content = f .read ()
84
96
85
- with open (os .path .abspath (os .path .dirname (__file__ )
86
- + '/test_files/' + "expect_output.vfg" ), 'r' , encoding = 'utf-8-sig' ) as f :
97
+ with open (os .path .abspath (os .path .dirname (__file__ )
98
+ + '/test_files/' + "expect_output.vfg" ), 'r' , encoding = 'utf-8-sig' ) as f :
87
99
expected_content = f .read ()
88
100
89
101
# Check that the generated vfg file is the same as the expected output
90
102
self .assertTrue (filecmp .cmp (os .path .abspath (os .path .dirname (__file__ ) + '/test_files/' + 'test.vfg' )
91
- , os .path .abspath (os .path .dirname (__file__ ) + '/test_files/' + 'expect_output.vfg' ), shallow = False )
92
- , msg = "The generated vfg file is different from the expected output." )
103
+ , os .path .abspath (os .path .dirname (__file__ ) + '/test_files/' + 'expect_output.vfg' ),
104
+ shallow = False )
105
+ , msg = "The generated vfg file is different from the expected output." )
93
106
94
107
def test_domain_parser (self ):
95
108
""" Test case for testing the domain parser functions
@@ -103,24 +116,24 @@ def test_domain_parser(self):
103
116
complex_predicates_list(JSON): The JSON structure generated by the Domain_parser.
104
117
"""
105
118
106
- with open (os .path .abspath (os .path .dirname (__file__ )
107
- + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
119
+ with open (os .path .abspath (os .path .dirname (__file__ )
120
+ + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
108
121
simple_domain_content = f .read ().lower ()
109
122
110
123
simple_predicates_list = Domain_parser .get_domain_json (simple_domain_content )
111
124
# simple domain predicates:
112
125
# (:predicates
113
126
# (connected ?x ?y - place)
114
- # (at-robot ?x - place)
115
- # (visited ?x - place))
127
+ # (at-robot ?x - place)
128
+ # (visited ?x - place))
116
129
simple_expected_predicates = {'connected' : 2 , 'at-robot' : 1 , 'visited' : 1 }
117
130
118
131
# Check that the generated simple predicates list is the same as the expected list
119
132
self .assertTrue (simple_predicates_list == simple_expected_predicates
120
- , msg = "The generated simple predicates list is different from the expected list" )
133
+ , msg = "The generated simple predicates list is different from the expected list" )
121
134
122
- with open (os .path .abspath (os .path .dirname (__file__ )
123
- + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
135
+ with open (os .path .abspath (os .path .dirname (__file__ )
136
+ + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
124
137
complex_domain_content = f .read ().lower ()
125
138
126
139
complex_predicates_list = Domain_parser .get_domain_json (complex_domain_content )
@@ -150,12 +163,12 @@ def test_problem_parser(self):
150
163
complex_problem_list(JSON): The JSON structure generated by the Problem_parser.
151
164
"""
152
165
153
- with open (os .path .abspath (os .path .dirname (__file__ )
154
- + '/test_files/' + '4_ops_problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
166
+ with open (os .path .abspath (os .path .dirname (__file__ )
167
+ + '/test_files/' + '4_ops_problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
155
168
simple_problem_content = f .read ().lower ()
156
169
157
- with open (os .path .abspath (os .path .dirname (__file__ )
158
- + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
170
+ with open (os .path .abspath (os .path .dirname (__file__ )
171
+ + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
159
172
simple_domain_content = f .read ().lower ()
160
173
161
174
simple_predicates_list = Domain_parser .get_domain_json (simple_domain_content )
@@ -172,30 +185,30 @@ def test_problem_parser(self):
172
185
{'goal' : [
173
186
{'name' : 'on' , 'objectNames' : ['a' , 'b' ]},
174
187
{'name' : 'on' , 'objectNames' : ['b' , 'c' ]}],
175
- 'goal-condition' : ['and' ]}]
188
+ 'goal-condition' : ['and' ]}]
176
189
177
190
# Check that the generated simple problem list is the same as the expected output
178
191
self .assertTrue (simple_problem_list == simple_expected_problem
179
- , msg = "The generated simple problem list is different from the expected output" )
192
+ , msg = "The generated simple problem list is different from the expected output" )
180
193
181
- with open (os .path .abspath (os .path .dirname (__file__ )
182
- + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
194
+ with open (os .path .abspath (os .path .dirname (__file__ )
195
+ + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
183
196
complex_problem_content = f .read ().lower ()
184
-
185
- with open (os .path .abspath (os .path .dirname (__file__ )
186
- + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
197
+
198
+ with open (os .path .abspath (os .path .dirname (__file__ )
199
+ + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
187
200
complex_domain_content = f .read ().lower ()
188
-
201
+
189
202
complex_predicates_list = Domain_parser .get_domain_json (complex_domain_content )
190
203
complex_problem_list = get_problem_dic (complex_problem_content , complex_predicates_list )
191
204
192
- with open (os .path .abspath (os .path .dirname (__file__ )
193
- + '/test_files/' + "complex_expected_problem.json" ), "r" ) as f :
205
+ with open (os .path .abspath (os .path .dirname (__file__ )
206
+ + '/test_files/' + "complex_expected_problem.json" ), "r" ) as f :
194
207
complex_expected_problem = json .load (f )
195
208
196
209
# Check that the generated complex problem list is the same as the expected output
197
210
self .assertTrue (complex_expected_problem == complex_problem_list
198
- , msg = "The generated complex problem list is different from the expected output" )
211
+ , msg = "The generated complex problem list is different from the expected output" )
199
212
200
213
def test_predicates_generator (self ):
201
214
""" Test case for testing the predicates generator function
@@ -213,12 +226,12 @@ def test_predicates_generator(self):
213
226
complex_stages(stage): The stage structure generated by the Predicates_parser.
214
227
"""
215
228
216
- with open (os .path .abspath (os .path .dirname (__file__ )
217
- + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
229
+ with open (os .path .abspath (os .path .dirname (__file__ )
230
+ + '/test_files/' + '4_ops_domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
218
231
simple_domain_content = f .read ().lower ()
219
232
220
- with open (os .path .abspath (os .path .dirname (__file__ )
221
- + '/test_files/' + '4_ops_problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
233
+ with open (os .path .abspath (os .path .dirname (__file__ )
234
+ + '/test_files/' + '4_ops_problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
222
235
simple_problem_content = f .read ().lower ()
223
236
224
237
with open (os .path .abspath (os .path .dirname (__file__ )
@@ -228,22 +241,23 @@ def test_predicates_generator(self):
228
241
simple_predicates_list = Domain_parser .get_domain_json (simple_domain_content )
229
242
simple_problem_dic = get_problem_dic (simple_problem_content , simple_predicates_list )
230
243
simple_object_list = get_object_list (simple_problem_content )
231
- simple_stages = get_stages (simple_plan , simple_problem_dic , simple_problem_content , simple_predicates_list )
232
-
233
- with open (os .path .abspath (os .path .dirname (__file__ )
234
- + '/test_files/' + "simple_expected_stages.json" ), "r" ) as f :
244
+ simple_stages = get_stages (simple_plan , simple_problem_dic , simple_problem_content , simple_predicates_list ,
245
+ self .animation_profile_test )
246
+
247
+ with open (os .path .abspath (os .path .dirname (__file__ )
248
+ + '/test_files/' + "simple_expected_stages.json" ), "r" ) as f :
235
249
simple_expected_stages = json .load (f )
236
-
250
+
237
251
# Check that the generated simple stages are the same as the expected output
238
252
self .assertTrue (simple_stages == simple_expected_stages
239
- , msg = "The generated simple stages are different from the expected output" )
253
+ , msg = "The generated simple stages are different from the expected output" )
240
254
241
- with open (os .path .abspath (os .path .dirname (__file__ )
242
- + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
255
+ with open (os .path .abspath (os .path .dirname (__file__ )
256
+ + '/test_files/' + 'domain.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
243
257
complex_domain_content = f .read ().lower ()
244
-
245
- with open (os .path .abspath (os .path .dirname (__file__ )
246
- + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
258
+
259
+ with open (os .path .abspath (os .path .dirname (__file__ )
260
+ + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
247
261
complex_problem_content = f .read ().lower ()
248
262
249
263
with open (os .path .abspath (os .path .dirname (__file__ )
@@ -253,19 +267,19 @@ def test_predicates_generator(self):
253
267
complex_predicates_list = Domain_parser .get_domain_json (complex_domain_content )
254
268
complex_problem_dic = get_problem_dic (complex_problem_content , complex_predicates_list )
255
269
complex_object_list = get_object_list (complex_problem_content )
256
- complex_stages = get_stages (complex_plan , complex_problem_dic , complex_problem_content , complex_predicates_list )
257
-
258
- with open (os .path .abspath (os .path .dirname (__file__ )
259
- + '/test_files/' + "complex_expected_stages.json" ), "r" ) as f :
270
+ complex_stages = get_stages (complex_plan , complex_problem_dic , complex_problem_content , complex_predicates_list ,
271
+ self . animation_profile_test )
272
+ with open (os .path .abspath (os .path .dirname (__file__ )
273
+ + '/test_files/' + "complex_expected_stages.json" ), "r" ) as f :
260
274
complex_expected_stages = json .load (f )
261
275
262
276
# Check that the generated complex stages are the same as the expected output
263
277
self .assertTrue (complex_stages == complex_expected_stages
264
- , msg = "The generated complex stages are different from the expected output" )
278
+ , msg = "The generated complex stages are different from the expected output" )
265
279
266
280
def test_solver (self ):
267
281
""" Test case for testing the solver functions
268
-
282
+
269
283
Expected Input:
270
284
domain_ap.pddl, problem.pddl: The animation and problem PDDL files.
271
285
expected_initialised_obj_dict.json: The expected output JSON file.
@@ -275,47 +289,56 @@ def test_solver(self):
275
289
expected_obj_name_prop(object): The object generated by the solver functions.
276
290
"""
277
291
278
- with open (os .path .abspath (os .path .dirname (__file__ )
279
- + '/test_files/' + 'domain_ap.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
292
+ with open (os .path .abspath (os .path .dirname (__file__ )
293
+ + '/test_files/' + 'domain_ap.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
280
294
animation_content = f .read ()
281
-
282
- with open (os .path .abspath (os .path .dirname (__file__ )
283
- + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
295
+
296
+ with open (os .path .abspath (os .path .dirname (__file__ )
297
+ + '/test_files/' + 'problem.pddl' ), 'r' , encoding = 'utf-8-sig' ) as f :
284
298
problem_content = f .read ().lower ()
285
299
286
300
object_list = get_object_list (problem_content )
287
301
animation_profile = json .loads (Animation_parser .get_animation_profile (animation_content , object_list ))
288
302
initialised_obj_dict = Initialise .initialise_objects (object_list , animation_profile )
289
-
290
- with open (os .path .abspath (os .path .dirname (__file__ )
291
- + '/test_files/' + "expected_initialised_obj_dict.json" ), "r" ) as f :
303
+
304
+ with open (os .path .abspath (os .path .dirname (__file__ )
305
+ + '/test_files/' + "expected_initialised_obj_dict.json" ), "r" ) as f :
292
306
expected_initialised_obj_dict = json .load (f )
293
-
307
+
294
308
# Check that the generated object dict is the same as the expected output
295
309
self .assertTrue (initialised_obj_dict == expected_initialised_obj_dict
296
- , msg = "The generated object dict is different from the expected output" )
310
+ , msg = "The generated object dict is different from the expected output" )
297
311
298
312
# testing check rule
299
313
true_predicate = {'name' : 'at-robot' , 'objectNames' : ['loc1_1' ]}
300
314
false_predicate = {'name' : 'at-robot' , 'objectNames' : ['loc1_2' ]}
301
315
objects_dic = {
302
- 'loc1_1' : {'prefabimage' : 'img-square' , 'showname' : False , 'x' : 100 , 'y' : 100 , 'color' : {'r' : 0.0 , 'g' : 0.0 , 'b' : 1.0 , 'a' : 1.0 }, 'width' : 80 , 'height' : 80 , 'depth' : 1 , 'name' : 'loc1_1' },
303
- 'loc1_2' : {'prefabimage' : 'img-square' , 'showname' : False , 'x' : 100 , 'y' : False , 'color' : {'r' : 0.0 , 'g' : 0.0 , 'b' : 1.0 , 'a' : 1.0 }, 'width' : 80 , 'height' : 80 , 'depth' : 1 , 'name' : 'loc1_2' },
304
- 'robot' : {'prefabimage' : 'img-robot' , 'showname' : False , 'x' : 100 , 'y' : 100 , 'color' : {'r' : 0.9804 , 'g' : 0.6353 , 'b' : 0.7098 , 'a' : 1.0 }, 'width' : 40 , 'height' : 40 , 'depth' : 2 , 'name' : 'robot' }}
316
+ 'loc1_1' : {'prefabimage' : 'img-square' , 'showname' : False , 'x' : 100 , 'y' : 100 ,
317
+ 'color' : {'r' : 0.0 , 'g' : 0.0 , 'b' : 1.0 , 'a' : 1.0 }, 'width' : 80 , 'height' : 80 , 'depth' : 1 ,
318
+ 'name' : 'loc1_1' },
319
+ 'loc1_2' : {'prefabimage' : 'img-square' , 'showname' : False , 'x' : 100 , 'y' : False ,
320
+ 'color' : {'r' : 0.0 , 'g' : 0.0 , 'b' : 1.0 , 'a' : 1.0 }, 'width' : 80 , 'height' : 80 , 'depth' : 1 ,
321
+ 'name' : 'loc1_2' },
322
+ 'robot' : {'prefabimage' : 'img-robot' , 'showname' : False , 'x' : 100 , 'y' : 100 ,
323
+ 'color' : {'r' : 0.9804 , 'g' : 0.6353 , 'b' : 0.7098 , 'a' : 1.0 }, 'width' : 40 , 'height' : 40 , 'depth' : 2 ,
324
+ 'name' : 'robot' }}
305
325
predicates_rules = {'at-robot' :
306
326
{'rules' : ['rule1' , 'rule2' , 'rule3' ],
307
- 'rule1' : {'left' : {'robot' : ['x' ]},'value' : {'equal' : {'?x' : 'x' }}},
327
+ 'rule1' : {'left' : {'robot' : ['x' ]}, 'value' : {'equal' : {'?x' : 'x' }}},
308
328
'rule2' : {'left' : {'robot' : ['y' ]}, 'value' : {'equal' : {'?x' : 'y' }}},
309
- 'rule3' : {'left' : {'?x' : ['color' ]}, 'value' : {'equal' : {'r' : 0.9804 , 'g' : 0.6353 , 'b' : 0.7098 , 'a' : 1.0 }}},
329
+ 'rule3' : {'left' : {'?x' : ['color' ]},
330
+ 'value' : {'equal' : {'r' : 0.9804 , 'g' : 0.6353 , 'b' : 0.7098 , 'a' : 1.0 }}},
310
331
'require' : {'?x' : ['x' , 'y' ]},
311
332
'objects' : ['?x' ],
312
333
'custom_obj' : ['robot' ]}}
313
334
314
335
# Check that the solver working with the expected predicate, objects dict and predicates rules
315
336
self .assertTrue (Solver .check_rule_complete (true_predicate , objects_dic , predicates_rules )
316
- , msg = "The input predicate list, objects dict and predicates rules didn't match the expected input params for the solver" )
337
+ ,
338
+ msg = "The input predicate list, objects dict and predicates rules didn't match the expected input params for the solver" )
317
339
self .assertFalse (Solver .check_rule_complete (false_predicate , objects_dic , predicates_rules )
318
- , msg = "The input params to the solver are fake data, but they match the expected input for the solver" )
340
+ ,
341
+ msg = "The input params to the solver are fake data, but they match the expected input for the solver" )
319
342
320
343
# test get obj name
321
344
property_dic = {'?x' : ['property1' , 'property2' ]}
@@ -325,7 +348,7 @@ def test_solver(self):
325
348
326
349
# Check that the generated object is the same as the expected output
327
350
self .assertTrue (expected_obj_name_prop == obj_name_prop
328
- , msg = "The generated object is different from the expected output" )
351
+ , msg = "The generated object is different from the expected output" )
329
352
330
353
331
354
if __name__ == '__main__' :
0 commit comments