public void TestAp() { var tasks = 0; var strategy = new SpyTaskStrategy(() => ++ tasks); var list = new List <int>(); var expected = new List <int> { 3, 2, 1 }; var ff = Future.Now <Func <int, Func <int, Func <int, int> > > >(a => b => c => a + b + c); var fa = Future.Func(() => { Thread.Sleep(10); list.Add(1); return(1); }, strategy); var fb = Future.Func(() => { Thread.Sleep(5); list.Add(2); return(2); }, strategy); var fc = Future.Func(() => { Thread.Sleep(0); list.Add(3); return(3); }, strategy); Assert.AreEqual(6, Future.Strategy(ff, strategy).Ap(fa).Ap(fb).Ap(fc).Run()); CollectionAssert.AreEqual(expected, list); Assert.AreEqual(4, tasks); }
public void TestOrder() { var list = new List <int>(); var expected = new List <int> { 1, 2 }; var fa = Future.Func(() => { Thread.Sleep(10); list.Add(1); return(1); }); var fb = Future.Func(() => { list.Add(2); return(2); }); CollectionAssert.AreEqual(expected, fa.Bind(a => fb.Bind(b => Future.Now(new List <int> { a, b }))).Run()); CollectionAssert.AreEqual(expected, list); }