예제 #1
0
        public void IsOfKindTest()
        {
            var petriNet = new Model.PetriNet.PetriNet();
            var actual   = petriNet.IsOfKind();

            Assert.AreEqual("PetriNet", actual);
        }
        public void IsOfKindTest()
        {
            var petriNet = new Model.PetriNet.PetriNet();
            var actual = petriNet.IsOfKind();

            Assert.AreEqual("PetriNet", actual);
        }
예제 #3
0
        public void PetriNetTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Assert.IsNotNull(testNet.Places);
            Assert.IsNotNull(testNet.Transitions);
            Assert.AreEqual("TestNet", testNet.Name);
        }
        public void IsEnabledFail()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start1 = testNet.AddPlace("Start", 1);
            Place start2 = testNet.AddPlace("Start", 0);
            Transition transition = testNet.AddTransition("Transition", new List<Place> { start1, start2 });

            Assert.IsFalse(transition.IsEnabled);
        }
예제 #5
0
        public void AddLoopTestNoParameter()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            testNet.AddLoop();

            Assert.AreEqual(0, testNet.Transitions.Count);
            Assert.AreEqual(0, testNet.Places.Count);
        }
예제 #6
0
        public void GetPlaceByNameTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace = testNet.AddPlace("TestPlace", 2);

            Place theSamePlace = testNet.GetPlaceByName("TestPlace");

            Assert.AreEqual(theSamePlace, testPlace);
        }
        public void AddLoopTestNoParameter()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            testNet.AddLoop();

            Assert.AreEqual(0, testNet.Transitions.Count);
            Assert.AreEqual(0, testNet.Places.Count);
        }
예제 #8
0
        public void FindTransitionTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition       = testNet.AddTransition("TestTransition");

            Transition transition2 = testNet.FindTransition("TestTransition");

            Assert.AreEqual(transition2, testTransition);
        }
        public void DeepCopyTest()
        {
            var petriNet1 = new Model.PetriNet.PetriNet();
            petriNet1.AddTransition("Test");

            var copy = (Model.PetriNet.PetriNet)petriNet1.DeepCopy();
            copy.Transitions[0].Name = "Test1";

            Assert.AreNotEqual(copy.Transitions[0].Name, petriNet1.Transitions[0].Name);
        }
예제 #10
0
        public void FindTransitionTestNotFound()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place tempPlaceIn  = testNet.AddPlace("place_1");
            Place tempPlaceOut = testNet.AddPlace("place_2");

            testNet.AddTransition("transition_1", incomingPlace: tempPlaceIn, outgoingPlace: tempPlaceOut);

            Assert.IsNull(testNet.FindTransition("not in the list"));
        }
예제 #11
0
        public void IsEnabledFail()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place      start1     = testNet.AddPlace("Start", 1);
            Place      start2     = testNet.AddPlace("Start", 0);
            Transition transition = testNet.AddTransition("Transition", new List <Place> {
                start1, start2
            });

            Assert.IsFalse(transition.IsEnabled);
        }
예제 #12
0
        public void AddTransitionTestSinglePlaces()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1", 2);
            Place testPlace2 = testNet.AddPlace("TestPlace2", 3);

            Transition testTransition = testNet.AddTransition("TestTransition", incomingPlace: testPlace1, outgoingPlace: testPlace2);

            Assert.AreEqual(testPlace1, testTransition.IncomingPlaces.First());
            Assert.AreEqual(testPlace2, testTransition.OutgoingPlaces.First());
        }
예제 #13
0
        public void AddPlaceTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Place testPlace = testNet.AddPlace("TestPlace", 2);

            Assert.IsNotNull(testPlace);
            Assert.IsInstanceOfType(testPlace, typeof(Place));
            Assert.AreEqual(testNet.Places.First(), testPlace);
            Assert.AreEqual(2, testPlace.Token);
        }
        public void AddPlaceTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Place testPlace = testNet.AddPlace("TestPlace", 2);

            Assert.IsNotNull(testPlace);
            Assert.IsInstanceOfType(testPlace, typeof(Place));
            Assert.AreEqual(testNet.Places.First(), testPlace);
            Assert.AreEqual(2, testPlace.Token);
        }
