Example #1
0
 public void TestHold()
 {
     StreamSink<int> e = new StreamSink<int>();
     Cell<int> b = e.Hold(0);
     List<int> @out = new List<int>();
     using (b.Listen(@out.Add))
     {
         e.Send(2);
         e.Send(9);
     }
     CollectionAssert.AreEqual(new[] { 0, 2, 9 }, @out);
 }
Example #2
0
        public void Test_Sample_TestCase()
        {
            StreamSink <char>   s = Stream.CreateSink <char>();
            DiscreteCell <char> c = s.Hold('a');
            char sample1          = c.Cell.Sample();

            s.Send('b');
            char sample2 = c.Cell.Sample();

            Assert.AreEqual('a', sample1);
            Assert.AreEqual('b', sample2);
        }
Example #3
0
        public void Test_SampleLazy_TestCase()
        {
            StreamSink <char>   s       = Stream.CreateSink <char>();
            DiscreteCell <char> c       = s.Hold('a');
            Lazy <char>         sample1 = c.Cell.SampleLazy();

            s.Send('b');
            Lazy <char> sample2 = c.Cell.SampleLazy();

            Assert.AreEqual('a', sample1.Value);
            Assert.AreEqual('b', sample2.Value);
        }
Example #4
0
        public void TestLazyCellCreation()
        {
            List <int>         @out = new List <int>();
            StreamSink <int>   s    = new StreamSink <int>();
            Cell <Cell <int> > c    = Cell.Constant(1).Map(_ => s.Hold(0));

            s.Send(1);
            c.SwitchC().Listen(@out.Add);
            s.Send(3);
            s.Send(5);
            CollectionAssert.AreEqual(new[] { 1, 3, 5 }, @out);
        }
        public void Test_Sample_TestCase()
        {
            StreamSink <char> s = new StreamSink <char>();
            Cell <char>       c = s.Hold('a');
            char sample1        = c.Sample();

            s.Send('b');
            char sample2 = c.Sample();

            Assert.AreEqual('a', sample1);
            Assert.AreEqual('b', sample2);
        }
Example #6
0
        public void TestHold()
        {
            StreamSink <int> s    = Stream.CreateSink <int>();
            Cell <int>       c    = s.Hold(0);
            List <int>       @out = new List <int>();
            IListener        l    = c.Listen(@out.Add);

            s.Send(2);
            s.Send(9);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 0, 2, 9 }, @out);
        }
Example #7
0
 public void TestHoldUpdates()
 {
     StreamSink<int> s = new StreamSink<int>();
     Cell<int> c = s.Hold(0);
     List<int> @out = new List<int>();
     using (Operational.Updates(c).Listen(@out.Add))
     {
         s.Send(2);
         s.Send(9);
     }
     CollectionAssert.AreEqual(new[] { 2, 9 }, @out);
 }
Example #8
0
        public void TestHoldUpdates()
        {
            StreamSink <int>   s    = Stream.CreateSink <int>();
            DiscreteCell <int> c    = s.Hold(0);
            List <int>         @out = new List <int>();
            IListener          l    = Operational.Updates(c.Cell).Listen(@out.Add);

            s.Send(2);
            s.Send(9);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 2, 9 }, @out);
        }
Example #9
0
        public void TestDefer()
        {
            StreamSink <char> s    = Stream.CreateSink <char>();
            Cell <char>       c    = s.Hold(' ');
            List <char>       @out = new List <char>();
            IListener         l    = Operational.Defer(s).Snapshot(c).Listen(@out.Add);

            s.Send('C');
            s.Send('B');
            s.Send('A');
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { 'C', 'B', 'A' }, @out);
        }
Example #10
0
 public void TestHoldIsDelayed()
 {
     StreamSink<int> s = new StreamSink<int>();
     Cell<int> h = s.Hold(0);
     Stream<string> pair = s.Snapshot(h, (a, b) => a + " " + b);
     List<string> @out = new List<string>();
     using (pair.Listen(@out.Add))
     {
         s.Send(2);
         s.Send(3);
     }
     CollectionAssert.AreEqual(new[] { "2 0", "3 2" }, @out);
 }
