Ejemplo n.º 1
0
        public void MinSome()
        {
            int min = 3;

            int[] values = new[] { 7, min, 5 };
            var   src    = FEnumerable.Ana(0, n => n < values.Length, n => n + 1, n => values[n]);

            Assert.AreEqual(min, src.Min().Value);
        }
Ejemplo n.º 2
0
        public void MaxSome()
        {
            int max = 9;

            int[] values = new[] { 7, max, 5 };
            var   src    = FEnumerable.Ana(0, n => n < values.Length, n => n + 1, n => values[n]);

            Assert.AreEqual(max, src.Max().Value);
        }
Ejemplo n.º 3
0
        public void MaxSomeProjected()
        {
            int max = 9;

            int[]           values = new[] { 7, max, 5 };
            Func <int, int> inc    = x => x + 1;
            var             src    = FEnumerable.Ana(0, n => n < values.Length, n => n + 1, n => values[n]);

            Assert.AreEqual(inc(max), src.Max(inc).Value);
        }
Ejemplo n.º 4
0
        public void AnaEmpty()
        {
            var empty = FEnumerable.Ana(0, _ => false, _ => _, x => x);

            for (int i = 0; i < 2; i++)
            {
                var e = empty();
                Assert.IsTrue(e() is Maybe <int> .None, "Non-empty (" + i + ")");
            }
        }
Ejemplo n.º 5
0
        public void All()
        {
            // 0, 1, 2
            var outer = FEnumerable.Ana(0, x => x < 3, x => x + 1, x => x.ToString());
            // 1, 2, 4, 8
            var inner = FEnumerable.Ana(1, x => x < 10, x => x * 2, x => x.ToString());
            // 1, 2, 4, 8, 2, 3, 5, 8, 3, 4, 6, 10
            var reslt = outer.Bind(_ => inner, (o, i) => int.Parse(o) + int.Parse(i));

            Assert.AreEqual(57, reslt.Cata(0, _ => true, (sum, x) => sum + x));
        }
Ejemplo n.º 6
0
        public void AnaInfinite()
        {
            var inc = FEnumerable.Ana(0, _ => true, x => x + 1, x => x.ToString());

            for (int i = 0; i < 2; i++)
            {
                var e = inc();
                Assert.IsTrue(e().Value == "0", "Invalid first (" + i + ")");
                Assert.IsTrue(e().Value == "1", "Invalid second (" + i + ")");
                Assert.IsTrue(e().Value == "2", "Invalid third (" + i + ")");
            }
        }
Ejemplo n.º 7
0
        public void AnaFinite()
        {
            var inc = FEnumerable.Ana(0, x => x < 3, x => x + 1, x => x.ToString());

            for (int i = 0; i < 2; i++)
            {
                var e = inc();
                Assert.IsTrue(e().Value == "0", "Invalid first (" + i + ")");
                Assert.IsTrue(e().Value == "1", "Invalid second (" + i + ")");
                Assert.IsTrue(e().Value == "2", "Invalid third (" + i + ")");
                Assert.IsTrue(e() is Maybe <string> .None, "Not at end (" + i + ")");
            }
        }
Ejemplo n.º 8
0
        public void OfType()
        {
            object[] os  = new[] { (object)1, (object)"Hello", (object)2 };
            var      src = FEnumerable.Ana(0, i => i < os.Length, i => i + 1, i => os[i]);
            var      res = src.OfType <int>();

            for (int i = 0; i < 2; i++)
            {
                var e = res();
                Assert.IsTrue(e().Value == 1);
                Assert.IsTrue(e().Value == 2);
                Assert.IsTrue(e() is Maybe <int> .None);
            }
        }
Ejemplo n.º 9
0
        public void Concat()
        {
            var src = FEnumerable.Ana(1, i => i <= 3, i => i + 1, i => FEnumerable.Range(0, i));
            var res = src.Concat();

            for (int i = 0; i < 2; i++)
            {
                var e = res();
                Assert.IsTrue(e().Value == 0);
                Assert.IsTrue(e().Value == 0);
                Assert.IsTrue(e().Value == 1);
                Assert.IsTrue(e().Value == 0);
                Assert.IsTrue(e().Value == 1);
                Assert.IsTrue(e().Value == 2);
                Assert.IsTrue(e() is Maybe <int> .None);
            }
        }
Ejemplo n.º 10
0
        public void DistinctComparer()
        {
            int[] xs  = new[] { 2, 3, 4, 3, 2, 1, 0, 2, 3, 4, 5 };
            var   src = FEnumerable.Ana(0, i => i < xs.Length, i => i + 1, i => xs[i]);
            var   res = src.Distinct(EqualityComparer <int> .Default);

            for (int i = 0; i < 2; i++)
            {
                var e = res();
                Assert.IsTrue(e().Value == 2);
                Assert.IsTrue(e().Value == 3);
                Assert.IsTrue(e().Value == 4);
                Assert.IsTrue(e().Value == 1);
                Assert.IsTrue(e().Value == 0);
                Assert.IsTrue(e().Value == 5);
                Assert.IsTrue(e() is Maybe <int> .None);
            }
        }