예제 #15
0
        public void FireTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place      start      = testNet.AddPlace("Start", 1);
            Place      end        = testNet.AddPlace("End");
            Transition transition = testNet.AddTransition("Transition", incomingPlace: start, outgoingPlace: end);

            transition.Fire();

            Assert.AreEqual(1, end.Token);
            Assert.AreEqual(0, start.Token);
        }
예제 #16
0
        public void AddTransitionTestNoPlaces()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Transition testTransition = testNet.AddTransition("TestTransition");

            Assert.IsNotNull(testTransition);
            Assert.IsInstanceOfType(testTransition, typeof(Transition));
            Assert.AreEqual(testNet.Transitions.First(), testTransition);
            Assert.IsNotNull(testTransition.IncomingPlaces);
            Assert.IsNotNull(testTransition.OutgoingPlaces);
        }
예제 #17
0
        public void GetNodesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition       = testNet.AddTransition("TestTransition");
            Place      testPlace            = testNet.AddPlace("TestPlace");

            List <Node> list = testNet.Nodes;

            Assert.IsTrue(list.Contains(testTransition));
            Assert.IsTrue(list.Contains(testPlace));
            Assert.AreEqual(2, list.Count);
        }
예제 #18
0
        public void CountTransitionsWithoutANDsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            testNet.AddTransition("TestTransition1");
            testNet.AddTransition("AND");
            testNet.AddTransition();
            testNet.AddTransition("TestTransition4");

            int result = testNet.CountTransitionsWithoutANDs();

            Assert.AreEqual(2, result);
        }
예제 #19
0
        public void DeepCopyTest()
        {
            var petriNet1 = new Model.PetriNet.PetriNet();

            petriNet1.AddTransition("Test");

            var copy = (Model.PetriNet.PetriNet)petriNet1.DeepCopy();

            copy.Transitions[0].Name = "Test1";

            Assert.AreNotEqual(copy.Transitions[0].Name, petriNet1.Transitions[0].Name);
        }
        public void FireTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start = testNet.AddPlace("Start", 1);
            Place end = testNet.AddPlace("End");
            Transition transition = testNet.AddTransition("Transition", incomingPlace: start, outgoingPlace: end);

            transition.Fire();

            Assert.AreEqual(1, end.Token);
            Assert.AreEqual(0, start.Token);
        }
        public void AddTransitionTestNoPlaces()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Transition testTransition = testNet.AddTransition("TestTransition");

            Assert.IsNotNull(testTransition);
            Assert.IsInstanceOfType(testTransition, typeof(Transition));
            Assert.AreEqual(testNet.Transitions.First(), testTransition);
            Assert.IsNotNull(testTransition.IncomingPlaces);
            Assert.IsNotNull(testTransition.OutgoingPlaces);
        }
        public void AddLoopTestGivenNameEasyTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start = testNet.AddPlace("Start");
            Place end = testNet.AddPlace("End");
            testNet.AddTransition("TestTransition", incomingPlace: start, outgoingPlace: end);

            testNet.AddLoop("TestTransition");

            Assert.AreEqual(2, testNet.Transitions.Count);
            Assert.AreEqual(2, testNet.Places.Count);
            Assert.IsTrue(testNet.Transitions[1].IsLoop);
        }
        public void CleanUpPetriNetTest()
        {
            var petriNet = new Model.PetriNet.PetriNet();
            var place1 = petriNet.AddPlace("1");
            var place2 = petriNet.AddPlace("2");
            var place3 = petriNet.AddPlace("3");
            var place4 = petriNet.AddPlace("4");
            petriNet.AddTransition("eins", incomingPlace: place1, outgoingPlace: place2);
            petriNet.AddTransition("", incomingPlace: place2, outgoingPlace: place3);
            petriNet.AddTransition("drei", incomingPlace: place3, outgoingPlace: place4);

            petriNet = PetriNetOperation.CleanUpPetriNet(petriNet);
            Assert.IsTrue(petriNet.Transitions.Count == 2 && petriNet.Places.Count == 3, "Transitions =" + petriNet.Transitions.Count + " Places =" + petriNet.Places.Count);
        }
