예제 #1
0
 public void TestHold()
 {
   var e = new EventSink<int>();
   Behavior<int> b = e.Hold(0);
   var @out = new List<int>();
   Listener l = b.Updates().Listen(new Handler<int> { Run = x => @out.Add(x) });
   e.Send(2);
   e.Send(9);
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { 2, 9 }, @out.Select(x => (int)x));
 }
예제 #2
0
        public void TestHoldIsDelayed()
        {
            var            e    = new EventSink <int>();
            Behavior <int> h    = e.Hold(0);
            Event <String> pair = e.Snapshot(h, (a, b) => a + " " + b);
            var            @out = new List <String>();
            Listener       l    = pair.Listen(x => { @out.Add(x); });

            e.Send(2);
            e.Send(3);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { "2 0", "3 2" }, @out);
        }
예제 #3
0
        public void TestDelay()
        {
            var             e    = new EventSink <char>();
            Behavior <char> b    = e.Hold(' ');
            var             @out = new List <char>();
            Listener        l    = e.Delay().Snapshot(b).Listen(x => { @out.Add(x); });

            e.Send('C');
            e.Send('B');
            e.Send('A');
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 'C', 'B', 'A' }, @out);
        }
예제 #4
0
        public void TestHold()
        {
            var            e    = new EventSink <int>();
            Behavior <int> b    = e.Hold(0);
            var            @out = new List <int>();
            Listener       l    = b.Updates().Listen(new Handler <int> {
                Run = x => @out.Add(x)
            });

            e.Send(2);
            e.Send(9);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 2, 9 }, @out.Select(x => (int)x));
        }
예제 #5
0
        public void TestCollect()
        {
            var            ea   = new EventSink <int>();
            var            @out = new List <int>();
            Behavior <int> sum  = ea.Hold(100).Collect(
                (int)0,
                //(a,s) => new Tuple2(a+s, a+s)
                (a, s) => new Tuple <int, int>(a + s, a + s));
            Listener l = sum.Value().Listen(x => { @out.Add(x); });

            ea.Send(5);
            ea.Send(7);
            ea.Send(1);
            ea.Send(2);
            ea.Send(3);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 100, 105, 112, 113, 115, 118 }, @out);
        }
예제 #6
0
 public void TestCollect()
 {
   var ea = new EventSink<int>();
   var @out = new List<int>();
   Behavior<int> sum = ea.Hold(100).Collect(
     (int)0,
     //(a,s) => new Tuple2(a+s, a+s)
     (a, s) => new Tuple<int, int>(a + s, a + s));
   Listener l = sum.Value().Listen(x => { @out.Add(x); });
   ea.Send(5);
   ea.Send(7);
   ea.Send(1);
   ea.Send(2);
   ea.Send(3);
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { 100, 105, 112, 113, 115, 118 }, @out);
 }
예제 #7
0
 public void TestHoldIsDelayed()
 {
   var e = new EventSink<int>();
   Behavior<int> h = e.Hold(0);
   Event<String> pair = e.Snapshot(h, (a, b) => a + " " + b);
   var @out = new List<String>();
   Listener l = pair.Listen(x => { @out.Add(x); });
   e.Send(2);
   e.Send(3);
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { "2 0", "3 2" }, @out);
 }
예제 #8
0
 public void TestDelay()
 {
   var e = new EventSink<char>();
   Behavior<char> b = e.Hold(' ');
   var @out = new List<char>();
   Listener l = e.Delay().Snapshot(b).Listen(x => { @out.Add(x); });
   e.Send('C');
   e.Send('B');
   e.Send('A');
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { 'C', 'B', 'A' }, @out);
 }