test_pn_interface.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. import unittest
  2. from utils import run_file, get_constructor, get_model_constructor
  3. set_inheritance = [
  4. "Which link in the metamodel is the inheritance link?",
  5. "Set inheritance link!",
  6. ]
  7. join = ["Model name?",
  8. "New metamodel?",
  9. ]
  10. unify = ["Which language do you want to unify?",
  11. "Name of this language in the unification",
  12. "Second language to unify?",
  13. "Name of this language in the unification",
  14. ]
  15. ramify = ["Name of the RAMified metamodel to create",
  16. "Source language?"]
  17. transform = ["Which model do you want to transform?",
  18. "Which schedule do you want to execute?",
  19. ]
  20. transform_result_true = ["Transformation result: True"]
  21. transform_result_false = ["Transformation result: False"]
  22. split = ["Name of the model to split up?",
  23. "Name of new metamodel?",
  24. "Typename to split?",
  25. ]
  26. do_instantiate_simple = [
  27. "new", "PetriNets", "abc",
  28. "instantiate", "Transition", "t1",
  29. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  30. "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
  31. "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
  32. "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
  33. instantiate_node = ["Type to instantiate?",
  34. "Name of new element?",
  35. "Instantiation successful!"]
  36. instantiate_edge = ["Type to instantiate?",
  37. "Name of new element?",
  38. "Source name?",
  39. "Destination name?",
  40. "Instantiation successful!"]
  41. all_files = [ "pn_interface.alc",
  42. "primitives.alc",
  43. "object_operations.alc",
  44. "conformance_scd.alc",
  45. "library.alc",
  46. "ftg.alc",
  47. "transform.alc",
  48. "model_management.alc",
  49. "ramify.alc",
  50. "metamodels.alc",
  51. "random.alc",
  52. "constructors.alc",
  53. "modelling.alc",
  54. "compilation_manager.alc",
  55. ]
  56. greeting = ["Welcome to the Model Management Interface, running live on the Modelverse!",
  57. "Use 'help' command for a list of possible commands"]
  58. new = ["Metamodel to instantiate?",
  59. "Name of model?"]
  60. prompt = ["Please give your command."]
  61. loaded = ["Model loaded, ready for commands!",
  62. "Use 'help' command for a list of possible commands"] + prompt
  63. load = ["Model to load?"]
  64. instantiate = ["Type to instantiate?"]
  65. instantiate_name = ["Name of new element?"]
  66. instantiate_ok = ["Instantiation successful!"]
  67. instantiate_source= ["Source name?"]
  68. instantiate_destination = ["Destination name?"]
  69. def list_menu(defined):
  70. defined.append(("PetriNets", "SimpleClassDiagrams"))
  71. defined.append(("SimpleClassDiagrams", "SimpleClassDiagrams"))
  72. defined.append(("LTM_bottom", "LTM_bottom"))
  73. defined.append(("FTG", "SimpleClassDiagrams"))
  74. return ["Found models:",
  75. set([" %s : %s" % (m, mm) for m, mm in defined])]
  76. def list_model(defined):
  77. return ["List of all elements:",
  78. set([" %s : %s" % (m, mm) for m, mm in defined])]
  79. def read_node(name, t, defs, attrs):
  80. return ["Element to read?",
  81. "Name: %s" % name,
  82. "Type: %s" % t,
  83. "Defines attributes:"] + \
  84. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  85. ["Attributes:"] + \
  86. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  87. def read_edge(name, t, src, dst, defs, attrs):
  88. return ["Element to read?",
  89. "Name: %s" % name,
  90. "Type: %s" % t,
  91. "Source: %s" % src,
  92. "Destination: %s" % dst,
  93. "Defines attributes:"] + \
  94. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  95. ["Attributes:"] + \
  96. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  97. delete = ["Model to delete?", "Deleted!"]
  98. rename = ["Old name?", "New name?", "Rename complete!"]
  99. attr_add = ["Which model do you want to assign an attribute to?",
  100. "Which attribute do you wish to assign?",
  101. "Value of attribute?",
  102. "Added attribute!"]
  103. attr_del = ["Which model do you want to remove an attribute of?",
  104. "Which attribute do you want to delete?",
  105. "Attribute deleted!",
  106. ]
  107. help_root = ["Currently no model is loaded, so your operations are limited to:",
  108. " new -- Create a new model and save it for future use"
  109. " load -- Load a previously made model",
  110. " rename -- Rename a previously made model",
  111. " delete -- Delete a previously made model",
  112. " list -- Show a list of all stored models",
  113. " help -- Show a list of possible commands"]
  114. verify_fail_weight= ["Natural number not larger than or equal to zero"]
  115. verify_fail_tokens= ["Natural number not larger than or equal to zero"]
  116. verify_fail_structure = ["Source of model edge not typed by source of type: p2t"]
  117. init = greeting + prompt
  118. did_instantiate_simple = init + \
  119. new + \
  120. loaded +\
  121. instantiate_node + \
  122. prompt + \
  123. instantiate_node + \
  124. prompt + \
  125. attr_add + \
  126. prompt + \
  127. instantiate_node + \
  128. prompt + \
  129. attr_add + \
  130. prompt + \
  131. instantiate_edge + \
  132. prompt + \
  133. attr_add + \
  134. prompt + \
  135. instantiate_edge + \
  136. prompt + \
  137. attr_add + \
  138. prompt
  139. def list_types(t):
  140. return ["List of types:"] + \
  141. [set([" %s : %s" % (m, mm) for m, mm in t])]
  142. modify = ["Element to modify?",
  143. "Attribute to modify?",
  144. "New value?",
  145. "Modified!",]
  146. class TestPetrinetInterface(unittest.TestCase):
  147. def test_po_pn_interface_manage(self):
  148. self.pn_interface_manage("PO")
  149. def test_co_pn_interface_manage(self):
  150. self.pn_interface_manage("CO")
  151. def pn_interface_manage(self, mode):
  152. self.assertTrue(run_file(all_files,
  153. ["list",
  154. "new", "PetriNets", "abc", "exit",
  155. "list",
  156. "new", "PetriNets", "def", "exit",
  157. "list",
  158. "delete", "def",
  159. "list",
  160. "rename", "abc", "a",
  161. "list",
  162. "delete", "a",
  163. "list",
  164. ],
  165. init + \
  166. list_menu([]) + prompt + \
  167. new + loaded + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  168. new + loaded + prompt + list_menu([("abc", "PetriNets"), ("def", "PetriNets")]) + prompt + \
  169. delete + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  170. rename + prompt + list_menu([("a", "PetriNets")]) + prompt + \
  171. delete + prompt + list_menu([]) + prompt,
  172. mode))
  173. def test_po_pn_interface_new_reload(self):
  174. self.pn_interface_new_reload("PO")
  175. def test_co_pn_interface_new_reload(self):
  176. self.pn_interface_new_reload("CO")
  177. def pn_interface_new_reload(self, mode):
  178. self.assertTrue(run_file(all_files,
  179. ["new", "PetriNets", "abc", "exit", "load", "abc"],
  180. init + new + loaded + prompt + load + loaded,
  181. mode))
  182. def test_po_pn_interface_instantiate_place(self):
  183. self.pn_interface_instantiate_place("PO")
  184. def test_co_pn_interface_instantiate_place(self):
  185. self.pn_interface_instantiate_place("CO")
  186. def pn_interface_instantiate_place(self, mode):
  187. self.assertTrue(run_file(all_files,
  188. ["new", "PetriNets", "abc",
  189. "instantiate", "Place", "p1",
  190. "attr_add", "p1", "tokens", 5,
  191. "list",
  192. "read", "p1",
  193. "instantiate", "Transition", "t1",
  194. "list",
  195. "read", "t1"],
  196. init + new + loaded + \
  197. instantiate_node + prompt + \
  198. attr_add + prompt + \
  199. list_model([("p1", "Place"), ("p1.tokens", "Natural")]) + prompt + \
  200. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  201. instantiate_node + prompt + \
  202. list_model([("p1", "Place"), ("t1", "Transition"), ("p1.tokens", "Natural")]) + prompt + \
  203. read_node("t1", "Transition", [], []) + prompt,
  204. mode))
  205. def test_po_pn_interface_instantiate_arcs(self):
  206. self.pn_interface_instantiate_arcs("PO")
  207. def test_co_pn_interface_instantiate_arcs(self):
  208. self.pn_interface_instantiate_arcs("CO")
  209. def pn_interface_instantiate_arcs(self, mode):
  210. self.assertTrue(run_file(all_files,
  211. do_instantiate_simple + [
  212. "read", "p1",
  213. "read", "p2",
  214. "read", "t1",
  215. "read", "p2t",
  216. "read", "t2p",
  217. ],
  218. did_instantiate_simple + \
  219. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  220. read_node("p2", "Place", [], [("tokens", "Natural", 0)]) + prompt + \
  221. read_node("t1", "Transition", [], []) + prompt + \
  222. read_edge("p2t", "P2T", "p1", "t1", [], [("weight", "Natural", 2)]) + prompt + \
  223. read_edge("t2p", "T2P", "t1", "p2", [], [("weight", "Natural", 1)]) + prompt,
  224. mode))
  225. def test_po_pn_interface_verify_OK(self):
  226. self.pn_interface_verify_OK("PO")
  227. def test_co_pn_interface_verify_OK(self):
  228. self.pn_interface_verify_OK("CO")
  229. def pn_interface_verify_OK(self, mode):
  230. self.assertTrue(run_file(all_files,
  231. do_instantiate_simple + ["verify"],
  232. did_instantiate_simple + ["OK"], mode))
  233. def test_po_pn_interface_verify_fail_tokens(self):
  234. self.pn_interface_verify_fail_tokens("PO")
  235. def test_co_pn_interface_verify_fail_tokens(self):
  236. self.pn_interface_verify_fail_tokens("CO")
  237. def pn_interface_verify_fail_tokens(self, mode):
  238. self.assertTrue(run_file(all_files,
  239. do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
  240. did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
  241. def test_po_pn_interface_verify_fail_weight(self):
  242. self.pn_interface_verify_fail_weight("PO")
  243. def test_co_pn_interface_verify_fail_weight(self):
  244. self.pn_interface_verify_fail_weight("CO")
  245. def pn_interface_verify_fail_weight(self, mode):
  246. self.assertTrue(run_file(all_files,
  247. do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
  248. did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
  249. def test_po_pn_interface_verify_fail_structure(self):
  250. self.pn_interface_verify_fail_structure("PO")
  251. def test_co_pn_interface_verify_fail_structure(self):
  252. self.pn_interface_verify_fail_structure("CO")
  253. def pn_interface_verify_fail_structure(self, mode):
  254. self.assertTrue(run_file(all_files,
  255. ["new", "PetriNets", "abc",
  256. "instantiate", "Transition", "t1",
  257. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  258. "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
  259. init + new + loaded + \
  260. instantiate_node + prompt + \
  261. instantiate_node + prompt + attr_add + prompt + \
  262. instantiate_edge + prompt + attr_add + prompt + \
  263. verify_fail_structure,
  264. mode))
  265. def test_po_pn_interface_types(self):
  266. self.pn_interface_types("PO")
  267. def test_co_pn_interface_types(self):
  268. self.pn_interface_types("CO")
  269. def pn_interface_types(self, mode):
  270. self.assertTrue(run_file(all_files,
  271. ["new", "PetriNets", "abc", "types"],
  272. init + new + loaded + list_types([("Place", "Class"),
  273. ("Transition", "Class"),
  274. ("P2T", "Association"),
  275. ("T2P", "Association"),
  276. ("Natural", "Class"),
  277. ("Place_tokens", "Association"),
  278. ("Place_tokens.name", "String"),
  279. ("Place_tokens.target_lower_cardinality", "Natural"),
  280. ("Place_tokens.target_upper_cardinality", "Natural"),
  281. ("P2T_weight", "Association"),
  282. ("P2T_weight.name", "String"),
  283. ("P2T_weight.target_lower_cardinality", "Natural"),
  284. ("P2T_weight.target_upper_cardinality", "Natural"),
  285. ("T2P_weight", "Association"),
  286. ("T2P_weight.name", "String"),
  287. ("T2P_weight.target_lower_cardinality", "Natural"),
  288. ("T2P_weight.target_upper_cardinality", "Natural"),
  289. ]) + prompt,
  290. mode))
  291. def test_po_pn_interface_modify_place(self):
  292. self.pn_interface_modify_place("PO")
  293. def test_co_pn_interface_modify_place(self):
  294. self.pn_interface_modify_place("CO")
  295. def pn_interface_modify_place(self, mode):
  296. self.assertTrue(run_file(all_files,
  297. ["new", "PetriNets", "abc",
  298. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  299. "read", "p1",
  300. "modify", "p1", "tokens", 1, "read", "p1"],
  301. init + new + loaded + \
  302. instantiate_node + prompt + attr_add + prompt + \
  303. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  304. modify + prompt + \
  305. read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt,
  306. mode))
  307. def test_po_pn_interface_verify_fail_attr_lower_cardinality(self):
  308. self.pn_interface_verify_fail_attr_lower_cardinality("PO")
  309. def test_co_pn_interface_verify_fail_attr_lower_cardinality(self):
  310. self.pn_interface_verify_fail_attr_lower_cardinality("CO")
  311. def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
  312. self.assertTrue(run_file(all_files,
  313. do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
  314. did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge of type Place_tokens at p999"] + prompt,
  315. mode))
  316. def test_po_pn_interface_verify_fail_attr_upper_cardinality(self):
  317. self.pn_interface_verify_fail_attr_upper_cardinality("PO")
  318. def test_co_pn_interface_verify_fail_attr_upper_cardinality(self):
  319. self.pn_interface_verify_fail_attr_upper_cardinality("CO")
  320. def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
  321. self.assertTrue(run_file(all_files,
  322. do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
  323. did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge of type Place_tokens at p1"] + prompt,
  324. mode))
  325. def test_po_pn_interface_verify_natural(self):
  326. self.pn_interface_verify_natural("PO")
  327. def test_co_pn_interface_verify_natural(self):
  328. self.pn_interface_verify_natural("CO")
  329. def pn_interface_verify_natural(self, mode):
  330. self.assertTrue(run_file(all_files,
  331. ["new", "PetriNets", "abc",
  332. "instantiate", "Place", "p1",
  333. "attr_add", "p1", "tokens", -5,
  334. "attr_del", "p1", "tokens",
  335. "attr_add", "p1", "tokens", 4,
  336. "verify"],
  337. init + new + loaded + \
  338. instantiate_node + prompt + \
  339. attr_add + prompt + \
  340. attr_del + prompt + \
  341. attr_add + prompt + \
  342. ["OK"] + prompt,
  343. mode))
  344. def test_po_pn_interface_verify_PN_OK(self):
  345. self.pn_interface_verify_PN_OK("PO")
  346. def test_co_pn_interface_verify_PN_OK(self):
  347. self.pn_interface_verify_PN_OK("CO")
  348. def pn_interface_verify_PN_OK(self, mode):
  349. self.assertTrue(run_file(all_files,
  350. ["load", "PetriNets", "verify"],
  351. init + load + loaded + ["OK"], mode))
  352. def test_po_rpgame(self):
  353. self.rpgame("PO")
  354. def test_co_rpgame(self):
  355. self.rpgame("CO")
  356. def rpgame(self, mode):
  357. constraint_code = \
  358. """
  359. include "primitives.alh"
  360. include "object_operations.alh"
  361. Element function constraint(model : Element, name : String):
  362. Element associations
  363. Element back_associations
  364. Element association
  365. String destination
  366. associations = allOutgoingAssociationInstances(model, name, "tile_left")
  367. while (0 < list_len(associations)):
  368. association = set_pop(associations)
  369. destination = readAssociationDestination(model, association)
  370. back_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
  371. if (list_len(back_associations) < 1):
  372. return "Left link does not have a right link back"!
  373. else:
  374. association = set_pop(back_associations)
  375. destination = readAssociationDestination(model, association)
  376. if (destination != name):
  377. return "Right link does not have a left link back to the same tile"!
  378. associations = allOutgoingAssociationInstances(model, name, "tile_right")
  379. while (0 < list_len(associations)):
  380. association = set_pop(associations)
  381. destination = readAssociationDestination(model, association)
  382. back_associations = allOutgoingAssociationInstances(model, destination, "tile_left")
  383. if (list_len(back_associations) < 1):
  384. return "Right link does not have a left link back"!
  385. else:
  386. association = set_pop(back_associations)
  387. destination = readAssociationDestination(model, association)
  388. if (destination != name):
  389. return "Right link does not have a left link back to the same tile"!
  390. associations = allOutgoingAssociationInstances(model, name, "tile_top")
  391. while (0 < list_len(associations)):
  392. association = set_pop(associations)
  393. destination = readAssociationDestination(model, association)
  394. back_associations = allOutgoingAssociationInstances(model, destination, "tile_bottom")
  395. if (list_len(back_associations) < 1):
  396. return "Top link does not have a bottom link back"!
  397. else:
  398. association = set_pop(back_associations)
  399. destination = readAssociationDestination(model, association)
  400. if (destination != name):
  401. return "Top link does not have a bottom link back to the same tile"!
  402. associations = allOutgoingAssociationInstances(model, name, "tile_bottom")
  403. while (0 < list_len(associations)):
  404. association = set_pop(associations)
  405. destination = readAssociationDestination(model, association)
  406. back_associations = allOutgoingAssociationInstances(model, destination, "tile_top")
  407. if (list_len(back_associations) < 1):
  408. return "Bottom link does not have a top link back"!
  409. else:
  410. association = set_pop(back_associations)
  411. destination = readAssociationDestination(model, association)
  412. if (destination != name):
  413. return "Bottom link does not have a top link back to the same tile"!
  414. return "OK"!
  415. """
  416. constructors = get_constructor(constraint_code)
  417. self.assertTrue(run_file(all_files,
  418. ["new", "SimpleClassDiagrams", "RPGame",
  419. "set_inheritance", "Inheritance",
  420. "instantiate", "Class", "Scene",
  421. "instantiate", "Class", "Tile",
  422. "instantiate", "Class", "Item",
  423. "instantiate", "Class", "Goal",
  424. "instantiate", "Class", "Character",
  425. "instantiate", "Class", "Hero",
  426. "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
  427. "instantiate", "Association", "tile_left", "Tile", "Tile",
  428. "instantiate", "Association", "tile_right", "Tile", "Tile",
  429. "instantiate", "Association", "tile_top", "Tile", "Tile",
  430. "instantiate", "Association", "tile_bottom", "Tile", "Tile",
  431. "instantiate", "Association", "character_on", "Character", "Tile",
  432. "instantiate", "Association", "item_on", "Item", "Tile",
  433. "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
  434. "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
  435. "attr_add", "Scene", "lower_cardinality", 1,
  436. "attr_add", "Scene", "upper_cardinality", 1,
  437. "attr_add", "Goal", "lower_cardinality", 1,
  438. "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
  439. "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
  440. "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
  441. "attr_add", "item_on", "target_lower_cardinality", 1,
  442. "attr_add", "item_on", "target_upper_cardinality", 1,
  443. "attr_add", "item_on", "source_upper_cardinality", 1,
  444. "attr_add", "character_on", "target_lower_cardinality", 1,
  445. "attr_add", "character_on", "target_upper_cardinality", 1,
  446. "attr_add", "character_on", "source_upper_cardinality", 1,
  447. "attr_add", "tile_left", "source_upper_cardinality", 1,
  448. "attr_add", "tile_left", "target_upper_cardinality", 1,
  449. "attr_add", "tile_right", "source_upper_cardinality", 1,
  450. "attr_add", "tile_right", "target_upper_cardinality", 1,
  451. "attr_add", "tile_top", "source_upper_cardinality", 1,
  452. "attr_add", "tile_top", "target_upper_cardinality", 1,
  453. "attr_add", "tile_bottom", "source_upper_cardinality", 1,
  454. "attr_add", "tile_bottom", "target_upper_cardinality", 1,
  455. "attr_add_code", "Tile", "constraint",
  456. ] + constructors + ["verify"] + ["exit"] + [
  457. "new", "RPGame", "my_game",
  458. "instantiate", "Scene", "scene",
  459. "instantiate", "Hero", "Link",
  460. "instantiate", "Goal", "goal",
  461. "instantiate", "Tile", "tile_00",
  462. "instantiate", "Tile", "tile_01",
  463. "instantiate", "Tile", "tile_10",
  464. "instantiate", "Tile", "tile_11",
  465. "instantiate", "scene_has_tiles", "", "scene", "tile_00",
  466. "instantiate", "scene_has_tiles", "", "scene", "tile_01",
  467. "instantiate", "scene_has_tiles", "", "scene", "tile_10",
  468. "instantiate", "scene_has_tiles", "", "scene", "tile_11",
  469. "instantiate", "character_on", "", "Link", "tile_00",
  470. "instantiate", "item_on", "", "goal", "tile_11",
  471. "instantiate", "tile_left", "", "tile_01", "tile_00",
  472. "instantiate", "tile_left", "", "tile_11", "tile_10",
  473. "instantiate", "tile_right", "", "tile_00", "tile_01",
  474. "instantiate", "tile_right", "", "tile_10", "tile_11",
  475. "instantiate", "tile_top", "", "tile_10", "tile_00",
  476. "instantiate", "tile_top", "", "tile_11", "tile_01",
  477. "instantiate", "tile_bottom", "", "tile_00", "tile_10",
  478. "instantiate", "tile_bottom", "", "tile_01", "tile_11",
  479. "verify",
  480. ],
  481. init + new + loaded + \
  482. set_inheritance + prompt + \
  483. (instantiate_node + prompt) * 6 + \
  484. (instantiate_edge + prompt) * 9 + \
  485. (attr_add + prompt) * 20 + \
  486. ["Which model do you want to assign a coded attribute to?",
  487. "Which attribute do you wish to assign?",
  488. "Constructors for code?",
  489. "Added code!"] + \
  490. prompt + \
  491. ["OK"] + \
  492. prompt + prompt + new + loaded + \
  493. (instantiate_node + prompt) * 7 + \
  494. (instantiate_edge + prompt) * 14 + \
  495. ["OK"],
  496. mode))
  497. def test_po_pn_interface_model_transform_pn(self):
  498. PN_runtime = open("integration/code/pn_runtime.mvc", "r").read()
  499. PN_model = open("integration/code/pn_runtime_model.mvc", "r").read()
  500. schedule_model = open("integration/code/pn_simulate.mvc", "r").read()
  501. self.assertTrue(run_file(all_files,
  502. get_model_constructor(PN_runtime) + [
  503. ] + get_model_constructor(PN_model) + [
  504. "load", "pn",
  505. "read", "t1",
  506. "read", "p1",
  507. "read", "p2",
  508. "read", "p3",
  509. "exit",
  510. "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
  511. ] + get_model_constructor(schedule_model) + [
  512. "transform", "pn", "pn_simulate",
  513. "transform", "pn", "pn_simulate",
  514. "load", "pn",
  515. "verify",
  516. "read", "t1",
  517. "read", "p1",
  518. "read", "p2",
  519. "read", "p3",
  520. "exit",
  521. ],
  522. greeting + prompt * 3 +
  523. load + loaded +
  524. read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  525. read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  526. read_node("p2", "Place", [], [("tokens", "Natural", 2)]) + prompt +
  527. read_node("p3", "Place", [], [("tokens", "Natural", 3)]) + prompt +
  528. prompt +
  529. ramify + prompt +
  530. prompt +
  531. transform + transform_result_true + prompt +
  532. transform + transform_result_false + prompt +
  533. load + loaded +
  534. ["OK"] + prompt +
  535. read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  536. read_node("p1", "Place", [], [("tokens", "Natural", 0)]) + prompt +
  537. read_node("p2", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  538. read_node("p3", "Place", [], [("tokens", "Natural", 5)]) + prompt,
  539. "PO"))
  540. def test_po_pn_interface_transform_pn_to_runtime(self):
  541. PN_runtime = open("integration/code/pn_runtime.mvc", "r").read()
  542. PN_design = open("integration/code/pn_design.mvc", "r").read()
  543. PN_model = open("integration/code/pn_design_model.mvc", "r").read()
  544. schedule_model_design_to_runtime = open("integration/code/pn_design_to_runtime.mvc", "r").read()
  545. schedule_model_print = open("integration/code/pn_print.mvc", "r").read()
  546. schedule_model_simulate = open("integration/code/pn_simulate.mvc", "r").read()
  547. self.assertTrue(run_file(all_files,
  548. get_model_constructor(PN_runtime) + \
  549. get_model_constructor(PN_design) + \
  550. get_model_constructor(PN_model) + [
  551. "unify", "PetriNets_Design_to_Runtime", "PetriNets_Design", "SOURCE_", "PetriNets_Runtime", "TARGET_",
  552. "join", "pn", "PetriNets_Design_to_Runtime", "SOURCE_",
  553. "load", "PetriNets_Design_to_Runtime",
  554. "instantiate", "Association", "PlaceLink", "SOURCE_Place", "TARGET_Place",
  555. "instantiate", "Association", "TransitionLink", "SOURCE_Transition", "TARGET_Transition",
  556. "exit",
  557. "ramify", "RAM_PetriNets_Design_Runtime", "PetriNets_Design_to_Runtime",
  558. "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
  559. ] + get_model_constructor(schedule_model_design_to_runtime) + [
  560. ] + get_model_constructor(schedule_model_print) + [
  561. ] + get_model_constructor(schedule_model_simulate) + [
  562. "transform", "pn", "pn_annotate",
  563. "split", "pn", "PetriNets_Runtime", "TARGET_",
  564. "transform", "pn", "pn_print",
  565. "transform", "pn", "pn_simulate",
  566. "transform", "pn", "pn_print",
  567. ],
  568. greeting + prompt * 4 +
  569. unify + prompt +
  570. join + prompt +
  571. load + loaded +
  572. instantiate_edge + prompt +
  573. instantiate_edge + prompt +
  574. prompt +
  575. ramify + prompt +
  576. ramify + prompt +
  577. prompt +
  578. prompt +
  579. prompt +
  580. transform + transform_result_true + prompt +
  581. split + prompt +
  582. transform + [set(['"p1" --> 1', '"p2" --> 2', '"p3" --> 3'])] + transform_result_true + prompt +
  583. transform + transform_result_true + prompt +
  584. transform + [set(['"p1" --> 0', '"p2" --> 1', '"p3" --> 5'])] + transform_result_true + prompt
  585. ,
  586. "PO"))