예제 #24
0
        public void AddLoopTestGivenNameEasyTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start = testNet.AddPlace("Start");
            Place end   = testNet.AddPlace("End");

            testNet.AddTransition("TestTransition", incomingPlace: start, outgoingPlace: end);

            testNet.AddLoop("TestTransition");

            Assert.AreEqual(2, testNet.Transitions.Count);
            Assert.AreEqual(2, testNet.Places.Count);
            Assert.IsTrue(testNet.Transitions[1].IsLoop);
        }
예제 #25
0
        public void GetPlacesWithoutFollowersTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1", 2);
            Place testPlace2 = testNet.AddPlace("TestPlace2", 3);
            Place testPlace3 = testNet.AddPlace("TestPlace3", 4);

            testPlace1.AppendOutgoingTransition(new Transition());
            testPlace3.AppendOutgoingTransition(new Transition());

            List <Place> testlist = testNet.GetPlacesWithoutFollowers();

            Assert.AreEqual(testlist.First(), testPlace2);
        }
        public void CleanUpPetriNetTest()
        {
            var petriNet = new Model.PetriNet.PetriNet();
            var place1   = petriNet.AddPlace("1");
            var place2   = petriNet.AddPlace("2");
            var place3   = petriNet.AddPlace("3");
            var place4   = petriNet.AddPlace("4");

            petriNet.AddTransition("eins", incomingPlace: place1, outgoingPlace: place2);
            petriNet.AddTransition("", incomingPlace: place2, outgoingPlace: place3);
            petriNet.AddTransition("drei", incomingPlace: place3, outgoingPlace: place4);

            petriNet = PetriNetOperation.CleanUpPetriNet(petriNet);
            Assert.IsTrue(petriNet.Transitions.Count == 2 && petriNet.Places.Count == 3, "Transitions =" + petriNet.Transitions.Count + " Places =" + petriNet.Places.Count);
        }
예제 #27
0
        public void RemoveNodeTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1      = testNet.AddTransition("TestTransition1");
            Transition testTransition2      = testNet.AddTransition("TestTransition2");
            Place      testPlace1           = testNet.AddPlace("TestPlace1");
            Place      testPlace2           = testNet.AddPlace("TestPlace2");

            testNet.RemoveNode(testTransition1);
            testNet.RemoveNode(testPlace1);

            Assert.AreEqual(1, testNet.Transitions.Count);
            Assert.AreEqual(1, testNet.Places.Count);
            Assert.AreEqual(testTransition2, testNet.Transitions.First());
            Assert.AreEqual(testPlace2, testNet.Places.First());
        }
예제 #28
0
        public void CountLoopsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1      = testNet.AddTransition("TestTransition1");

            testNet.AddTransition("TestTransition2");
            Transition testTransition3 = testNet.AddTransition("TestTransition3");

            testNet.AddTransition("TestTransition4");
            testTransition1.IsLoop = true;
            testTransition3.IsLoop = true;

            int result = testNet.CountLoops();

            Assert.AreEqual(2, result);
        }
예제 #29
0
        public void GetTransitionsWithoutFollowersTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1      = testNet.AddTransition("TestTransition1");
            Transition testTransition2      = testNet.AddTransition("TestTransition2");
            Transition testTransition3      = testNet.AddTransition("TestTransition3");

            testNet.AddTransition("TestTransition4");
            testTransition1.AddOutgoingPlace(new Place());
            testTransition2.AddOutgoingPlace(new Place());

            List <Transition> testList = testNet.GetTransitionsWithoutFollowers();

            Assert.IsNotNull(testList);
            Assert.AreEqual(testTransition3, testList.First());
            Assert.AreEqual(2, testList.Count);
        }
예제 #30
0
        public void GetSourcesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1      = testNet.AddTransition("TestTransition1");
            Transition testTransition2      = testNet.AddTransition("TestTransition2");

            testTransition2.AddIncomingPlace(new Place());
            Place testPlace1 = testNet.AddPlace("TestPlace1");
            Place testPlace2 = testNet.AddPlace("TestPlace2");

            testPlace2.AppendIncomingTransition(testTransition1);

            List <Node> list = testNet.GetSources();

            Assert.IsTrue(list.Contains(testTransition1));
            Assert.IsTrue(list.Contains(testPlace1));
            Assert.AreEqual(2, list.Count);
        }
