Esempio n. 1
0
        public void TwoStepFlowArrives()
        {
            var testModel = new IntFlowModel();
            var source    = new IntFlowSource();
            var direct1   = new IntFlowInToOut();
            var direct2   = new IntFlowInToOut();
            var sink      = new IntFlowSink();

            testModel.Components = new IntFlowComponentCollection(source, direct1, direct2, sink);

            source.SendForward      = testModel.CreateForward;
            source.ReceivedBackward = testModel.PrintReceivedBackward;
            sink.SendBackward       = testModel.CreateBackward;
            sink.ReceivedForward    = testModel.PrintReceivedForward;
            testModel.Combinator.ConnectOutWithIn(source, direct1);
            testModel.Combinator.ConnectOutWithIn(direct1, direct2);
            testModel.Combinator.ConnectOutWithIn(direct2, sink);
            testModel.Combinator.CommitFlow();

            var simulator = new Simulator(testModel);             //Important: Call after all objects have been created

            simulator.SimulateStep();

            var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
            var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
            var sourceAfterStep         = (IntFlowSource)flowComponentsAfterStep[0];
            var sinkAfterStep           = (IntFlowSink)flowComponentsAfterStep[3];

            sinkAfterStep.Incoming.Forward.Should().Be(7);
            sourceAfterStep.Outgoing.Backward.Should().Be(1);
        }
Esempio n. 2
0
		public void SimpleFlowArrives()
		{
			var testModel = new IntFlowModel();
			var source = new IntFlowSource();
			var direct = new IntFlowInToOut();
			var sink = new IntFlowSink();
			testModel.Components = new IntFlowComponentCollection(source, direct, sink);

			source.SendForward = testModel.CreateForward;
			source.ReceivedBackward = testModel.PrintReceivedBackward;
			sink.SendBackward = testModel.CreateBackward;
			sink.ReceivedForward = testModel.PrintReceivedForward;
			testModel.Combinator.ConnectOutWithIn(source, direct);
			testModel.Combinator.ConnectOutWithIn(direct, sink);
			testModel.Combinator.CommitFlow();

			var simulator = new Simulator(testModel); //Important: Call after all objects have been created
			simulator.SimulateStep();

			var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
			var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
			var sourceAfterStep = (IntFlowSource)flowComponentsAfterStep[0];
			var directAfterStep = (IntFlowInToOut)flowComponentsAfterStep[1];
			var sinkAfterStep = (IntFlowSink)flowComponentsAfterStep[2];
			sourceAfterStep.Outgoing.Forward.Should().Be((Int)7);
			directAfterStep.Incoming.Forward.Should().Be((Int)7);
			directAfterStep.Outgoing.Forward.Should().Be((Int)7);
			sinkAfterStep.Incoming.Forward.Should().Be((Int)7);
			sinkAfterStep.Incoming.Backward.Should().Be(1);
			directAfterStep.Outgoing.Backward.Should().Be(1);
			directAfterStep.Incoming.Backward.Should().Be(1);
			sourceAfterStep.Outgoing.Backward.Should().Be(1);
		}
Esempio n. 3
0
        public void CompositeFlowArrives()
        {
            var testModel         = new IntFlowModel();
            var source            = new IntFlowSource();
            var composite         = new IntFlowComposite();
            var firstInComposite  = new IntFlowInToOut();
            var secondInComposite = new IntFlowInToOut();
            var sink = new IntFlowSink();

            testModel.Components = new IntFlowComponentCollection(source, composite, firstInComposite, secondInComposite, sink);

            source.SendForward      = testModel.CreateForward;
            source.ReceivedBackward = testModel.PrintReceivedBackward;
            sink.SendBackward       = testModel.CreateBackward;
            sink.ReceivedForward    = testModel.PrintReceivedForward;
            testModel.Combinator.ConnectOutWithIn(source, composite);
            testModel.Combinator.ConnectInWithIn(composite, firstInComposite);
            testModel.Combinator.ConnectOutWithIn(firstInComposite, secondInComposite);
            testModel.Combinator.ConnectOutWithOut(secondInComposite, composite);
            testModel.Combinator.ConnectOutWithIn(composite, sink);
            testModel.Combinator.CommitFlow();

            var simulator = new Simulator(testModel);             //Important: Call after all objects have been created

            simulator.SimulateStep();

            var flowCombinatorAfterStep   = (IntFlowCombinator)simulator.Model.Roots[0];
            var flowComponentsAfterStep   = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
            var sourceAfterStep           = (IntFlowSource)flowComponentsAfterStep[0];
            var compositeAfterStep        = (IntFlowComposite)flowComponentsAfterStep[1];
            var firstInCompositeAfterStep = (IntFlowInToOut)flowComponentsAfterStep[2];
            var sinkAfterStep             = (IntFlowSink)flowComponentsAfterStep[4];

            sourceAfterStep.Outgoing.Forward.Should().Be((Int)7);
            compositeAfterStep.Incoming.Forward.Should().Be((Int)7);
            compositeAfterStep.FlowIn.Outgoing.Forward.Should().Be((Int)7);
            firstInCompositeAfterStep.Incoming.Forward.Should().Be((Int)7);
            compositeAfterStep.FlowOut.Outgoing.Forward.Should().Be((Int)7);
            compositeAfterStep.Outgoing.Forward.Should().Be((Int)7);
            sinkAfterStep.Incoming.Forward.Should().Be((Int)7);
            sourceAfterStep.Outgoing.Backward.Should().Be(1);
        }