Example #11
0
        public void TestHold()
        {
            StreamSink <int> e    = new StreamSink <int>();
            Cell <int>       b    = e.Hold(0);
            List <int>       @out = new List <int>();

            using (b.Listen(@out.Add))
            {
                e.Send(2);
                e.Send(9);
            }
            CollectionAssert.AreEqual(new[] { 0, 2, 9 }, @out);
        }
Example #12
0
        public void TestHoldUpdates()
        {
            StreamSink <int> s    = new StreamSink <int>();
            Cell <int>       c    = s.Hold(0);
            List <int>       @out = new List <int>();

            using (Operational.Updates(c).Listen(@out.Add))
            {
                s.Send(2);
                s.Send(9);
            }
            CollectionAssert.AreEqual(new[] { 2, 9 }, @out);
        }
Example #13
0
        public void TestHoldImplicitDelay()
        {
            StreamSink <char> s    = Stream.CreateSink <char>();
            Cell <char>       c    = s.Hold(' ');
            List <char>       @out = new List <char>();
            IListener         l    = s.Snapshot(c).Listen(@out.Add);

            s.Send('C');
            s.Send('B');
            s.Send('A');
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { ' ', 'C', 'B' }, @out);
        }
Example #14
0
        public void TestHold()
        {
            StreamSink <char>   s    = Stream.CreateSink <char>();
            DiscreteCell <char> c    = s.Hold(' ');
            List <char>         @out = new List <char>();
            IListener           l    = c.Listen(@out.Add);

            s.Send('C');
            s.Send('B');
            s.Send('A');
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { ' ', 'C', 'B', 'A' }, @out);
        }
Example #15
0
        public void TestHoldIsDelayed()
        {
            StreamSink <int>   s    = Stream.CreateSink <int>();
            DiscreteCell <int> h    = s.Hold(0);
            Stream <string>    pair = s.Snapshot(h.Cell, (a, b) => a + " " + b);
            List <string>      @out = new List <string>();
            IListener          l    = pair.Listen(@out.Add);

            s.Send(2);
            s.Send(3);
            l.Unlisten();
            CollectionAssert.AreEqual(new[] { "2 0", "3 2" }, @out);
        }
Example #16
0
        public void TestHoldIsDelayed()
        {
            StreamSink <int> s    = new StreamSink <int>();
            Cell <int>       h    = s.Hold(0);
            Stream <string>  pair = s.Snapshot(h, (a, b) => a + " " + b);
            List <string>    @out = new List <string>();

            using (pair.Listen(@out.Add))
            {
                s.Send(2);
                s.Send(3);
            }
            CollectionAssert.AreEqual(new[] { "2 0", "3 2" }, @out);
        }
Example #17
0
        public void TestHold()
        {
            StreamSink <char> s    = new StreamSink <char>();
            Cell <char>       b    = s.Hold(' ');
            List <char>       @out = new List <char>();

            using (b.Listen(@out.Add))
            {
                s.Send('C');
                s.Send('B');
                s.Send('A');
            }
            CollectionAssert.AreEqual(new[] { ' ', 'C', 'B', 'A' }, @out);
        }
Example #18
0
        public void Post()
        {
            Cell <int> cell = Transaction.Run(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                return(s.Hold(1));
            });
            int value = 0;

            Transaction.Post(() => value = cell.Sample());

            Assert.AreEqual(2, value);
        }
Example #19
0
        public void TestHoldImplicitDelay()
        {
            StreamSink <char> s    = new StreamSink <char>();
            Cell <char>       c    = s.Hold(' ');
            List <char>       @out = new List <char>();

            using (s.Snapshot(c).Listen(@out.Add))
            {
                s.Send('C');
                s.Send('B');
                s.Send('A');
            }
            CollectionAssert.AreEqual(new[] { ' ', 'C', 'B' }, @out);
        }
Example #20
0
        public void TestDefer()
        {
            StreamSink <char> s    = new StreamSink <char>();
            Cell <char>       c    = s.Hold(' ');
            List <char>       @out = new List <char>();

            using (Operational.Defer(s).Snapshot(c).Listen(@out.Add))
            {
                s.Send('C');
                s.Send('B');
                s.Send('A');
            }
            CollectionAssert.AreEqual(new[] { 'C', 'B', 'A' }, @out);
        }