예제 #31
0
        public void RemoveNodesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition  testTransition1     = testNet.AddTransition("TestTransition1");
            Transition  testTransition2     = testNet.AddTransition("TestTransition2");
            Place       testPlace1          = testNet.AddPlace("TestPlace1");
            Place       testPlace2          = testNet.AddPlace("TestPlace2");
            List <Node> nodesToRemove       = new List <Node> {
                testTransition1, testPlace1
            };

            testNet.RemoveNodes(nodesToRemove);

            Assert.AreEqual(1, testNet.Transitions.Count);
            Assert.AreEqual(1, testNet.Places.Count);
            Assert.AreEqual(testTransition2, testNet.Transitions.First());
            Assert.AreEqual(testPlace2, testNet.Places.First());
        }
예제 #32
0
        public void AddTransitionTestPlaceLists()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place        testPlace1         = testNet.AddPlace("TestPlace1", 2);
            Place        testPlace2         = testNet.AddPlace("TestPlace2", 3);
            Place        testPlace3         = testNet.AddPlace("TestPlace3", 2);
            Place        testPlace4         = testNet.AddPlace("TestPlace4", 3);
            List <Place> list1 = new List <Place> {
                testPlace1, testPlace2
            };
            List <Place> list2 = new List <Place> {
                testPlace3, testPlace4
            };

            Transition testTransition = testNet.AddTransition("TestTransition", list1, list2);

            Assert.AreEqual(testPlace1, testTransition.IncomingPlaces.First());
            Assert.AreEqual(testPlace3, testTransition.OutgoingPlaces.First());
        }
예제 #33
0
        public void MergeWithPetriNetTest()
        {
            Model.PetriNet.PetriNet testNet1 = new Model.PetriNet.PetriNet("TestNet");
            Place      start1 = testNet1.AddPlace("Start");
            Place      end1   = testNet1.AddPlace("End");
            Transition trans1 = testNet1.AddTransition("Trans1", incomingPlace: start1, outgoingPlace: end1);

            Model.PetriNet.PetriNet testNet2 = new Model.PetriNet.PetriNet("TestNet");
            Place      start2 = testNet2.AddPlace("Start");
            Place      end2   = testNet2.AddPlace("End");
            Transition trans2 = testNet2.AddTransition("Trans2", incomingPlace: start2, outgoingPlace: end2);

            testNet1.MergeWithPetriNet(testNet2, trans1);

            Assert.AreEqual(4, testNet1.Places.Count);
            Assert.AreEqual(2, testNet1.Transitions.Count);
            Assert.AreEqual(2, trans1.OutgoingPlaces.Count);
            Assert.AreEqual(trans2, trans1.OutgoingPlaces[1].OutgoingTransitions[0]);
        }
예제 #34
0
        public void RemoveNodeAndConnectionsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place      testPlace1           = testNet.AddPlace("TestPlace1");
            Place      testPlace2           = testNet.AddPlace("TestPlace2");
            Place      testPlace3           = testNet.AddPlace("TestPlace3");
            Transition testTransition1      = testNet.AddTransition("TestTransition1", incomingPlace: testPlace1, outgoingPlace: testPlace2);
            Transition testTransition2      = testNet.AddTransition("TestTransition2", incomingPlace: testPlace2, outgoingPlace: testPlace3);

            testNet.RemoveNodeAndConnections(testPlace2);

            Assert.AreEqual(0, testTransition1.OutgoingPlaces.Count);
            Assert.AreEqual(0, testTransition2.IncomingPlaces.Count);
            Assert.IsFalse(testNet.Places.Contains(testPlace2));

            testNet.RemoveNodeAndConnections(testTransition2);

            Assert.AreEqual(0, testPlace3.IncomingTransitions.Count);
        }
