예제 #1
0
        public static void LinqSelectTest()
        {
            var res =
                from x in Lst.Make(4, 3, 2)
                select x * 2;

            Assert.Equal(new int[] { 8, 6, 4 }, res);
        }
예제 #2
0
        public static async Task LinqSelectAsyncTest()
        {
            var res =
                from x in Task.FromResult(Lst.Make(4, 3, 2))
                select x * 2;

            Assert.Equal(new int[] { 8, 6, 4 }, await res);
        }
예제 #3
0
        public static IEnumerable <object[]> Ap2Data()
        {
            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(),
                Lst.Make <int>(),
                Lst.Make <int>(),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(),
                Lst.Make(1),
                Lst.Make <int>(),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(),
                Lst.Make(1),
                Lst.Make(1),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(x => y => x + y),
                Lst.Make <int>(),
                Lst.Make <int>(),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(x => y => x + y),
                Lst.Make(4),
                Lst.Make(6),
                Lst.Make(10),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(x => y => x + y),
                Lst.Make(1, 2, 3),
                Lst.Make(7, 8, 9),
                Lst.Make(8, 9, 10, 9, 10, 11, 10, 11, 12),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(x => y => x + y, x => y => x * y),
                Lst.Make(5),
                Lst.Make(8),
                Lst.Make(13, 40),
            });

            yield return(new object[] {
                Lst.Make <Func <int, Func <int, int> > >(x => y => x + y, x => y => x * y),
                Lst.Make(5, 6, 7),
                Lst.Make(10, 20, 30),
                Lst.Make(15, 25, 35, 16, 26, 36, 17, 27, 37, 50, 100, 150, 60, 120, 180, 70, 140, 210),
            });
        }
예제 #4
0
        public static async Task LinqSelectManyAsyncTest()
        {
            var res =
                from x in Task.FromResult(Lst.Make(2, 3, 5))
                from y in Task.FromResult(Lst.Make(7, 11, 13))
                select x *y;

            Assert.Equal(new int[] { 14, 22, 26, 21, 33, 39, 35, 55, 65 }, await res);
        }
예제 #5
0
        public static void LinqSelectManyTest()
        {
            var res =
                from x in Lst.Make(2, 3, 5)
                from y in Lst.Make(7, 11, 13)
                select x *y;

            Assert.Equal(new int[] { 14, 22, 26, 21, 33, 39, 35, 55, 65 }, res);
        }
예제 #6
0
        public static void LstAppendCompact()
        {
            var fl      = Lst.Make(5, 6, 2, 8);
            var fl2     = fl.Append(9);
            var flSlice = fl.Slice(1, 2);
            var fl3     = flSlice.Append(11);
            var fl4     = flSlice.AppendRange(new int[] { 22, 33, 44 });

            Assert.Equal(new int[] { 5, 6, 2, 8 }, fl);
            Assert.Equal(new int[] { 5, 6, 2, 8, 9 }, fl2);
            Assert.Equal(new int[] { 6, 2 }, flSlice);
            Assert.Equal(new int[] { 6, 2, 11 }, fl3);
            Assert.Equal(new int[] { 6, 2, 22, 33, 44 }, fl4);
        }
예제 #7
0
        public static void LstBindTest()
        {
            var res = Lst.Make <int>().Bind(x => Lst.Make("a", "b")).ToLst();

            Assert.Empty(res);

            res = Lst.Make <int>(1, 2, 3).Bind(x => Lst.Make <string>()).ToLst();

            Assert.Empty(res);

            res = Lst.Make <int>(1, 2, 3).Bind(x => Lst.Make(x + "a", x + "b")).ToLst();

            Assert.Equal(new string[] { "1a", "1b", "2a", "2b", "3a", "3b" }, res);
        }