Esempio n. 4
0
        public void MergeFlowWorksWithComposite()
        {
            var testModel     = new IntFlowModel();
            var sourceOutside = new IntFlowSource();
            var sourceInside  = new IntFlowSource();
            var composite     = new IntFlowComposite();
            var way1Direct    = new IntFlowInToOut();
            var way2Direct    = new IntFlowInToOut();
            var sink          = new IntFlowSink();

            testModel.Components = new IntFlowComponentCollection(sourceOutside, sourceInside, composite, way1Direct, way2Direct, sink);

            sourceOutside.SendForward      = testModel.CreateForward;
            sourceOutside.ReceivedBackward = testModel.PrintReceivedBackward;
            sourceInside.SendForward       = testModel.CreateForward;
            sourceInside.ReceivedBackward  = testModel.PrintReceivedBackward;
            sink.SendBackward    = testModel.CreateBackward;
            sink.ReceivedForward = testModel.PrintReceivedForward;
            testModel.Combinator.ConnectOutWithIn(sourceOutside, composite);
            testModel.Combinator.ConnectInWithIn(composite, way1Direct);
            testModel.Combinator.ConnectOutWithIn(sourceInside, way2Direct);
            testModel.Combinator.ConnectOutsWithOut(new IFlowComponentUniqueOutgoing <Int, Int>[] { way1Direct, way2Direct }, composite);
            testModel.Combinator.ConnectOutWithIn(composite, sink);
            testModel.Combinator.CommitFlow();

            var simulator = new Simulator(testModel);             //Important: Call after all objects have been created

            simulator.SimulateStep();

            var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
            var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
            var sourceInsideAfterStep   = (IntFlowSource)flowComponentsAfterStep[1];
            var sourceOutsideAfterStep  = (IntFlowSource)flowComponentsAfterStep[0];
            var sinkAfterStep           = (IntFlowSink)flowComponentsAfterStep[5];

            sinkAfterStep.Incoming.Forward.Should().Be(7);
            sourceOutsideAfterStep.Outgoing.Backward.Should().Be(1);
            sourceInsideAfterStep.Outgoing.Backward.Should().Be(1);
        }
Esempio n. 5
0
        public void SplitFlowWorks()
        {
            var testModel  = new IntFlowModel();
            var source     = new IntFlowSource();
            var way1Direct = new IntFlowInToOut();
            var way2Direct = new IntFlowInToOut();
            var way1Sink   = new IntFlowSink();
            var way2Sink   = new IntFlowSink();

            testModel.Components = new IntFlowComponentCollection(source, way1Direct, way2Direct, way1Sink, way2Sink);

            source.SendForward       = testModel.CreateForward;
            source.ReceivedBackward  = testModel.PrintReceivedBackward;
            way1Sink.SendBackward    = testModel.CreateBackward;
            way1Sink.ReceivedForward = testModel.PrintReceivedForward;
            way2Sink.SendBackward    = testModel.CreateBackward;
            way2Sink.ReceivedForward = testModel.PrintReceivedForward;
            testModel.Combinator.ConnectOutWithIns(source, new IFlowComponentUniqueIncoming <Int, Int>[] { way1Direct, way2Direct });
            testModel.Combinator.ConnectOutWithIn(way1Direct, way1Sink);
            testModel.Combinator.ConnectOutWithIn(way2Direct, way2Sink);
            testModel.Combinator.CommitFlow();

            var simulator = new Simulator(testModel);             //Important: Call after all objects have been created

            simulator.SimulateStep();

            var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
            var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
            var sourceAfterStep         = (IntFlowSource)flowComponentsAfterStep[0];
            var sink1AfterStep          = (IntFlowSink)flowComponentsAfterStep[3];
            var sink2AfterStep          = (IntFlowSink)flowComponentsAfterStep[4];

            sink1AfterStep.Incoming.Forward.Should().Be(7);
            sink2AfterStep.Incoming.Forward.Should().Be(7);
            sourceAfterStep.Outgoing.Backward.Should().Be(1);
        }