예제 #35
0
        public void GetTransitionsWithoutFollowersIgnoreLoopsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1      = testNet.AddTransition("TestTransition1");
            Transition testTransition2      = testNet.AddTransition("TestTransition2");
            Transition testTransition3      = testNet.AddTransition("TestTransition3");

            testNet.AddTransition("TestTransition4");
            testTransition1.AddOutgoingPlace(new Place());
            testTransition2.AddOutgoingPlace(new Place());
            Place testPlace = new Place();

            testTransition3.AddOutgoingPlace(testPlace);
            testPlace.AppendOutgoingTransition(new Transition("", isLoop: true));

            List <Transition> testList = testNet.GetTransitionsWithoutFollowersIgnoreLoops();

            Assert.IsNotNull(testList);
            Assert.AreEqual(testTransition3, testList.First());
            Assert.AreEqual(2, testList.Count);
        }
        public void AddLoopTestGivenTransitionHardTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start = testNet.AddPlace("Start");
            Place midLeft1 = testNet.AddPlace("MidLeft1");
            Place midLeft2 = testNet.AddPlace("MidLeft2");
            Place midLeft3 = testNet.AddPlace("MidLeft3");
            Place midRight1 = testNet.AddPlace("MidRight1");
            Place midRight2 = testNet.AddPlace("MidRight2");
            Place midRight3 = testNet.AddPlace("MidRight3");
            Place end = testNet.AddPlace("End");
            testNet.AddTransition("Left", incomingPlace: start, outgoingPlaces: new List<Place> { midLeft1, midLeft2, midLeft3 });
            Transition testTransition = testNet.AddTransition("TestTransition", new List<Place> { midLeft1, midLeft2, midLeft3 }, new List<Place> { midRight1, midRight2, midRight3 });
            testNet.AddTransition("Right", new List<Place> { midRight1, midRight2, midRight3 }, outgoingPlace: end);

            testNet.AddLoop(transition: testTransition);

            Assert.AreEqual(6, testNet.Transitions.Count);
            Assert.AreEqual(10, testNet.Places.Count);
            Assert.IsTrue(testNet.Transitions[3].IsLoop);
            Assert.AreEqual(testTransition, midLeft1.OutgoingTransitions[0].OutgoingPlaces[0].OutgoingTransitions[0]);
        }
        public void AddTransitionTestPlaceLists()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1", 2);
            Place testPlace2 = testNet.AddPlace("TestPlace2", 3);
            Place testPlace3 = testNet.AddPlace("TestPlace3", 2);
            Place testPlace4 = testNet.AddPlace("TestPlace4", 3);
            List<Place> list1 = new List<Place> { testPlace1, testPlace2 };
            List<Place> list2 = new List<Place> { testPlace3, testPlace4 };

            Transition testTransition = testNet.AddTransition("TestTransition", list1, list2);

            Assert.AreEqual(testPlace1, testTransition.IncomingPlaces.First());
            Assert.AreEqual(testPlace3, testTransition.OutgoingPlaces.First());
        }
        public void RemoveNodesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            Transition testTransition2 = testNet.AddTransition("TestTransition2");
            Place testPlace1 = testNet.AddPlace("TestPlace1");
            Place testPlace2 = testNet.AddPlace("TestPlace2");
            List<Node> nodesToRemove = new List<Node> { testTransition1, testPlace1 };

            testNet.RemoveNodes(nodesToRemove);

            Assert.AreEqual(1, testNet.Transitions.Count);
            Assert.AreEqual(1, testNet.Places.Count);
            Assert.AreEqual(testTransition2, testNet.Transitions.First());
            Assert.AreEqual(testPlace2, testNet.Places.First());
        }
        public void RemoveNodeAndConnectionsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1");
            Place testPlace2 = testNet.AddPlace("TestPlace2");
            Place testPlace3 = testNet.AddPlace("TestPlace3");
            Transition testTransition1 = testNet.AddTransition("TestTransition1", incomingPlace: testPlace1, outgoingPlace: testPlace2);
            Transition testTransition2 = testNet.AddTransition("TestTransition2", incomingPlace: testPlace2, outgoingPlace: testPlace3);

            testNet.RemoveNodeAndConnections(testPlace2);

            Assert.AreEqual(0, testTransition1.OutgoingPlaces.Count);
            Assert.AreEqual(0, testTransition2.IncomingPlaces.Count);
            Assert.IsFalse(testNet.Places.Contains(testPlace2));

            testNet.RemoveNodeAndConnections(testTransition2);

            Assert.AreEqual(0, testPlace3.IncomingTransitions.Count);
        }
        public void RemoveNodeTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            Transition testTransition2 = testNet.AddTransition("TestTransition2");
            Place testPlace1 = testNet.AddPlace("TestPlace1");
            Place testPlace2 = testNet.AddPlace("TestPlace2");

            testNet.RemoveNode(testTransition1);
            testNet.RemoveNode(testPlace1);

            Assert.AreEqual(1, testNet.Transitions.Count);
            Assert.AreEqual(1, testNet.Places.Count);
            Assert.AreEqual(testTransition2, testNet.Transitions.First());
            Assert.AreEqual(testPlace2, testNet.Places.First());
        }
        public void CountLoopsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            testNet.AddTransition("TestTransition2");
            Transition testTransition3 = testNet.AddTransition("TestTransition3");
            testNet.AddTransition("TestTransition4");
            testTransition1.IsLoop = true;
            testTransition3.IsLoop = true;

            int result = testNet.CountLoops();

            Assert.AreEqual(2, result);
        }
        public void GetPlaceByNameTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace = testNet.AddPlace("TestPlace", 2);

            Place theSamePlace = testNet.GetPlaceByName("TestPlace");

            Assert.AreEqual(theSamePlace, testPlace);
        }
        public void GetSourcesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            Transition testTransition2 = testNet.AddTransition("TestTransition2");
            testTransition2.AddIncomingPlace(new Place());
            Place testPlace1 = testNet.AddPlace("TestPlace1");
            Place testPlace2 = testNet.AddPlace("TestPlace2");
            testPlace2.AppendIncomingTransition(testTransition1);

            List<Node> list = testNet.GetSources();

            Assert.IsTrue(list.Contains(testTransition1));
            Assert.IsTrue(list.Contains(testPlace1));
            Assert.AreEqual(2, list.Count);
        }
        public void PetriNetTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Assert.IsNotNull(testNet.Places);
            Assert.IsNotNull(testNet.Transitions);
            Assert.AreEqual("TestNet", testNet.Name);
        }
        public void IsOfKindTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Assert.AreEqual("PetriNet", testNet.IsOfKind());
        }
        public void CountTransitionsWithoutANDsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            testNet.AddTransition("TestTransition1");
            testNet.AddTransition("AND");
            testNet.AddTransition();
            testNet.AddTransition("TestTransition4");

            int result = testNet.CountTransitionsWithoutANDs();

            Assert.AreEqual(2, result);
        }
