|
@@ -2,7 +2,7 @@ import unittest
|
|
|
import sys
|
|
|
import os
|
|
|
|
|
|
-from utils import execute, kill, run_file, run_barebone
|
|
|
+from utils import execute, kill, run_file, run_barebone, get_constructor
|
|
|
|
|
|
bottom = [
|
|
|
"model",
|
|
@@ -65,9 +65,18 @@ bottom = [
|
|
|
"exit",
|
|
|
]
|
|
|
|
|
|
+bottom_link_al = [
|
|
|
+ "model",
|
|
|
+ "instantiate_node", "1", "ComplexAttribute", "ActionLanguage",
|
|
|
+ "instantiate_attribute", "1", "ActionLanguage", "type", "/models/ActionLanguage",
|
|
|
+
|
|
|
+ "model_define_attribute", "1", "Element", "constraint", True, "ActionLanguage",
|
|
|
+ "exit",
|
|
|
+ ]
|
|
|
+
|
|
|
action_language = [
|
|
|
"model",
|
|
|
- "instantiate_model", "2", "1",
|
|
|
+ "instantiate_model", "1", "2",
|
|
|
"instantiate_node", "2", "Class", "Element",
|
|
|
"instantiate_node", "2", "Class", "Action",
|
|
|
"instantiate_node", "2", "Class", "Statement",
|
|
@@ -88,10 +97,9 @@ action_language = [
|
|
|
"instantiate_node", "2", "Class", "input",
|
|
|
"instantiate_node", "2", "Class", "resolve",
|
|
|
"instantiate_node", "2", "Class", "call",
|
|
|
-
|
|
|
- "instantiate_node", "2", "SimpleAttribute", "Natural",
|
|
|
- "instantiate_node", "2", "SimpleAttribute", "String",
|
|
|
- "instantiate_node", "2", "SimpleAttribute", "Boolean",
|
|
|
+ "instantiate_node", "2", "Class", "Natural",
|
|
|
+ "instantiate_node", "2", "Class", "String",
|
|
|
+ "instantiate_node", "2", "Class", "Boolean",
|
|
|
|
|
|
"instantiate_link", "2", "Inheritance", "", "Action", "Element",
|
|
|
"instantiate_link", "2", "Inheritance", "", "funcdef", "Action",
|
|
@@ -116,7 +124,7 @@ action_language = [
|
|
|
"instantiate_link", "2", "Inheritance", "", "String", "Element",
|
|
|
"instantiate_link", "2", "Inheritance", "", "Boolean", "Element",
|
|
|
|
|
|
- "instantiate_link", "2", "Association", "dict_link", "Any", "Any",
|
|
|
+ "instantiate_link", "2", "Association", "dict_link", "Action", "Element",
|
|
|
"model_define_attribute", "2", "dict_link", "name", False, "String",
|
|
|
"instantiate_attribute", "2", "dict_link", "target_upper_cardinality", 1,
|
|
|
|
|
@@ -175,43 +183,18 @@ action_language = [
|
|
|
"instantiate_attribute", "2", "call_params", "target_lower_cardinality", 1,
|
|
|
"instantiate_attribute", "2", "call_last_param", "target_lower_cardinality", 1,
|
|
|
|
|
|
- "model_define_attribute", "2", "Element", "constraint", True, "funcdef",
|
|
|
- "model_define_attribute", "2", "AttributeValue", "to_string", True, "funcdef",
|
|
|
+ "export_node", "2", "models/ActionLanguage",
|
|
|
"exit",
|
|
|
]
|
|
|
|
|
|
-def add_constraints(model):
|
|
|
+def add_constraint(model, element, code):
|
|
|
+ location = "constraints/%s_%s" % (model, element)
|
|
|
+ print(locals())
|
|
|
return [
|
|
|
"model",
|
|
|
- "instantiate_attribute_code", str(model), "Natural", "constraint",
|
|
|
- "funcdef",
|
|
|
- "constraint",
|
|
|
- 2, str(model*100), str(model*100+1),
|
|
|
- "if",
|
|
|
- "call",
|
|
|
- "access", "resolve", "is_physical_int",
|
|
|
- 1,
|
|
|
- "call",
|
|
|
- "access", "resolve", "dict_read",
|
|
|
- 2,
|
|
|
- "call",
|
|
|
- "access", "resolve", "dict_read",
|
|
|
- 2,
|
|
|
- "access", "resolve", str(model*100),
|
|
|
- "const", "model",
|
|
|
- False,
|
|
|
- "access", "resolve", str(model*100+1),
|
|
|
- False,
|
|
|
- False,
|
|
|
- "return",
|
|
|
- True,
|
|
|
- "const", "OK",
|
|
|
- True,
|
|
|
- "return",
|
|
|
- True,
|
|
|
- "const", "Natural instance is not an integer.",
|
|
|
- False,
|
|
|
- False,
|
|
|
+ "add_code_model", "AL", location,
|
|
|
+ ] + get_constructor(code) + [
|
|
|
+ "instantiate_attribute", model, element, "constraint", location,
|
|
|
"exit",
|
|
|
]
|
|
|
|
|
@@ -313,21 +296,99 @@ def conformance_check(node):
|
|
|
True,
|
|
|
]
|
|
|
|
|
|
+code_natural = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ String function constraint(model : Element, name : String):
|
|
|
+ Element self
|
|
|
+ self = model["model"][name]
|
|
|
+ if (is_physical_int(self)):
|
|
|
+ if (integer_gte(self, 0)):
|
|
|
+ return "OK"!
|
|
|
+ else:
|
|
|
+ return "Natural number not larger than or equal to zero"!
|
|
|
+ else:
|
|
|
+ return "Natural number not larger than or equal to zero"!
|
|
|
+ """
|
|
|
+
|
|
|
+code_string = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ Element function constraint(model : Element, name : String):
|
|
|
+ if (is_physical_string(model["model"][name])):
|
|
|
+ return "OK"!
|
|
|
+ else:
|
|
|
+ return "String has non-string instance"!
|
|
|
+ """
|
|
|
+
|
|
|
+code_boolean = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ Element function constraint(model : Element, name : String):
|
|
|
+ if (is_physical_boolean(model["model"][name])):
|
|
|
+ return "OK"!
|
|
|
+ else:
|
|
|
+ return "Boolean has non-boolean instance"!
|
|
|
+ """
|
|
|
+
|
|
|
+code_location = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ include "library.alh"
|
|
|
+ Element function constraint(model : Element, name : String):
|
|
|
+ if (is_physical_string(model["model"][name])):
|
|
|
+ if (element_neq(import_node(model["model"][name]), read_root())):
|
|
|
+ return "OK"!
|
|
|
+ else:
|
|
|
+ return "Location references non-existing element!"!
|
|
|
+ else:
|
|
|
+ return "Location has non-string instance"!
|
|
|
+ """
|
|
|
+
|
|
|
+code_complex_attribute = \
|
|
|
+ """
|
|
|
+ include "primitives.alh"
|
|
|
+ include "library.alh"
|
|
|
+ Element function constraint(model : Element, name : String):
|
|
|
+ if (is_physical_string(model["model"][name])):
|
|
|
+ if (element_neq(import_node(model["model"][name]), read_root())):
|
|
|
+ return "OK"!
|
|
|
+ else:
|
|
|
+ return "Complex Attribute references non-existing element!"!
|
|
|
+ else:
|
|
|
+ return "Complex Attribute has non-string value"!
|
|
|
+ """
|
|
|
+
|
|
|
class TestConstructorsModels(unittest.TestCase):
|
|
|
def test_constructors_instantiate_bottom(self):
|
|
|
commands = bottom + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_action_language(self):
|
|
|
- commands = bottom + action_language + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
+ commands = bottom + action_language + bottom_link_al + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_constraints_scd(self):
|
|
|
- commands = bottom + action_language + add_constraints(1) + conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
+ commands = bottom + action_language + bottom_link_al + \
|
|
|
+ add_constraint("1", "Natural", code_natural) + \
|
|
|
+ add_constraint("1", "String", code_string) + \
|
|
|
+ add_constraint("1", "Location", code_location) + \
|
|
|
+ add_constraint("1", "Boolean", code_boolean) + \
|
|
|
+ add_constraint("1", "ComplexAttribute", code_complex_attribute) + \
|
|
|
+ conformance_check("models/SimpleClassDiagrams_new") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_constraints_pn(self):
|
|
|
- commands = bottom + action_language + add_constraints(1) + instantiate_scd + add_constraints(2) + instantiate_pn + conformance_check("models/PN_instance") + ["return", False]
|
|
|
+ commands = bottom + action_language + bottom_link_al + \
|
|
|
+ add_constraint("1", "Natural", code_natural) + \
|
|
|
+ add_constraint("1", "String", code_string) + \
|
|
|
+ add_constraint("1", "Location", code_location) + \
|
|
|
+ add_constraint("1", "Boolean", code_boolean) + \
|
|
|
+ add_constraint("1", "ComplexAttribute", code_complex_attribute) + \
|
|
|
+ instantiate_scd + \
|
|
|
+ instantiate_pn + \
|
|
|
+ add_constraint("3", "Natural", code_natural) + \
|
|
|
+ conformance_check("models/PN_instance") + ["return", False]
|
|
|
self.assertTrue(run_barebone(commands, ["OK"], 1))
|
|
|
|
|
|
def test_constructors_instantiate_scd(self):
|