Explorar el Código

Add test for transformation_between and check for querying all transformations

Yentl Van Tendeloo hace 7 años
padre
commit
0a87c63e7c
Se han modificado 2 ficheros con 216 adiciones y 0 borrados
  1. 3 0
      bootstrap/core_algorithm.alc
  2. 213 0
      unit/test_all.py

+ 3 - 0
bootstrap/core_algorithm.alc

@@ -1199,6 +1199,9 @@ String function cmd_transformation_between(source_dict : String, target_dict : S
 	String link
 	Element keys
 
+	if (dict_len(source_dict) + dict_len(target_dict) == 0):
+		return "Incorrect format: cannot resolve empty input and output list as this would return all transformations."!
+
 	result = allInstances(core, "Transformation")
 
 	// Iterate over all inputs

+ 213 - 0
unit/test_all.py

@@ -3562,6 +3562,219 @@ class TestModelverse(unittest.TestCase):
         except NotAModel:
             pass
 
+    def test_op_transformation_between_MANUAL(self):
+        # Add set of transformations
+        def create_transf(name, inputs, outputs):
+            transformation_add_MANUAL({"key_%s" % i: "users/user/test/" + i for i in inputs}, {"key_%s" % i: "users/user/test/" + i for i in outputs}, "users/user/test/" + name)
+
+        model_add("users/user/test/A", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/B", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/C", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/D", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/E", "formalisms/SimpleClassDiagrams")
+
+        create_transf("1", ["A"], ["B"])
+        create_transf("2", ["A"], ["C", "D"])
+        create_transf("3", ["B", "C"], ["D"])
+        create_transf("4", ["A", "B"], ["D", "E"])
+
+        # Test normal operation
+        def check_transformations(inputs, outputs, expected):
+            assert transformation_between({"key_" + i: "users/user/test/" + i for i in inputs}, {"key_" + i: "users/user/test/" + i for i in outputs}) == set(["users/user/test/" + i for i in expected])
+
+        # Obvious ones, with a perfect signature match
+        check_transformations(["A"], ["B"], ["1"])
+        check_transformations(["A"], ["C", "D"], ["2"])
+        check_transformations(["B", "C"], ["D"], ["3"])
+        check_transformations(["A", "B"], ["D", "E"], ["4"])
+
+        # Incomplete matches
+        check_transformations(["A"], [], ["1", "2", "4"])
+        check_transformations(["B"], [], ["3", "4"])
+        check_transformations(["C"], [], ["3"])
+        check_transformations(["D"], [], [])
+        check_transformations(["E"], [], [])
+        check_transformations([], ["A"], [])
+        check_transformations([], ["B"], ["1"])
+        check_transformations([], ["C"], ["2"])
+        check_transformations([], ["D"], ["2", "3", "4"])
+        check_transformations([], ["E"], ["4"])
+
+        # Complete match, which doesn't return as it would give all transformations in the Modelverse...
+        try:
+            check_transformations([], [], [])
+            self.fail()
+        except IncorrectFormat:
+            pass
+
+        # Non-existing model (source)
+        try:
+            assert transformation_between({"key_A": "users/user/test/Z"}, {"key_B": "users/user/test/B"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (source)
+        assert transformation_between({"key_B": "users/user/test/A"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Model mismatch (source)
+        assert transformation_between({"key_A": "users/user/test/B"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Non-existing model (target)
+        try:
+            assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/Z"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_A": "users/user/test/B"}) == set([])
+
+        # Model mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/A"}) == set([])
+
+    def test_op_transformation_between_AL(self):
+        # Add set of transformations
+        def create_transf(name, inputs, outputs):
+            transformation_add_AL({"key_%s" % i: "users/user/test/" + i for i in inputs}, {"key_%s" % i: "users/user/test/" + i for i in outputs}, "users/user/test/" + name, "Void function main():\n\treturn!")
+
+        model_add("users/user/test/A", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/B", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/C", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/D", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/E", "formalisms/SimpleClassDiagrams")
+
+        create_transf("1", ["A"], ["B"])
+        create_transf("2", ["A"], ["C", "D"])
+        create_transf("3", ["B", "C"], ["D"])
+        create_transf("4", ["A", "B"], ["D", "E"])
+
+        # Test normal operation
+        def check_transformations(inputs, outputs, expected):
+            assert transformation_between({"key_" + i: "users/user/test/" + i for i in inputs}, {"key_" + i: "users/user/test/" + i for i in outputs}) == set(["users/user/test/" + i for i in expected])
+
+        # Obvious ones, with a perfect signature match
+        check_transformations(["A"], ["B"], ["1"])
+        check_transformations(["A"], ["C", "D"], ["2"])
+        check_transformations(["B", "C"], ["D"], ["3"])
+        check_transformations(["A", "B"], ["D", "E"], ["4"])
+
+        # Incomplete matches
+        check_transformations(["A"], [], ["1", "2", "4"])
+        check_transformations(["B"], [], ["3", "4"])
+        check_transformations(["C"], [], ["3"])
+        check_transformations(["D"], [], [])
+        check_transformations(["E"], [], [])
+        check_transformations([], ["A"], [])
+        check_transformations([], ["B"], ["1"])
+        check_transformations([], ["C"], ["2"])
+        check_transformations([], ["D"], ["2", "3", "4"])
+        check_transformations([], ["E"], ["4"])
+
+        # Complete match, which doesn't return as it would give all transformations in the Modelverse...
+        try:
+            check_transformations([], [], [])
+            self.fail()
+        except IncorrectFormat:
+            pass
+
+        # Non-existing model (source)
+        try:
+            assert transformation_between({"key_A": "users/user/test/Z"}, {"key_B": "users/user/test/B"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (source)
+        assert transformation_between({"key_B": "users/user/test/A"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Model mismatch (source)
+        assert transformation_between({"key_A": "users/user/test/B"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Non-existing model (target)
+        try:
+            assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/Z"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_A": "users/user/test/B"}) == set([])
+
+        # Model mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/A"}) == set([])
+
+    def test_op_transformation_between_MT(self):
+        # Add set of transformations
+        def create_transf(name, inputs, outputs):
+            transformation_add_MT({"key_%s" % i: "users/user/test/" + i for i in inputs}, {"key_%s" % i: "users/user/test/" + i for i in outputs}, "users/user/test/" + name, "Composite a{}")
+
+        model_add("users/user/test/A", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/B", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/C", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/D", "formalisms/SimpleClassDiagrams")
+        model_add("users/user/test/E", "formalisms/SimpleClassDiagrams")
+
+        create_transf("1", ["A"], ["B"])
+        create_transf("2", ["A"], ["C", "D"])
+        create_transf("3", ["B", "C"], ["D"])
+        create_transf("4", ["A", "B"], ["D", "E"])
+
+        # Test normal operation
+        def check_transformations(inputs, outputs, expected):
+            assert transformation_between({"key_" + i: "users/user/test/" + i for i in inputs}, {"key_" + i: "users/user/test/" + i for i in outputs}) == set(["users/user/test/" + i for i in expected])
+
+        # Obvious ones, with a perfect signature match
+        check_transformations(["A"], ["B"], ["1"])
+        check_transformations(["A"], ["C", "D"], ["2"])
+        check_transformations(["B", "C"], ["D"], ["3"])
+        check_transformations(["A", "B"], ["D", "E"], ["4"])
+
+        # Incomplete matches
+        check_transformations(["A"], [], ["1", "2", "4"])
+        check_transformations(["B"], [], ["3", "4"])
+        check_transformations(["C"], [], ["3"])
+        check_transformations(["D"], [], [])
+        check_transformations(["E"], [], [])
+        check_transformations([], ["A"], [])
+        check_transformations([], ["B"], ["1"])
+        check_transformations([], ["C"], ["2"])
+        check_transformations([], ["D"], ["2", "3", "4"])
+        check_transformations([], ["E"], ["4"])
+
+        # Complete match, which doesn't return as it would give all transformations in the Modelverse...
+        try:
+            check_transformations([], [], [])
+            self.fail()
+        except IncorrectFormat:
+            pass
+
+        # Non-existing model (source)
+        try:
+            assert transformation_between({"key_A": "users/user/test/Z"}, {"key_B": "users/user/test/B"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (source)
+        assert transformation_between({"key_B": "users/user/test/A"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Model mismatch (source)
+        assert transformation_between({"key_A": "users/user/test/B"}, {"key_B": "users/user/test/B"}) == set([])
+
+        # Non-existing model (target)
+        try:
+            assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/Z"}) == set([])
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Key mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_A": "users/user/test/B"}) == set([])
+
+        # Model mismatch (target)
+        assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/A"}) == set([])
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):