예제 #8
0
        public static IEnumerable <object[]> EqualsData()
        {
            yield return(new object[] {
                Lst.Make <int>(),
                Lst.Make <int>(),
                true
            });

            yield return(new object[] {
                Lst.Make(1),
                Lst.Make(1),
                true
            });

            yield return(new object[] {
                Lst.Make(1, 2, 3),
                Lst.Make(1, 2, 3),
                true
            });

            yield return(new object[] {
                Lst.Make(4),
                Lst.Make <int>(),
                false
            });

            yield return(new object[] {
                Lst.Make <int>(),
                Lst.Make(7),
                false
            });

            yield return(new object[] {
                Lst.Make(1, 2),
                Lst.Make(5, 6),
                false
            });

            yield return(new object[] {
                Lst.Make(1, 2),
                Lst.Make(1),
                false
            });

            yield return(new object[] {
                Lst.Make(1, 2, 3),
                Lst.Make(1, 2, 3, 4),
                false
            });
        }
예제 #9
0
        public static void LstCompactTest()
        {
            var fl    = Lst.Make(0, 1, 2, 3, 4);
            var flBig = fl.AppendRange(Enumerable.Repeat(0, 3000).ZipWithStream(5, i => i + 1).Select(xy => xy.Item2));

            Assert.Equal(3005, fl.UnderlyingListCount);
            Assert.Equal(3005, flBig.UnderlyingListCount);

            Assert.Equal(new int[] { 0, 1, 2, 3, 4 }, fl);

            flBig.Dispose();

            Assert.Equal(5, fl.UnderlyingListCount);
            Assert.Equal(new int[] { 0, 1, 2, 3, 4 }, fl);

            flBig = fl.AppendRange(Enumerable.Repeat(0, 2000).ZipWithStream(5, i => i + 1).Select(xy => xy.Item2));

            Assert.Equal(new int[] { 0, 1, 2, 3, 4 }, fl);
            Assert.Equal(2005, fl.UnderlyingListCount);
            Assert.Equal(2005, flBig.UnderlyingListCount);

            var flSlice  = flBig.Slice(10, 300);
            var flSlice2 = flBig.Slice(11, 300);
            var flSlice3 = flBig.Slice(5, 300);
            var flSlice4 = flBig.Slice(20, 5);
            var flSlice5 = flBig.Slice(5, 400);

            Assert.Equal(300, flSlice.Count);
            Assert.Equal(Enumerable.Range(10, 300), flSlice);
            Assert.Equal(300, flSlice2.Count);
            Assert.Equal(Enumerable.Range(11, 300), flSlice2);
            Assert.Equal(300, flSlice3.Count);
            Assert.Equal(Enumerable.Range(5, 300), flSlice3);
            Assert.Equal(5, flSlice4.Count);
            Assert.Equal(Enumerable.Range(20, 5), flSlice4);
            Assert.Equal(400, flSlice5.Count);
            Assert.Equal(Enumerable.Range(5, 400), flSlice5);

            Assert.Equal(2005, flBig.UnderlyingListCount);

            flBig.Dispose();

            Assert.Equal(405, flSlice.UnderlyingListCount);
            Assert.Equal(405, flSlice2.UnderlyingListCount);
            Assert.Equal(405, flSlice3.UnderlyingListCount);
            Assert.Equal(405, flSlice4.UnderlyingListCount);
            Assert.Equal(405, flSlice5.UnderlyingListCount);
        }
예제 #10
0
        public static IEnumerable <object[]> Ap1Data()
        {
            yield return(new object[] {
                Lst.Make <Func <int, int> >(),
                Lst.Make <int>(),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(),
                Lst.Make(1),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(x => x + 1),
                Lst.Make <int>(),
                Lst.Make <int>(),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(x => x + 1),
                Lst.Make(4),
                Lst.Make(5),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(x => x + 1),
                Lst.Make(1, 2, 3),
                Lst.Make(2, 3, 4),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(x => x + 1, x => x * 2),
                Lst.Make(5),
                Lst.Make(6, 10),
            });

            yield return(new object[] {
                Lst.Make <Func <int, int> >(x => x + 1, x => x * 2),
                Lst.Make(5, 6, 7),
                Lst.Make(6, 7, 8, 10, 12, 14),
            });
        }
예제 #11
0
        public static void LstMonadZeroTest(int[] xs, int[] ys, int[] expected)
        {
            Assert.Empty(Lst.Make <int>().Mzero().ToLst());

            Assert.Equal(expected, xs.MakeLst().Mplus(ys.MakeLst()).ToLst());
        }