예제 #47
0
        public void IsOfKindTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");

            Assert.AreEqual("PetriNet", testNet.IsOfKind());
        }
        public void ConvertToDotTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place start = testNet.AddPlace("Start");
            Place midLeft1 = testNet.AddPlace("MidLeft1");
            Place midLeft2 = testNet.AddPlace("MidLeft2");
            Place midLeft3 = testNet.AddPlace("MidLeft3");
            Place midRight1 = testNet.AddPlace("MidRight1");
            Place midRight2 = testNet.AddPlace("MidRight2");
            Place midRight3 = testNet.AddPlace("MidRight3");
            Place end = testNet.AddPlace("End");
            testNet.AddTransition("Left", incomingPlace: start, outgoingPlaces: new List<Place> { midLeft1, midLeft2, midLeft3 });
            testNet.AddTransition("TestTransition", new List<Place> { midLeft1, midLeft2, midLeft3 }, new List<Place> { midRight1, midRight2, midRight3 });
            testNet.AddTransition("Right", new List<Place> { midRight1, midRight2, midRight3 }, outgoingPlace: end);

            String dotCode = testNet.ConvertToDot();

            Assert.IsNotNull(dotCode);
        }
        public void GetPlacesWithoutFollowersTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1", 2);
            Place testPlace2 = testNet.AddPlace("TestPlace2", 3);
            Place testPlace3 = testNet.AddPlace("TestPlace3", 4);
            testPlace1.AppendOutgoingTransition(new Transition());
            testPlace3.AppendOutgoingTransition(new Transition());

            List<Place> testlist = testNet.GetPlacesWithoutFollowers();

            Assert.AreEqual(testlist.First(), testPlace2);
        }
        public void FindTransitionTestNotFound()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place tempPlaceIn = testNet.AddPlace("place_1");
            Place tempPlaceOut = testNet.AddPlace("place_2");
            testNet.AddTransition("transition_1", incomingPlace: tempPlaceIn, outgoingPlace: tempPlaceOut);

            Assert.IsNull(testNet.FindTransition("not in the list"));
        }
        public void MergeWithPetriNetTest()
        {
            Model.PetriNet.PetriNet testNet1 = new Model.PetriNet.PetriNet("TestNet");
            Place start1 = testNet1.AddPlace("Start");
            Place end1 = testNet1.AddPlace("End");
            Transition trans1 = testNet1.AddTransition("Trans1", incomingPlace: start1, outgoingPlace: end1);

            Model.PetriNet.PetriNet testNet2 = new Model.PetriNet.PetriNet("TestNet");
            Place start2 = testNet2.AddPlace("Start");
            Place end2 = testNet2.AddPlace("End");
            Transition trans2 = testNet2.AddTransition("Trans2", incomingPlace: start2, outgoingPlace: end2);

            testNet1.MergeWithPetriNet(testNet2, trans1);

            Assert.AreEqual(4, testNet1.Places.Count);
            Assert.AreEqual(2, testNet1.Transitions.Count);
            Assert.AreEqual(2, trans1.OutgoingPlaces.Count);
            Assert.AreEqual(trans2, trans1.OutgoingPlaces[1].OutgoingTransitions[0]);
        }
        public void GetNodesTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition = testNet.AddTransition("TestTransition");
            Place testPlace = testNet.AddPlace("TestPlace");

            List<Node> list = testNet.Nodes;

            Assert.IsTrue(list.Contains(testTransition));
            Assert.IsTrue(list.Contains(testPlace));
            Assert.AreEqual(2, list.Count);
        }
        public void GetTransitionsWithoutFollowersIgnoreLoopsTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            Transition testTransition2 = testNet.AddTransition("TestTransition2");
            Transition testTransition3 = testNet.AddTransition("TestTransition3");
            testNet.AddTransition("TestTransition4");
            testTransition1.AddOutgoingPlace(new Place());
            testTransition2.AddOutgoingPlace(new Place());
            Place testPlace = new Place();
            testTransition3.AddOutgoingPlace(testPlace);
            testPlace.AppendOutgoingTransition(new Transition("", isLoop: true));

            List<Transition> testList = testNet.GetTransitionsWithoutFollowersIgnoreLoops();

            Assert.IsNotNull(testList);
            Assert.AreEqual(testTransition3, testList.First());
            Assert.AreEqual(2, testList.Count);
        }
        public void GetTransitionsWithoutFollowersTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition1 = testNet.AddTransition("TestTransition1");
            Transition testTransition2 = testNet.AddTransition("TestTransition2");
            Transition testTransition3 = testNet.AddTransition("TestTransition3");
            testNet.AddTransition("TestTransition4");
            testTransition1.AddOutgoingPlace(new Place());
            testTransition2.AddOutgoingPlace(new Place());

            List<Transition> testList = testNet.GetTransitionsWithoutFollowers();

            Assert.IsNotNull(testList);
            Assert.AreEqual(testTransition3, testList.First());
            Assert.AreEqual(2, testList.Count);
        }
        public void AddTransitionTestSinglePlaces()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Place testPlace1 = testNet.AddPlace("TestPlace1", 2);
            Place testPlace2 = testNet.AddPlace("TestPlace2", 3);

            Transition testTransition = testNet.AddTransition("TestTransition", incomingPlace: testPlace1, outgoingPlace: testPlace2);

            Assert.AreEqual(testPlace1, testTransition.IncomingPlaces.First());
            Assert.AreEqual(testPlace2, testTransition.OutgoingPlaces.First());
        }
        public void FindTransitionTest()
        {
            Model.PetriNet.PetriNet testNet = new Model.PetriNet.PetriNet("TestNet");
            Transition testTransition = testNet.AddTransition("TestTransition");

            Transition transition2 = testNet.FindTransition("TestTransition");

            Assert.AreEqual(transition2, testTransition);
        }