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