Exemple #1
0
 public void TestLift()
 {
     CellSink<int> b1 = new CellSink<int>(1);
     CellSink<long> b2 = new CellSink<long>(5L);
     List<string> @out = new List<string>();
     using (b1.Lift(b2, (x, y) => x + " " + y).Listen(@out.Add))
     {
         b1.Send(12);
         b2.Send(6L);
     }
     CollectionAssert.AreEqual(new[] { "1 5", "12 5", "12 6" }, @out);
 }
Exemple #2
0
        public void TestLift()
        {
            CellSink <int>  c1   = new CellSink <int>(1);
            CellSink <long> c2   = new CellSink <long>(5L);
            List <string>   @out = new List <string>();

            using (c1.Lift(c2, (x, y) => x + " " + y).Listen(@out.Add))
            {
                c1.Send(12);
                c2.Send(6L);
            }
            CollectionAssert.AreEqual(new[] { "1 5", "12 5", "12 6" }, @out);
        }
Exemple #3
0
        public void TestLiftSimultaneousUpdates()
        {
            List <int>     @out     = new List <int>();
            CellSink <int> cellSink = Cell.CreateSink(1);
            Cell <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);
        }
Exemple #4
0
        public void TestLiftFromSimultaneous()
        {
            Tuple <CellSink <int>, CellSink <int> > t = Transaction.Run(() =>
            {
                CellSink <int> localC1 = new CellSink <int>(3);
                CellSink <int> localC2 = new CellSink <int>(5);
                localC2.Send(7);
                return(Tuple.Create(localC1, localC2));
            });
            CellSink <int> c1   = t.Item1;
            CellSink <int> c2   = t.Item2;
            List <int>     @out = new List <int>();

            using (c1.Lift(c2, (x, y) => x + y).Listen(@out.Add))
            {
            }
            CollectionAssert.AreEqual(new[] { 10 }, @out);
        }
Exemple #5
0
            public void Run()
            {
                CellSink <double> mainClock = Cell.CreateSink(0.0);
                StreamSink <Unit> sPause    = Stream.CreateSink <Unit>();
                StreamSink <Unit> sResume   = Stream.CreateSink <Unit>();
                Cell <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();
            }
Exemple #6
0
            public void Run()
            {
                CellSink <Double> mainClock = new CellSink <double>(0.0);
                StreamSink <Unit> sPause    = new StreamSink <Unit>();
                StreamSink <Unit> sResume   = new StreamSink <Unit>();
                Cell <Double>     gameClock = PausableClock(sPause, sResume, mainClock);

                using (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);
                }
            }