123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- import unittest
- import sys
- import os
- from utils import execute, kill, run_file, run_barebone
- def flatten(lst):
- new_lst = []
- for f in lst:
- if isinstance(f, (list, tuple)):
- new_lst.extend(flatten(f))
- else:
- new_lst.append(f)
- return new_lst
- bottom = [
- '"model"',
- '"instantiate_bottom"', 1,
- '"add_node"', 1, '"Class"',
- '"add_node"', 1, '"Type"',
- '"add_node"', 1, '"Any"',
- '"add_node"', 1, '"String"',
- '"add_node"', 1, '"Integer"',
- '"add_value"', 1, '"inheritance"', '"inheritance"',
- '"add_value"', 1, '"link"', '"link"',
- '"add_value"', 1, '"name"', '"name"',
- '"add_edge"', 1, '"l1"', '"Class"', '"Any"',
- '"add_edge"', 1, '"l2"', '"Type"', '"Any"',
- '"add_edge"', 1, '"Inheritance"', '"Any"', '"Any"',
- '"add_edge"', 1, '"l4"', '"Inheritance"', '"inheritance"',
- '"add_edge"', 1, '"Association"', '"Any"', '"Any"',
- '"add_edge"', 1, '"l6"', '"Association"', '"Any"',
- '"add_edge"', 1, '"l7"', '"Association"', '"link"',
- '"add_edge"', 1, '"l8"', '"Association"', '"String"',
- '"add_edge"', 1, '"l9"', '"l8"', '"name"',
- '"exit"',
- ]
- retype = [
- '"model"',
- '"retype_model"', 1, 1,
- '"define_inheritance"', 1, '"Inheritance"',
- '"retype"', 1, '"Class"', '"Class"',
- '"retype"', 1, '"Type"', '"Class"',
- '"retype"', 1, '"Any"', '"Class"',
- '"retype"', 1, '"String"', '"Type"',
- '"retype"', 1, '"Integer"', '"Type"',
- '"retype"', 1, '"inheritance"', '"String"',
- '"retype"', 1, '"link"', '"String"',
- '"retype"', 1, '"name"', '"String"',
- '"retype"', 1, '"l1"', '"Inheritance"',
- '"retype"', 1, '"l2"', '"Inheritance"',
- '"retype"', 1, '"Inheritance"', '"Association"',
- '"retype"', 1, '"l4"', '"l8"',
- '"retype"', 1, '"Association"', '"Association"',
- '"retype"', 1, '"l6"', '"Inheritance"',
- '"retype"', 1, '"l7"', '"l8"',
- '"retype"', 1, '"l8"', '"Association"',
- '"retype"', 1, '"l9"', '"l8"',
- '"exit"',
- ]
- action_language = [
- '"model"',
- '"instantiate_node"', 1, '"Class"', '"Action"',
- '"instantiate_node"', 1, '"Class"', '"Statement"',
- '"instantiate_node"', 1, '"Class"', '"Expression"',
- '"instantiate_node"', 1, '"Class"', '"Funcdef"',
- '"instantiate_node"', 1, '"Class"', '"Param"',
- '"instantiate_node"', 1, '"Class"', '"If"',
- '"instantiate_node"', 1, '"Class"', '"Break"',
- '"instantiate_node"', 1, '"Class"', '"While"',
- '"instantiate_node"', 1, '"Class"', '"Continue"',
- '"instantiate_node"', 1, '"Class"', '"Assign"',
- '"instantiate_node"', 1, '"Class"', '"Return"',
- '"instantiate_node"', 1, '"Class"', '"Output"',
- '"instantiate_node"', 1, '"Class"', '"Declare"',
- '"instantiate_node"', 1, '"Class"', '"Global"',
- '"instantiate_node"', 1, '"Class"', '"Access"',
- '"instantiate_node"', 1, '"Class"', '"Constant"',
- '"instantiate_node"', 1, '"Class"', '"Input"',
- '"instantiate_node"', 1, '"Class"', '"Resolve"',
- '"instantiate_node"', 1, '"Class"', '"Call"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Funcdef"', '"Any"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Action"', '"Any"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Param"', '"Any"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Statement"', '"Action"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Expression"', '"Action"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Resolve"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"If"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Break"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Continue"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Global"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"While"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Assign"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Return"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Call"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Declare"', '"Statement"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Call"', '"Expression"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Access"', '"Expression"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Constant"', '"Expression"',
- '"instantiate_link"', 1, '"Inheritance"', '""', '"Input"', '"Expression"',
- '"instantiate_link"', 1, '"Association"', '"statement_next"', '"Statement"', '"Statement"',
- '"instantiate_attribute"', 1, '"statement_next"', '"name"', '"next"',
- '"instantiate_link"', 1, '"Association"', '"if_cond"', '"If"', '"Expression"',
- '"instantiate_attribute"', 1, '"if_cond"', '"name"', '"cond"',
- '"instantiate_link"', 1, '"Association"', '"if_true"', '"If"', '"Statement"',
- '"instantiate_attribute"', 1, '"if_true"', '"name"', '"true"',
- '"instantiate_link"', 1, '"Association"', '"if_false"', '"If"', '"Statement"',
- '"instantiate_attribute"', 1, '"if_false"', '"name"', '"false"',
- '"instantiate_link"', 1, '"Association"', '"while_cond"', '"While"', '"Expression"',
- '"instantiate_attribute"', 1, '"while_cond"', '"name"', '"cond"',
- '"instantiate_link"', 1, '"Association"', '"while_body"', '"While"', '"Statement"',
- '"instantiate_attribute"', 1, '"while_body"', '"name"', '"body"',
- '"instantiate_link"', 1, '"Association"', '"assign_var"', '"Assign"', '"Any"',
- '"instantiate_attribute"', 1, '"assign_var"', '"name"', '"var"',
- '"instantiate_link"', 1, '"Association"', '"assign_value"', '"Assign"', '"Expression"',
- '"instantiate_attribute"', 1, '"assign_value"', '"name"', '"value"',
- '"instantiate_link"', 1, '"Association"', '"break_while"', '"Break"', '"While"',
- '"instantiate_attribute"', 1, '"break_while"', '"name"', '"while"',
- '"instantiate_link"', 1, '"Association"', '"continue_while"', '"Continue"', '"While"',
- '"instantiate_attribute"', 1, '"continue_while"', '"name"', '"while"',
- '"instantiate_link"', 1, '"Association"', '"return_value"', '"Return"', '"Expression"',
- '"instantiate_attribute"', 1, '"return_value"', '"name"', '"value"',
- '"instantiate_link"', 1, '"Association"', '"resolve_var"', '"Resolve"', '"Any"',
- '"instantiate_attribute"', 1, '"resolve_var"', '"name"', '"var"',
- '"instantiate_link"', 1, '"Association"', '"access_var"', '"Access"', '"Any"',
- '"instantiate_attribute"', 1, '"access_var"', '"name"', '"var"',
- '"instantiate_link"', 1, '"Association"', '"constant_node"', '"Constant"', '"Any"',
- '"instantiate_attribute"', 1, '"constant_node"', '"name"', '"node"',
- '"instantiate_link"', 1, '"Association"', '"output_node"', '"Output"', '"Expression"',
- '"instantiate_attribute"', 1, '"output_node"', '"name"', '"node"',
- '"instantiate_link"', 1, '"Association"', '"global_var"', '"Global"', '"String"',
- '"instantiate_attribute"', 1, '"global_var"', '"name"', '"var"',
- '"instantiate_link"', 1, '"Association"', '"param_name"', '"Param"', '"String"',
- '"instantiate_attribute"', 1, '"param_name"', '"name"', '"name"',
- '"instantiate_link"', 1, '"Association"', '"param_value"', '"Param"', '"Expression"',
- '"instantiate_attribute"', 1, '"param_value"', '"name"', '"value"',
- '"instantiate_link"', 1, '"Association"', '"param_next_param"', '"Param"', '"Param"',
- '"instantiate_attribute"', 1, '"param_next_param"', '"name"', '"next_param"',
- '"instantiate_link"', 1, '"Association"', '"funcdef_body"', '"Funcdef"', '"Statement"',
- '"instantiate_attribute"', 1, '"funcdef_body"', '"name"', '"body"',
- '"instantiate_link"', 1, '"Association"', '"call_func"', '"Call"', '"Expression"',
- '"instantiate_attribute"', 1, '"call_func"', '"name"', '"func"',
- '"instantiate_link"', 1, '"Association"', '"call_params"', '"Call"', '"Param"',
- '"instantiate_attribute"', 1, '"call_params"', '"name"', '"params"',
- '"instantiate_link"', 1, '"Association"', '"call_last_param"', '"Call"', '"Param"',
- '"instantiate_attribute"', 1, '"call_last_param"', '"name"', '"last_param"',
- '"exit"',
- ]
- bottom_attributes = [
- '"model"',
- '"instantiate_link"', 1, '"Association"', '"lc"', '"Class"', '"Integer"',
- '"instantiate_attribute"', 1, '"lc"', '"name"', '"lower_cardinality"',
- '"instantiate_link"', 1, '"Association"', '"uc"', '"Class"', '"Integer"',
- '"instantiate_attribute"', 1, '"uc"', '"name"', '"upper_cardinality"',
- '"instantiate_link"', 1, '"Association"', '"slc"', '"Association"', '"Integer"',
- '"instantiate_attribute"', 1, '"slc"', '"name"', '"source_lower_cardinality"',
- '"instantiate_link"', 1, '"Association"', '"suc"', '"Association"', '"Integer"',
- '"instantiate_attribute"', 1, '"suc"', '"name"', '"source_upper_cardinality"',
- '"instantiate_link"', 1, '"Association"', '"tlc"', '"Association"', '"Integer"',
- '"instantiate_attribute"', 1, '"tlc"', '"name"', '"target_lower_cardinality"',
- '"instantiate_link"', 1, '"Association"', '"tuc"', '"Association"', '"Integer"',
- '"instantiate_attribute"', 1, '"tuc"', '"name"', '"target_upper_cardinality"',
- '"exit"',
- ]
- instantiate_scd = [
- '"model"',
- '"instantiate_model"', 1, 2,
- '"define_inheritance"', 2, '"Inheritance"',
- '"instantiate_node"', 2, '"Class"', '"Place"',
- '"instantiate_node"', 2, '"Class"', '"Transition"',
- '"instantiate_node"', 2, '"Type"', '"Integer"',
- '"instantiate_link"', 2, '"Association"', '"P2T"', '"Place"', '"Transition"',
- '"instantiate_link"', 2, '"Association"', '"T2P"', '"Transition"', '"Place"',
- '"instantiate_link"', 2, '"Association"', '"Place_tokens"', '"Place"', '"Integer"',
- '"instantiate_attribute"', 2, '"Place_tokens"', '"name"', '"tokens"',
- '"instantiate_link"', 2, '"Association"', '"P2T_weight"', '"P2T"', '"Integer"',
- '"instantiate_attribute"', 2, '"P2T_weight"', '"name"', '"weight"',
- '"instantiate_link"', 2, '"Association"', '"T2P_weight"', '"T2P"', '"Integer"',
- '"instantiate_attribute"', 2, '"T2P_weight"', '"name"', '"weight"',
- '"exit"',
- ]
- instantiate_pn = [
- '"model"',
- '"instantiate_model"', 2, 3,
- '"instantiate_node"', 3, '"Place"', '"p1"',
- '"instantiate_node"', 3, '"Place"', '"p2"',
- '"instantiate_node"', 3, '"Transition"', '"t1"',
- '"instantiate_node"', 3, '"Transition"', '"t2"',
- '"instantiate_link"', 3, '"P2T"', '"p1_t1"', '"p1"', '"t1"',
- '"instantiate_link"', 3, '"T2P"', '"t1_p2"', '"t1"', '"p2"',
- '"instantiate_link"', 3, '"P2T"', '"p2_t2"', '"p2"', '"t2"',
- '"instantiate_link"', 3, '"T2P"', '"t2_p1"', '"t2"', '"p1"',
- '"instantiate_attribute"', 3, '"p1_t1"', '"weight"', '1',
- '"instantiate_attribute"', 3, '"t1_p2"', '"weight"', '2',
- '"instantiate_attribute"', 3, '"p2_t2"', '"weight"', '3',
- '"instantiate_attribute"', 3, '"t2_p1"', '"weight"', '4',
- '"instantiate_attribute"', 3, '"p1"', '"tokens"', '5',
- '"instantiate_attribute"', 3, '"p2"', '"tokens"', '6',
- '"exit"',
- ]
- instantiate_example = [
- '"model"',
- '"instantiate_model"', 1, 2,
- '"define_inheritance"', 2, '"Inheritance"',
- '"instantiate_node"', 2, '"Class"', '"A"',
- '"instantiate_node"', 2, '"Class"', '"B"',
- '"instantiate_node"', 2, '"Class"', '"C"',
- '"instantiate_link"', 2, '"Inheritance"', '"b_inherits_a"', '"B"', '"A"',
- '"instantiate_link"', 2, '"Association"', '"A_tokens"', '"A"', '"B"',
- '"instantiate_attribute"', 2, '"A_tokens"', '"name"', '"tokens"',
- '"instantiate_link"', 2, '"Association"', '"C_tokens"', '"C"', '"B"',
- '"instantiate_attribute"', 2, '"C_tokens"', '"name"', '"tokens"',
- '"exit"',
- '"model"',
- '"instantiate_model"', 2, 3,
- '"instantiate_node"', 3, '"A"', '"a"',
- '"instantiate_attribute"', 3, '"a"', '"tokens"', '"b"',
- '"instantiate_node"', 3, '"B"', '"b"',
- '"instantiate_node"', 3, '"C"', '"c"',
- '"instantiate_attribute"', 3, '"c"', '"tokens"', '"b"',
- '"exit"',
- ]
- def conformance_call(operation, model, metamodel):
- return [
- '"output"',
- '"call"',
- '"access"', '"resolve"', '"%s"' % operation,
- '3',
- '"const"', 3,
- '"const"', '"%s"' % model,
- '"const"', '"%s"' % metamodel,
- 'false',
- 'true',
- ]
- is_direct_instance = \
- conformance_call("is_direct_instance", "a", "A") + \
- conformance_call("is_direct_instance", "b", "A") + \
- conformance_call("is_direct_instance", "c", "A") + \
- conformance_call("is_direct_instance", "a", "B") + \
- conformance_call("is_direct_instance", "b", "B") + \
- conformance_call("is_direct_instance", "c", "B") + \
- conformance_call("is_direct_instance", "a", "C") + \
- conformance_call("is_direct_instance", "b", "C") + \
- conformance_call("is_direct_instance", "c", "C")
- is_nominal_instance = \
- conformance_call("is_nominal_instance", "a", "A") + \
- conformance_call("is_nominal_instance", "b", "A") + \
- conformance_call("is_nominal_instance", "c", "A") + \
- conformance_call("is_nominal_instance", "a", "B") + \
- conformance_call("is_nominal_instance", "b", "B") + \
- conformance_call("is_nominal_instance", "c", "B") + \
- conformance_call("is_nominal_instance", "a", "C") + \
- conformance_call("is_nominal_instance", "b", "C") + \
- conformance_call("is_nominal_instance", "c", "C")
- def conformance_check(node):
- return [
- '"output"',
- '"call"',
- '"access"', '"resolve"', '"conformance_scd"',
- '1',
- '"const"', node,
- 'false',
- 'true',
- ]
- class TestConstructorsModels(unittest.TestCase):
- def test_constructors_instantiate_bottom(self):
- commands = bottom + retype + bottom_attributes + conformance_check(1) + ['"return"', 'false']
- self.assertTrue(run_barebone(commands, ["OK"], 1))
- def test_constructors_action_language(self):
- commands = bottom + retype + bottom_attributes + action_language + conformance_check(1) + ['"return"', 'false']
- self.assertTrue(run_barebone(commands, ["OK"], 1))
- def test_constructors_instantiate_scd(self):
- commands = bottom + retype + bottom_attributes + instantiate_scd + conformance_check(2) + ['"return"', 'false']
- self.assertTrue(run_barebone(commands, ["OK"], 1))
- def test_constructors_instantiate_pn(self):
- commands = bottom + retype + bottom_attributes + instantiate_scd + instantiate_pn + conformance_check(3) + ['"return"', 'false']
- self.assertTrue(run_barebone(commands, ["OK"], 1))
- def test_constructors_instantiate_example(self):
- commands = bottom + retype + bottom_attributes + instantiate_example + conformance_check(2) + conformance_check(3) + ['"return"', 'false']
- self.assertTrue(run_barebone(commands, ["OK", "OK"], 1))
- def test_constructors_is_direct_instance(self):
- commands = bottom + retype + bottom_attributes + instantiate_example + is_direct_instance + ['"return"', 'false']
- expected = ['True', 'False', 'False',
- 'False', 'True', 'False',
- 'False', 'False', 'True']
- self.assertTrue(run_barebone(commands, expected, 1))
- def test_constructors_is_nominal_instance(self):
- commands = bottom + retype + bottom_attributes + instantiate_example + is_nominal_instance + ['"return"', 'false']
- expected = ['True', 'True', 'False',
- 'False', 'True', 'False',
- 'False', 'False', 'True']
- self.assertTrue(run_barebone(commands, expected, 1))
|