示例#1
0
        public static async Task WhileMAsync1CancelTest()
        {
            var cts = new CancellationTokenSource();

            cts.Cancel();
            var xs  = Task.FromResult(new Finite <bool>(false).ToAsyncMonad());
            var ret = (await xs.WhileMAsync(() => Task.FromResult(new Finite <int>(2).ToAsyncMonad()), cts.Token)).DownF();

            Assert.Empty(ret.Value);

            cts = new CancellationTokenSource();
            cts.CancelAfter(1250);
            var body = new Finite <int>(2, 4);

            xs  = Task.FromResult(new Finite <bool>(true, 2).ToAsyncMonad());
            ret = (await xs.WhileMAsync(() => Task.FromResult(body.ToAsyncMonad()), cts.Token)).DownF();

            Assert.Equal(new int[] { 2, 2 }, ret.Value);

            cts = new CancellationTokenSource();
            cts.CancelAfter(1250);
            body = new Finite <int>(2, 1);
            xs   = Task.FromResult(new Finite <bool>(true, 3).ToAsyncMonad());
            ret  = (await xs.WhileMAsync(() => Task.FromResult(body.ToAsyncMonad()), cts.Token)).DownF();

            Assert.Equal(new int[] { 2, 0 }, ret.Value);
        }
示例#2
0
        public static async Task WhileMAsync1Test()
        {
            var xs  = Task.FromResult(new Finite <bool>(false).ToAsyncMonad());
            var ret = (await xs.WhileMAsync(() => Task.FromResult(new Finite <int>(2).ToAsyncMonad()))).DownF();

            Assert.Empty(ret.Value);

            var body = new Finite <int>(2, 4);

            xs  = Task.FromResult(new Finite <bool>(true, 2).ToAsyncMonad());
            ret = (await xs.WhileMAsync(() => Task.FromResult(body.ToAsyncMonad()))).DownF();

            Assert.Equal(new int[] { 2, 2 }, ret.Value);

            body = new Finite <int>(2, 1);
            xs   = Task.FromResult(new Finite <bool>(true, 3).ToAsyncMonad());
            ret  = (await xs.WhileMAsync(() => Task.FromResult(body.ToAsyncMonad()))).DownF();

            Assert.Equal(new int[] { 2, 0, 0 }, ret.Value);
        }