Browse Source

Added some more tests for invalid models

Yentl Van Tendeloo 9 years ago
parent
commit
bf0a519c29

+ 156 - 0
integration/code/several_petrinets.mvc

@@ -0,0 +1,156 @@
+import models/SimpleClassDiagrams as SCD
+include "primitives.alh"
+
+SCD PetriNets{
+    Class Natural {
+        $
+            if (bool_not(is_physical_int(self))):
+                return "Natural has no integer value"
+            elif (integer_lt(self, 0)):
+                return "Natural does not have a positive or zero value"
+            else:
+                return "OK"
+         $
+    }
+    Class Place{
+        tokens : Natural
+    }
+    Class Transition{}
+    Association P2T (Place, Transition) {
+        weight : Natural
+    }
+    Association T2P (Transition, Place) {
+        weight : Natural
+    }
+}
+
+PetriNets valid_petrinet {
+    Place p1 {
+        tokens = 1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {
+        weight = 1
+    }
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_1 {
+    Place p1 {
+        tokens = -1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {
+        weight = 1
+    }
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_2 {
+    Place p1 {
+        tokens = 1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {
+        weight = -1
+    }
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_3 {
+    Place p1 {
+        tokens = 1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T wrong_p2t (p1, p2) {
+        weight = 1
+    }
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_4 {
+    Place p1 {
+        tokens = 1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {
+        weight = 1
+    }
+    T2P wrong_t2p(p1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_5 {
+    Place p1 {}
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {
+        weight = 1
+    }
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_6 {
+    Place p1 {
+        tokens = 1
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {}
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+PetriNets invalid_petrinet_7 {
+    Place p1 {
+        tokens = "abc"
+    }
+    Place p2 {
+        tokens = 3
+    }
+    Transition t1 {}
+    P2T (p1, t1) {}
+    T2P (t1, p2) {
+        weight = 2
+    }
+}
+
+export valid_petrinet to models/valid_petrinet
+export invalid_petrinet_1 to models/invalid_petrinet_1
+export invalid_petrinet_2 to models/invalid_petrinet_2
+export invalid_petrinet_3 to models/invalid_petrinet_3
+export invalid_petrinet_4 to models/invalid_petrinet_4
+export invalid_petrinet_5 to models/invalid_petrinet_5
+export invalid_petrinet_6 to models/invalid_petrinet_6
+export invalid_petrinet_7 to models/invalid_petrinet_7

+ 14 - 0
integration/test_constructors_models_compiled.py

@@ -77,3 +77,17 @@ class TestConstructorsModelsCompiled(unittest.TestCase):
                    conformance_check("models/my_petrinet") + \
                    ['"return"', 'false']
         self.assertTrue(run_barebone(commands, ["OK"], 1))
+
+    def test_constructors_petrinet_invalids(self):
+        commands = ['"model"' ,'"initialize_SCD"', '"models/SimpleClassDiagrams"', '"exit"'] + \
+                   model_compile("integration/code/several_petrinets.mvc") + \
+                   conformance_check("models/valid_petrinet") + \
+                   conformance_check("models/invalid_petrinet_1") + \
+                   conformance_check("models/invalid_petrinet_2") + \
+                   conformance_check("models/invalid_petrinet_3") + \
+                   conformance_check("models/invalid_petrinet_4") + \
+                   conformance_check("models/invalid_petrinet_5") + \
+                   conformance_check("models/invalid_petrinet_6") + \
+                   conformance_check("models/invalid_petrinet_7") + \
+                   ['"return"', 'false']
+        self.assertTrue(run_barebone(commands, ["OK", "Natural does not have a positive or zero value", "Natural does not have a positive or zero value", "Destination of model edge not typed by source of type: wrong_p2t", "Source of model edge not typed by source of type: wrong_t2p", "Minimum cardinality violation: Place_tokens", "Minimum cardinality violation: P2T_weight", "Natural has no integer value"], 1))