Exemplo n.º 1
0
        public void TestLift()
        {
            DiscreteCellSink <int>  c1   = DiscreteCell.CreateSink(1);
            DiscreteCellSink <long> c2   = DiscreteCell.CreateSink(5L);
            List <string>           @out = new List <string>();
            IListener l = c1.Lift(c2, (x, y) => x + " " + y).Listen(@out.Add);

            c1.Send(12);
            c2.Send(6L);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { "1 5", "12 5", "12 6" }, @out);
        }
Exemplo n.º 2
0
        public void TestLiftSimultaneousUpdates()
        {
            List <int>             @out     = new List <int>();
            DiscreteCellSink <int> cellSink = DiscreteCell.CreateSink(1);
            DiscreteCell <int>     cell     = cellSink.Map(v => 2 * v);
            IListener l = cellSink.Lift(cell, (x, y) => x + y).Updates.Listen(@out.Add);

            cellSink.Send(2);
            cellSink.Send(7);

            l.Unlisten();

            CollectionAssert.AreEqual(new[] { 6, 21 }, @out);
        }
Exemplo n.º 3
0
        public void TestLiftFromSimultaneous()
        {
            ValueTuple <DiscreteCellSink <int>, DiscreteCellSink <int> > t = Transaction.Run(() =>
            {
                DiscreteCellSink <int> localC1 = DiscreteCell.CreateSink(3);
                DiscreteCellSink <int> localC2 = DiscreteCell.CreateSink(5);
                localC2.Send(7);
                return(ValueTuple.Create(localC1, localC2));
            });
            DiscreteCellSink <int> c1   = t.Item1;
            DiscreteCellSink <int> c2   = t.Item2;
            List <int>             @out = new List <int>();
            IListener l = c1.Lift(c2, (x, y) => x + y).Listen(@out.Add);

            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 10 }, @out);
        }
Exemplo n.º 4
0
            public void Run()
            {
                DiscreteCellSink <double> mainClock = new DiscreteCellSink <double>(0.0);
                StreamSink <Unit>         sPause    = new StreamSink <Unit>();
                StreamSink <Unit>         sResume   = new StreamSink <Unit>();
                DiscreteCell <double>     gameClock = PausableClock(sPause, sResume, mainClock);
                IListener l = mainClock.Lift(gameClock, (m, g) => "main=" + m + " game=" + g).Listen(Console.WriteLine);

                mainClock.Send(1.0);
                mainClock.Send(2.0);
                mainClock.Send(3.0);
                sPause.Send(Unit.Value);
                mainClock.Send(4.0);
                mainClock.Send(5.0);
                mainClock.Send(6.0);
                sResume.Send(Unit.Value);
                mainClock.Send(7.0);
                l.Unlisten();
            }