Esempio n. 1
0
        static void Main(string[] args)
        {
            IEnumerable <MyClass> Objects = ParallelEnumerable.Repeat <MyClass>(new MyClass(), 2);

            PetriController <MyClass> pn = new PetriController <MyClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Synch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Synch, 0);

            pn.Run();
        }
Esempio n. 2
0
        public void GeneralTests()
        {
            //test1
            IEnumerable<TestClass> Objects = ParallelEnumerable.Repeat<TestClass>(new TestClass(), 2);

            PetriController<TestClass> pn = new PetriController<TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Synch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Synch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            //test2
            Objects = ParallelEnumerable.Repeat<TestClass>(new TestClass(), 2);

            pn = new PetriController<TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Asynch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Asynch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            //test3
            Objects = ParallelEnumerable.Repeat<TestClass>(new TestClass(), 2);

            pn = new PetriController<TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 3 && o.Word == "ddd", o => { }, o => { o.Number = 4; o.Word = "eee"; }, ExecutionMode.Synch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 4 && o.Word == "eee"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 4 && o.Word == "eee"));
        }
Esempio n. 3
0
        public void GeneralTests()
        {
            //test1
            IEnumerable <TestClass> Objects = ParallelEnumerable.Repeat <TestClass>(new TestClass(), 2);

            PetriController <TestClass> pn = new PetriController <TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Synch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Synch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            //test2
            Objects = ParallelEnumerable.Repeat <TestClass>(new TestClass(), 2);

            pn = new PetriController <TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Asynch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Asynch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 3 && o.Word == "ddd"));

            //test3
            Objects = ParallelEnumerable.Repeat <TestClass>(new TestClass(), 2);

            pn = new PetriController <TestClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Asynch, 0);
            pn.AddTransition(o => true, o => o.Number == 3 && o.Word == "ddd", o => { }, o => { o.Number = 4; o.Word = "eee"; }, ExecutionMode.Synch, 0);

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 4 && o.Word == "eee"));

            pn.Run();

            Assert.IsTrue(Objects.All(o => o.Number == 4 && o.Word == "eee"));
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            IEnumerable<MyClass> Objects = ParallelEnumerable.Repeat<MyClass>(new MyClass(), 2);

            PetriController<MyClass> pn = new PetriController<MyClass>();

            pn.SetReset(o => { o.Number = 0; o.Word = "aaa"; });

            pn.SetObjects(Objects.ToList());

            pn.AddTransition(o => true, o => o.Number == 0 && o.Word == "aaa", o => { }, o => { o.Number = 1; o.Word = "bbb"; }, ExecutionMode.Synch, 0);
            pn.AddTransition(o => true, o => o.Number == 1 && o.Word == "bbb", o => { }, o => { o.Number = 2; o.Word = "ccc"; }, ExecutionMode.Synch, 0);
            pn.AddGeneralTransition(o => true, o => o.Number == 2 && o.Word == "ccc", o => { }, o => { o.Number = 3; o.Word = "ddd"; }, ExecutionMode.Synch, 0);

            pn.Run();
        }