Esempio n. 6
0
		public void MergeFlowWorksWithComposite()
		{
			var testModel = new IntFlowModel();
			var sourceOutside = new IntFlowSource();
			var sourceInside = new IntFlowSource();
			var composite = new IntFlowComposite();
			var way1Direct = new IntFlowInToOut();
			var way2Direct = new IntFlowInToOut();
			var sink = new IntFlowSink();
			testModel.Components = new IntFlowComponentCollection(sourceOutside, sourceInside, composite, way1Direct, way2Direct, sink);

			sourceOutside.SendForward = testModel.CreateForward;
			sourceOutside.ReceivedBackward = testModel.PrintReceivedBackward;
			sourceInside.SendForward = testModel.CreateForward;
			sourceInside.ReceivedBackward = testModel.PrintReceivedBackward;
			sink.SendBackward = testModel.CreateBackward;
			sink.ReceivedForward = testModel.PrintReceivedForward;
			testModel.Combinator.ConnectOutWithIn(sourceOutside, composite);
			testModel.Combinator.ConnectInWithIn(composite, way1Direct);
			testModel.Combinator.ConnectOutWithIn(sourceInside, way2Direct);
			testModel.Combinator.ConnectOutsWithOut(new IFlowComponentUniqueOutgoing<Int, Int>[] { way1Direct, way2Direct }, composite);
			testModel.Combinator.ConnectOutWithIn(composite, sink);
			testModel.Combinator.CommitFlow();

			var simulator = new Simulator(testModel); //Important: Call after all objects have been created
			simulator.SimulateStep();

			var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
			var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
			var sourceInsideAfterStep = (IntFlowSource)flowComponentsAfterStep[1];
			var sourceOutsideAfterStep = (IntFlowSource)flowComponentsAfterStep[0];
			var sinkAfterStep = (IntFlowSink)flowComponentsAfterStep[5];
			sinkAfterStep.Incoming.Forward.Should().Be(7);
			sourceOutsideAfterStep.Outgoing.Backward.Should().Be(1);
			sourceInsideAfterStep.Outgoing.Backward.Should().Be(1);
		}
Esempio n. 7
0
		public void SplitFlowWorks()
		{
			var testModel = new IntFlowModel();
			var source = new IntFlowSource();
			var way1Direct = new IntFlowInToOut();
			var way2Direct = new IntFlowInToOut();
			var way1Sink = new IntFlowSink();
			var way2Sink = new IntFlowSink();
			testModel.Components = new IntFlowComponentCollection(source, way1Direct, way2Direct, way1Sink, way2Sink);

			source.SendForward = testModel.CreateForward;
			source.ReceivedBackward = testModel.PrintReceivedBackward;
			way1Sink.SendBackward = testModel.CreateBackward;
			way1Sink.ReceivedForward = testModel.PrintReceivedForward;
			way2Sink.SendBackward = testModel.CreateBackward;
			way2Sink.ReceivedForward = testModel.PrintReceivedForward;
			testModel.Combinator.ConnectOutWithIns(source, new IFlowComponentUniqueIncoming<Int, Int>[] { way1Direct, way2Direct });
			testModel.Combinator.ConnectOutWithIn(way1Direct, way1Sink);
			testModel.Combinator.ConnectOutWithIn(way2Direct, way2Sink);
			testModel.Combinator.CommitFlow();

			var simulator = new Simulator(testModel); //Important: Call after all objects have been created
			simulator.SimulateStep();

			var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0];
			var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components;
			var sourceAfterStep = (IntFlowSource)flowComponentsAfterStep[0];
			var sink1AfterStep = (IntFlowSink)flowComponentsAfterStep[3];
			var sink2AfterStep = (IntFlowSink)flowComponentsAfterStep[4];
			sink1AfterStep.Incoming.Forward.Should().Be(7);
			sink2AfterStep.Incoming.Forward.Should().Be(7);
			sourceAfterStep.Outgoing.Backward.Should().Be(1);
		}