Beispiel #1
0
        public void RefinementFramework()
        {
            FileInfo            model     = new FileInfo(@"..\..\..\TorXakisDotNetAdapter.Models\Models\Reference.txs");
            RefinementFramework framework = new RefinementFramework(model);

            Assert.AreEqual(model, framework.Connector.Model.File);

            TransitionSystem system1 = CreateTransitionSystem1();

            framework.AddSystem(system1);
            Assert.AreEqual(system1, framework.Systems.ElementAt(0));

            TransitionSystem system2 = CreateTransitionSystem2();

            framework.AddSystem(system2);
            Assert.AreEqual(system2, framework.Systems.ElementAt(1));

            Console.WriteLine(framework);

            // Trigger a reactive transition, which should activate a proactive one next.
            if (true)
            {
                NewItem modelInput = new NewItem()
                {
                    Id = 1,
                };
                Console.WriteLine("Using model input: " + modelInput);
                HashSet <Tuple <TransitionSystem, ReactiveTransition> > reactives = framework.PossibleReactiveTransitions(modelInput);
                Console.WriteLine("Possible reactives transitions: " + string.Join(", ", reactives.Select(x => x.Item1.ModelAction.Name + ": " + x.Item2).ToArray()));
                Assert.AreEqual(1, reactives.Count);

                framework.HandleModelInput(modelInput);
                Console.WriteLine(framework);
                Assert.AreEqual(system1.States.ElementAt(0), system1.CurrentState);
            }

            // Trigger a reactive transition, which should activate a proactive one next.
            if (true)
            {
                ItemEventArgsNew systemEvent = new ItemEventArgsNew()
                {
                    GUID       = guids[0],
                    SystemName = systemNames[0],
                    Position   = positions[0],
                    Rotation   = rotations[0],
                    ModelGroup = modelGroups[0],
                    Model      = models[0],
                };
                Console.WriteLine("Using system event: " + systemEvent);
                HashSet <Tuple <TransitionSystem, ReactiveTransition> > reactives = framework.PossibleReactiveTransitions(systemEvent);
                Console.WriteLine("Possible reactives transitions: " + string.Join(", ", reactives.Select(x => x.Item1.ModelAction.Name + ": " + x.Item2).ToArray()));
                Assert.AreEqual(1, reactives.Count);

                framework.HandleSystemEvent(systemEvent);
                Console.WriteLine(framework);
                Assert.AreEqual(system2.States.ElementAt(0), system2.CurrentState);
            }
        }
Beispiel #2
0
        public void TransitionSystem2()
        {
            TransitionSystem system = CreateTransitionSystem2();

            Console.WriteLine(system);

            // Determine possible reactive transitions.
            ItemEventArgsNew systemEvent = new ItemEventArgsNew()
            {
                GUID       = guids[0],
                SystemName = systemNames[0],
                Position   = positions[0],
                Rotation   = rotations[0],
                ModelGroup = modelGroups[0],
                Model      = models[0],
            };

            Console.WriteLine("Using system event: " + systemEvent);
            HashSet <ReactiveTransition> reactives = system.PossibleReactiveTransitions(systemEvent);

            Console.WriteLine("Possible reactive transitions: " + string.Join(", ", reactives.Select(x => x.ToString()).ToArray()));
            Assert.AreEqual(1, reactives.Count);
            Assert.AreEqual(system.Transitions.ElementAt(0), reactives.First());

            // Execute and check reactive transition.
            system.ExecuteReactiveTransition(systemEvent, reactives.First());
            Console.WriteLine(system);
            Assert.AreEqual(system.States.ElementAt(1), system.CurrentState);

            // Determine possible proactive transitions.
            HashSet <ProactiveTransition> proactives = system.PossibleProactiveTransitions();

            Console.WriteLine("Possible proactive transitions: " + string.Join(", ", proactives.Select(x => x.ToString()).ToArray()));
            Assert.AreEqual(1, proactives.Count);
            Assert.AreEqual(system.Transitions.ElementAt(1), proactives.First());

            // Execute and check proactive transition.
            IAction generatedAction = system.ExecuteProactiveTransition(proactives.First());

            Console.WriteLine("Generated action: " + generatedAction);
            Assert.AreEqual(typeof(NewItem), generatedAction.GetType());
            Assert.AreEqual(1, (generatedAction as NewItem).Id);
            Console.WriteLine(system);
            Assert.AreEqual(system.States.ElementAt(0), system.CurrentState);
        }