|
@@ -1,14 +1,18 @@
|
|
|
import unittest
|
|
|
+import sys
|
|
|
+sys.path.append("interface/HUTN")
|
|
|
+
|
|
|
+from hutn_compiler.compiler import main as do_compile
|
|
|
|
|
|
from utils import run_file
|
|
|
|
|
|
do_instantiate_simple = [
|
|
|
- "new", "PetriNets", "abc",
|
|
|
- "instantiate", "Transition", "t1",
|
|
|
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
|
|
|
- "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
|
|
|
- "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
|
|
|
- "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
|
|
|
+ '"new"', '"PetriNets"', '"abc"',
|
|
|
+ '"instantiate"', '"Transition"', '"t1"',
|
|
|
+ '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
|
|
|
+ '"instantiate"', '"Place"', '"p2"', '"attr_add"', '"p2"', '"tokens"', '0',
|
|
|
+ '"instantiate"', '"P2T"', '"p2t"', '"p1"', '"t1"', '"attr_add"', '"p2t"', '"weight"', '2',
|
|
|
+ '"instantiate"', '"T2P"', '"t2p"', '"t1"', '"p2"', '"attr_add"', '"t2p"', '"weight"', '1']
|
|
|
|
|
|
instantiate_node = ["Type to instantiate?",
|
|
|
"Name of new element?",
|
|
@@ -148,17 +152,17 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_manage(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["list",
|
|
|
- "new", "PetriNets", "abc", "exit",
|
|
|
- "list",
|
|
|
- "new", "PetriNets", "def", "exit",
|
|
|
- "list",
|
|
|
- "delete", "def",
|
|
|
- "list",
|
|
|
- "rename", "abc", "a",
|
|
|
- "list",
|
|
|
- "delete", "a",
|
|
|
- "list",
|
|
|
+ ['"list"',
|
|
|
+ '"new"', '"PetriNets"', '"abc"', '"exit"',
|
|
|
+ '"list"',
|
|
|
+ '"new"', '"PetriNets"', '"def"', '"exit"',
|
|
|
+ '"list"',
|
|
|
+ '"delete"', '"def"',
|
|
|
+ '"list"',
|
|
|
+ '"rename"', '"abc"', '"a"',
|
|
|
+ '"list"',
|
|
|
+ '"delete"', '"a"',
|
|
|
+ '"list"',
|
|
|
],
|
|
|
init + \
|
|
|
list_menu([]) + prompt + \
|
|
@@ -177,7 +181,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_new_reload(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc", "exit", "load", "abc"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"', '"exit"', '"load"', '"abc"'],
|
|
|
init + new + loaded + prompt + load + loaded,
|
|
|
mode))
|
|
|
|
|
@@ -189,14 +193,14 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_instantiate_place(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc",
|
|
|
- "instantiate", "Place", "p1",
|
|
|
- "attr_add", "p1", "tokens", 5,
|
|
|
- "list",
|
|
|
- "read", "p1",
|
|
|
- "instantiate", "Transition", "t1",
|
|
|
- "list",
|
|
|
- "read", "t1"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"',
|
|
|
+ '"instantiate"', '"Place"', '"p1"',
|
|
|
+ '"attr_add"', '"p1"', '"tokens"', '5',
|
|
|
+ '"list"',
|
|
|
+ '"read"', '"p1"',
|
|
|
+ '"instantiate"', '"Transition"', '"t1"',
|
|
|
+ '"list"',
|
|
|
+ '"read"', '"t1"'],
|
|
|
init + new + loaded + \
|
|
|
instantiate_node + prompt + \
|
|
|
attr_add + prompt + \
|
|
@@ -216,11 +220,11 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
def pn_interface_instantiate_arcs(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
do_instantiate_simple + [
|
|
|
- "read", "p1",
|
|
|
- "read", "p2",
|
|
|
- "read", "t1",
|
|
|
- "read", "p2t",
|
|
|
- "read", "t2p",
|
|
|
+ '"read"', '"p1"',
|
|
|
+ '"read"', '"p2"',
|
|
|
+ '"read"', '"t1"',
|
|
|
+ '"read"', '"p2t"',
|
|
|
+ '"read"', '"t2p"',
|
|
|
],
|
|
|
did_instantiate_simple + \
|
|
|
read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
|
|
@@ -238,7 +242,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_enabled(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["enabled"],
|
|
|
+ do_instantiate_simple + ['"enabled"'],
|
|
|
did_instantiate_simple + enabled(["t1"]) + prompt,
|
|
|
mode))
|
|
|
|
|
@@ -250,7 +254,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_fire(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["fire", "t1"],
|
|
|
+ do_instantiate_simple + ['"fire"', '"t1"'],
|
|
|
did_instantiate_simple + fire([("p1", 3), ("p2", 1)]) + prompt,
|
|
|
mode))
|
|
|
|
|
@@ -262,7 +266,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_OK(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["verify"],
|
|
|
+ do_instantiate_simple + ['"verify"'],
|
|
|
did_instantiate_simple + ["OK"], mode))
|
|
|
|
|
|
def test_po_pn_interface_verify_fail_tokens(self):
|
|
@@ -273,7 +277,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_fail_tokens(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
|
|
|
+ do_instantiate_simple + ['"modify"', '"p1"', '"tokens"', '-5', '"verify"'],
|
|
|
did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
|
|
|
|
|
|
def test_po_pn_interface_verify_fail_weight(self):
|
|
@@ -284,7 +288,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_fail_weight(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
|
|
|
+ do_instantiate_simple + ['"modify"', '"p2t"', '"weight"', '-2', '"verify"'],
|
|
|
did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
|
|
|
|
|
|
def test_po_pn_interface_verify_fail_structure(self):
|
|
@@ -295,10 +299,10 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_fail_structure(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc",
|
|
|
- "instantiate", "Transition", "t1",
|
|
|
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
|
|
|
- "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"',
|
|
|
+ '"instantiate"', '"Transition"', '"t1"',
|
|
|
+ '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
|
|
|
+ '"instantiate"', '"P2T"', '"p2t"', '"t1"', '"p1"', '"attr_add"', '"p2t"', '"weight"', '2', '"verify"'],
|
|
|
init + new + loaded + \
|
|
|
instantiate_node + prompt + \
|
|
|
instantiate_node + prompt + attr_add + prompt + \
|
|
@@ -314,7 +318,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_types(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc", "types"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"', '"types"'],
|
|
|
init + new + loaded + list_types([("Place", "Class"), ("Transition", "Class"), ("P2T", "Association"), ("T2P", "Association"), ("Natural", "Class")]),
|
|
|
mode))
|
|
|
|
|
@@ -326,10 +330,10 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_modify_place(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc",
|
|
|
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
|
|
|
- "read", "p1",
|
|
|
- "modify", "p1", "tokens", 1, "read", "p1"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"',
|
|
|
+ '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
|
|
|
+ '"read"', '"p1"',
|
|
|
+ '"modify"', '"p1"', '"tokens"', '1', '"read"', '"p1"'],
|
|
|
init + new + loaded + \
|
|
|
instantiate_node + prompt + attr_add + prompt + \
|
|
|
read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
|
|
@@ -345,7 +349,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
|
|
|
+ do_instantiate_simple + ['"instantiate"', '"Place"', '"p999"', '"verify"'],
|
|
|
did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge at p999"] + prompt,
|
|
|
mode))
|
|
|
|
|
@@ -357,7 +361,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
|
|
|
+ do_instantiate_simple + ['"attr_add"', '"p1"', '"tokens"', '5', '"verify"'],
|
|
|
did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge at p1"] + prompt,
|
|
|
mode))
|
|
|
|
|
@@ -369,12 +373,12 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_natural(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "PetriNets", "abc",
|
|
|
- "instantiate", "Place", "p1",
|
|
|
- "attr_add", "p1", "tokens", -5,
|
|
|
- "attr_del", "p1", "tokens",
|
|
|
- "attr_add", "p1", "tokens", 4,
|
|
|
- "verify"],
|
|
|
+ ['"new"', '"PetriNets"', '"abc"',
|
|
|
+ '"instantiate"', '"Place"', '"p1"',
|
|
|
+ '"attr_add"', '"p1"', '"tokens"', '-5',
|
|
|
+ '"attr_del"', '"p1"', '"tokens"',
|
|
|
+ '"attr_add"', '"p1"', '"tokens"', '4',
|
|
|
+ '"verify"'],
|
|
|
init + new + loaded + \
|
|
|
instantiate_node + prompt + \
|
|
|
attr_add + prompt + \
|
|
@@ -391,7 +395,7 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
|
|
|
def pn_interface_verify_PN_OK(self, mode):
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["load", "PetriNets", "verify"],
|
|
|
+ ['"load"', '"PetriNets"', '"verify"'],
|
|
|
init + load + loaded + ["OK"], mode))
|
|
|
|
|
|
def test_po_rpgame(self):
|
|
@@ -401,48 +405,73 @@ class TestPetrinetInterface(unittest.TestCase):
|
|
|
self.rpgame("CO")
|
|
|
|
|
|
def rpgame(self, mode):
|
|
|
+
|
|
|
+ constraint_code = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ include "object_operations.alh"
|
|
|
+
|
|
|
+ Element function constraint(model : Element, name : String):
|
|
|
+ Element associations
|
|
|
+ Element back_associations
|
|
|
+ Element association
|
|
|
+
|
|
|
+ associations = allOutgoingAssociationInstances(model, name, "tile_left")
|
|
|
+ while (0 < list_len(associations)):
|
|
|
+ association = set_pop(associations)
|
|
|
+ destination = reverseKeyLookup(model["model"], read_edge_dst(association))
|
|
|
+ back_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
|
|
|
+ if (list_len(back_associations) < 1):
|
|
|
+ return "Left link does not have a right link back"
|
|
|
+ else:
|
|
|
+ association = list_get(back_associations, 0)
|
|
|
+ destination = reverseKeyLookup(model["model"], read_edge_dst(association))
|
|
|
+ if (destination != name):
|
|
|
+ return "Left link does not have a right link back to the same node"
|
|
|
+ """
|
|
|
+
|
|
|
self.assertTrue(run_file(all_files,
|
|
|
- ["new", "SimpleClassDiagrams", "RPGame",
|
|
|
- "instantiate", "Class", "Scene",
|
|
|
- "instantiate", "Class", "Tile",
|
|
|
- "instantiate", "Class", "Item",
|
|
|
- "instantiate", "Class", "Goal",
|
|
|
- "instantiate", "Class", "Character",
|
|
|
- "instantiate", "Class", "Hero",
|
|
|
- "instantiate", "Class", "String",
|
|
|
- "instantiate", "Association", "scene_name", "Scene", "String",
|
|
|
- "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
|
|
|
- "instantiate", "Association", "tile_left", "Tile", "Tile",
|
|
|
- "instantiate", "Association", "tile_right", "Tile", "Tile",
|
|
|
- "instantiate", "Association", "tile_top", "Tile", "Tile",
|
|
|
- "instantiate", "Association", "tile_bottom", "Tile", "Tile",
|
|
|
- "instantiate", "Association", "character_on", "Character", "Tile",
|
|
|
- "instantiate", "Association", "item_on", "Item", "Tile",
|
|
|
- "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
|
|
|
- "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
|
|
|
- "attr_add", "Scene", "lower_cardinality", 1,
|
|
|
- "attr_add", "Scene", "upper_cardinality", 1,
|
|
|
- "attr_add", "Goal", "lower_cardinality", 1,
|
|
|
- "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
|
|
|
- "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
|
|
|
- "attr_add", "scene_name", "target_lower_cardinality", 1,
|
|
|
- "attr_add", "scene_name", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "item_on", "target_lower_cardinality", 1,
|
|
|
- "attr_add", "item_on", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "item_on", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "character_on", "target_lower_cardinality", 1,
|
|
|
- "attr_add", "character_on", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "character_on", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_left", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_left", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_right", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_right", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_top", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_top", "target_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_bottom", "source_upper_cardinality", 1,
|
|
|
- "attr_add", "tile_bottom", "target_upper_cardinality", 1,
|
|
|
- "verify",
|
|
|
+ ['"new"', '"SimpleClassDiagrams"', '"RPGame"',
|
|
|
+ '"instantiate"', '"Class"', '"Scene"',
|
|
|
+ '"instantiate"', '"Class"', '"Tile"',
|
|
|
+ '"instantiate"', '"Class"', '"Item"',
|
|
|
+ '"instantiate"', '"Class"', '"Goal"',
|
|
|
+ '"instantiate"', '"Class"', '"Character"',
|
|
|
+ '"instantiate"', '"Class"', '"Hero"',
|
|
|
+ '"instantiate"', '"Class"', '"String"',
|
|
|
+ '"instantiate"', '"Association"', '"scene_name"', '"Scene"', '"String"',
|
|
|
+ '"instantiate"', '"Association"', '"scene_has_tiles"', '"Scene"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"tile_left"', '"Tile"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"tile_right"', '"Tile"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"tile_top"', '"Tile"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"tile_bottom"', '"Tile"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"character_on"', '"Character"', '"Tile"',
|
|
|
+ '"instantiate"', '"Association"', '"item_on"', '"Item"', '"Tile"',
|
|
|
+ '"instantiate"', '"Inheritance"', '"hero_is_character"', '"Hero"', '"Character"',
|
|
|
+ '"instantiate"', '"Inheritance"', '"goal_is_item"', '"Goal"', '"Item"',
|
|
|
+ '"attr_add"', '"Scene"', '"lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"Scene"', '"upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"Goal"', '"lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"scene_has_tiles"', '"source_lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"scene_has_tiles"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"scene_has_tiles"', '"target_lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"scene_name"', '"target_lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"scene_name"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"item_on"', '"target_lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"item_on"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"item_on"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"character_on"', '"target_lower_cardinality"', '1',
|
|
|
+ '"attr_add"', '"character_on"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"character_on"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_left"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_left"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_right"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_right"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_top"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_top"', '"target_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_bottom"', '"source_upper_cardinality"', '1',
|
|
|
+ '"attr_add"', '"tile_bottom"', '"target_upper_cardinality"', '1',
|
|
|
+ '"verify"',
|
|
|
],
|
|
|
init + new + loaded + (instantiate_node + prompt) * 7 + (instantiate_edge + prompt) * 10 + (attr_add + prompt) * 22 + ["OK"] + prompt,
|
|
|
mode))
|