浏览代码

Fix for finding the bottom type

Yentl Van Tendeloo 8 年之前
父节点
当前提交
bc6f4c5675
共有 3 个文件被更改,包括 33 次插入14 次删除
  1. 5 5
      bootstrap/conformance_finding.alc
  2. 2 0
      bootstrap/mini_modify.alc
  3. 26 9
      integration/test_mvc.py

+ 5 - 5
bootstrap/conformance_finding.alc

@@ -32,10 +32,10 @@ Boolean function find_type_mapping(model : Element):
 	// 2) find a mapping based on the current partial mapping, but only if it is not yet complete
 	// TODO this must be expanded for other things than trivial metamodels!
 	if (dict_len(model["model"]) > dict_len(tm)):
-		// log("Model is incompletely typed!")
-		// log("Model has: " + set_to_string(dict_keys(model["model"])))
-		// log("Type mapping has: " + set_to_string(dict_keys(tm)))
-		// log("Missing: " + set_to_string(set_difference(dict_keys(model["model"]), dict_keys(tm))))
+		//log("Model is incompletely typed!")
+		//log("Model has: " + set_to_string(dict_keys(model["model"])))
+		//log("Type mapping has: " + set_to_string(dict_keys(tm)))
+		//log("Missing: " + set_to_string(set_difference(dict_keys(model["model"]), dict_keys(tm))))
 
 		// TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
 		//      and it makes the assumption that SCD is the M3 level...
@@ -80,7 +80,7 @@ Boolean function find_type_mapping(model : Element):
 		while (set_len(elems) > 0):
 			elem = set_pop(elems)
 
-			if (is_edge(elem)):
+			if (is_edge(model["model"][elem])):
 				retype(model, elem, edge_element)
 			else:
 				retype(model, elem, node_element)

+ 2 - 0
bootstrap/mini_modify.alc

@@ -50,6 +50,8 @@ String function pretty_print(model : Element):
 				else:
 					result = result + ((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
 				result = result + "\n"
+		else:
+			log("Skip instance: " + type)
 	return result!
 
 String function cmd_help_m(write : Boolean):

+ 26 - 9
integration/test_mvc.py

@@ -55,6 +55,13 @@ def get_model_list(location):
 def compare_locations(location, extra_to_default):
     assert model_list(location) == get_model_list(location) | set(extra_to_default)
 
+def compare_unordered_lists(got, expected):
+    assert len(got) == len(expected)
+    for i in got:
+        assert i in expected
+    for i in expected:
+        assert i in got
+
 class TestModelverseCore(unittest.TestCase):
     def setUp(self):
         self.proc, self.address = start_mvc()
@@ -386,7 +393,9 @@ class TestModelverseCore(unittest.TestCase):
 
         alter_context("formalisms/PetriNet", "formalisms/SimpleClassDiagrams")
         alter_context("models/my_pn", "formalisms/PetriNet")
-        element_list_nice("formalisms/PetriNet") == \
+        
+        got = element_list_nice("formalisms/PetriNet")
+        expected = \
             [{'id': 'Natural', 'type': 'SimpleAttribute', 'constraint': None},
              {'id': 'String', 'type': 'SimpleAttribute', 'constraint': None},
              {'id': 'Place', 'type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': None},
@@ -399,8 +408,10 @@ class TestModelverseCore(unittest.TestCase):
              {'id': 'T2P', 'type': 'Association', '__source': 'Transition', '__target': 'Place', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': None},
              {'id': 'T2P_weight', 'type': 'AttributeLink', '__source': 'T2P', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': None}
             ]
+        compare_unordered_lists(got, expected)
 
-        element_list_nice("models/my_pn") == \
+        got = element_list_nice("models/my_pn")
+        expected = \
             [{'id': 'p1', 'type': 'Place', 'tokens': 1, 'name': 'p1'},
              {'id': 'p2', 'type': 'Place', 'tokens': 2, 'name': 'p2'},
              {'id': 'p3', 'type': 'Place', 'tokens': 3, 'name': 'p3'},
@@ -409,30 +420,36 @@ class TestModelverseCore(unittest.TestCase):
              {'id': '__1', 'type': 'P2T', '__source': 'p2', '__target': 't1', 'weight': 1},
              {'id': '__2', 'type': 'T2P', '__source': 't1', '__target': 'p3', 'weight': 2}
             ]
+        compare_unordered_lists(got, expected)
 
         alter_context("formalisms/PetriNet", "formalisms/Bottom")
         alter_context("models/my_pn", "formalisms/Bottom")
 
-        count = 0
+        count_nodes = 0
+        count_edges = 0
         for entry in element_list_nice("formalisms/PetriNet"):
             assert entry["type"] in ["Node", "Edge"]
             if entry["type"] == "Node":
                 assert len(entry) == 2
+                count_nodes += 1
             else:
                 assert len(entry) == 4
-            count += 1
-        #TODO be more specific here
-        assert count > 1
+                count_edges += 1
+        assert count_nodes == 14
+        assert count_edges == 17
 
-        count = 0
+        count_nodes = 0
+        count_edges = 0
         for entry in element_list_nice("models/my_pn"):
             assert entry["type"] in ["Node", "Edge"]
             if entry["type"] == "Node":
                 assert len(entry) == 2
+                count_nodes += 1
             else:
                 assert len(entry) == 4
-        #TODO be more specific here
-        assert count > 1
+                count_edges += 1
+        assert count_nodes == 14
+        assert count_edges == 13
 
         alter_context("formalisms/PetriNet", "formalisms/PetriNet")
         alter_context("models/my_pn", "formalisms/SimpleClassDiagrams")