test_pn_interface.py 29 KB

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