Пример #1
0
        public void TestLiftGlitch()
        {
            var               a  = new BehaviorSink <int>(1);
            Behavior <int>    a3 = a.Map <int>(x => x * 3);
            Behavior <int>    a5 = a.Map <int>(x => x * 5);
            Behavior <String> b  = Behavior <int> .Lift((x, y) => x + " " + y, a3, a5);

            var      @out = new List <String>();
            Listener l    = b.Value().Listen(x => { @out.Add(x); });

            a.Send(2);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { "3 5", "6 10" }, @out);
        }
Пример #2
0
        public void TestMapB()
        {
            var      b    = new BehaviorSink <int>(6);
            var      @out = new List <String>();
            Listener l    = b.Map(x => x.ToString())
                            .Value().Listen(x => { @out.Add(x); });

            b.Send(8);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { "6", "8" }, @out);
        }
Пример #3
0
 public void TestLiftGlitch()
 {
   var a = new BehaviorSink<int>(1);
   Behavior<int> a3 = a.Map<int>(x => x * 3);
   Behavior<int> a5 = a.Map<int>(x => x * 5);
   Behavior<String> b = Behavior<int>.Lift((x, y) => x + " " + y, a3, a5);
   var @out = new List<String>();
   Listener l = b.Value().Listen(x => { @out.Add(x); });
   a.Send(2);
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { "3 5", "6 10" }, @out);
 }
Пример #4
0
        public void FunctionalBehaviorLoopWithCaptures()
        {
            BehaviorSink <int> s = Behavior.CreateSink(0);

            (Behavior <int> result, Behavior <int> s2) = Behavior.Loop <int>()
                                                         .WithCaptures(l => (Behavior: Operational.Updates(s).Snapshot(l, (n, o) => n + o).Hold(0).AsBehavior(), Captures: s.Map(v => 2 * v)));

            List <int> @out = new List <int>();
            List <int> out2 = new List <int>();

            using (Transaction.Run(() => Operational.Value(result).Listen(@out.Add)))
                using (Transaction.Run(() => Operational.Value(s2).Listen(out2.Add)))

                {
                    s.Send(1);
                    s.Send(2);
                    s.Send(3);
                }

            CollectionAssert.AreEqual(new[] { 0, 1, 3, 6 }, @out);
            CollectionAssert.AreEqual(new[] { 0, 2, 4, 6 }, out2);
        }
Пример #5
0
 public void TestMapBLateListen()
 {
   var b = new BehaviorSink<int>(6);
   var @out = new List<String>();
   Behavior<String> bm = b.Map(x => x.ToString());
   b.Send(2);
   Listener l = bm.Value().Listen(x => { @out.Add(x); });
   b.Send(8);
   l.Unlisten();
   CollectionAssert.AreEqual(new[] { "2", "8" }, @out);
 }