Example #21
0
        public void PostInTransaction()
        {
            int value = 0;

            Transaction.RunVoid(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                Cell <int> c = s.Hold(1);
                Transaction.Post(() => value = c.Sample());
                Assert.AreEqual(0, value);
            });

            Assert.AreEqual(2, value);
        }
Example #22
0
        public void PostInConstructTransaction()
        {
            int value = 0;

            Transaction.RunConstruct(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                DiscreteCell <int> c         = s.Hold(1);
                Transaction.Post(() => value = c.Cell.Sample());
                Assert.AreEqual(value, 0);
                return(Unit.Value);
            });

            Assert.AreEqual(value, 2);
        }
Example #23
0
        public void NestedPost()
        {
            Cell <int> cell = Transaction.Run(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                Transaction.Post(() =>
                {
                    s.Send(3);
                    Transaction.Post(() => s.Send(5));
                });
                Transaction.Post(() => s.Send(4));
                return(s.Hold(1));
            });

            Assert.AreEqual(5, cell.Sample());
        }
Example #24
0
        public void PostInNestedTransaction()
        {
            int value = 0;

            Transaction.RunVoid(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                Transaction.RunVoid(() =>
                {
                    DiscreteCell <int> c         = s.Hold(1);
                    Transaction.Post(() => value = c.Cell.Sample());
                });
                Assert.AreEqual(value, 0);
            });

            Assert.AreEqual(value, 2);
        }
Example #25
0
        public void PostInNestedConstructTransaction()
        {
            int value = 0;

            Transaction.Run(() =>
            {
                StreamSink <int> s = Stream.CreateSink <int>();
                s.Send(2);
                Transaction.RunVoid(() =>
                {
                    Cell <int> c = s.Hold(1);
                    Transaction.Post(() => value = c.Sample());
                });
                Assert.AreEqual(0, value);
                return(Unit.Value);
            });

            Assert.AreEqual(2, value);
        }
Example #26
0
        public void CellValuesWithPrevious()
        {
            StreamSink <int> s = Stream.CreateSink <int>();
            Cell <int>       c = s.Hold(0);
            List <(int Current, Maybe <int> Previous)> @out = new List <(int Current, Maybe <int> Previous)>();

            using (Transaction.Run(
                       () =>
            {
                Stream <(int Current, Maybe <int> Previous)> r = c.Updates()
                                                                 .Snapshot(c, (n, o) => (Current: n, Previous: Maybe.Some(o)))
                                                                 .OrElse(
                    Cell.ConstantLazy(c.SampleLazy()).Values().Map(v => (Current: v, Previous: Maybe <int> .None)));
                return(r.Listen(@out.Add));
            }))
            {
                s.Send(1);
                s.Send(2);
                s.Send(3);
                s.Send(4);
            }

            CollectionAssert.AreEqual(
                new[]
Example #27
0
 public void TestHold()
 {
     StreamSink<char> s = new StreamSink<char>();
     Cell<char> c = s.Hold(' ');
     List<char> @out = new List<char>();
     using (c.Listen(@out.Add))
     {
         s.Send('C');
         s.Send('B');
         s.Send('A');
     }
     CollectionAssert.AreEqual(new[] { ' ', 'C', 'B', 'A' }, @out);
 }
Example #28
0
 public void TestHoldImplicitDelay()
 {
     StreamSink<char> s = new StreamSink<char>();
     Cell<char> b = s.Hold(' ');
     List<char> @out = new List<char>();
     using (s.Snapshot(b).Listen(@out.Add))
     {
         s.Send('C');
         s.Send('B');
         s.Send('A');
     }
     CollectionAssert.AreEqual(new[] { ' ', 'C', 'B' }, @out);
 }
Example #29
0
 public void TestDefer()
 {
     StreamSink<char> s = new StreamSink<char>();
     Cell<char> b = s.Hold(' ');
     List<char> @out = new List<char>();
     using (Operational.Defer(s).Snapshot(b).Listen(@out.Add))
     {
         s.Send('C');
         s.Send('B');
         s.Send('A');
     }
     CollectionAssert.AreEqual(new[] { 'C', 'B', 'A' }, @out);
 }