Beispiel #1
0
        public void ExecuteTestInline()
        {
            Func <List <PointTest> > linqForEachSelectForSelectMany = () =>
            {
                var rnd      = new Random();
                var range    = Enumerable.Range(1, 10);
                var minValue = 5;
                var maxValue = 600;
                var points   = range.Select(i =>
                {
                    var p = new PointTest {
                        X = rnd.Next(minValue, maxValue), Y = rnd.Next(minValue, maxValue)
                    };
                    return(p);
                });

                var map = new GraphTest(points);

                var AllPoints = new List <LineTest>();
                foreach (var p in map.Points)
                {
                    for (var i = 0; i < map.Points.Count; i++)
                    {
                        if (p != map.Points[i])
                        {
                            var ln = new LineTest(p, map.Points[i]);
                            if (!AllPoints.Any(x => x == ln))
                            {
                                AllPoints.Add(ln);
                            }
                        }
                    }
                }
                //return result;



                var res = AllPoints.SelectMany(x => new[] { x.A, x.B }).ToList();
                return(res);
            };

            var engine = new ILEngine.ILInstructionEngine();

            var expected = linqForEachSelectForSelectMany();

            var IlExecuted = engine.ExecuteTyped <List <PointTest> >(linqForEachSelectForSelectMany.Method, engine);

            Assert.IsNotNull(IlExecuted);
            Assert.IsInstanceOfType(IlExecuted, typeof(List <PointTest>));
            Assert.IsTrue(IlExecuted.Count == expected.Count);  //TODO: this can fail if same points are generated
                                                                // Assert.IsTrue(expected.SequenceEqual(IlExecuted));  //TODO: points are generated randomly
        }
Beispiel #2
0
        public void ExecuteTestInline1()
        {
            var rnd      = new Random();
            var range    = Enumerable.Range(1, 10);
            var minValue = 5;
            var maxValue = 600;
            var points   = range.Select(i =>
            {
                var p = new PointTest {
                    X = rnd.Next(minValue, maxValue), Y = rnd.Next(minValue, maxValue)
                };
                return(p);
            });
            var map = new GraphTest(points);

            Func <List <LineTest> > UniqueLines = () =>
            {
                var AllPoints = new List <LineTest>();
                foreach (var p in map.Points)
                {
                    for (var i = 0; i < map.Points.Count; i++)
                    {
                        if (p != map.Points[i])
                        {
                            var ln = new LineTest(p, map.Points[i]);
                            if (!AllPoints.Any(x => x == ln))
                            {
                                AllPoints.Add(ln);
                            }
                        }
                    }
                }
                return(AllPoints);
            };



            var engine = new ILEngine.ILInstructionEngine();

            var expected   = UniqueLines();
            var IlExecuted = engine.ExecuteTyped <List <LineTest> >(UniqueLines.Method, UniqueLines.Target);// <-- this fails because the func loads a local variable as an arg even though there is no arg in the func()

            Assert.IsNotNull(IlExecuted);
            Assert.IsInstanceOfType(IlExecuted, typeof(List <LineTest>));
            Assert.IsTrue(IlExecuted.Count == expected.Count); //TODO: this can fail if same points are generated
            //Assert.IsTrue(expected.SequenceEqual(IlExecuted)); <-- //TODO: points are generated randomly
        }
Beispiel #3
0
 public LineTest(PointTest a, PointTest b)
 {
     this.A = a; this.B = b;
 }
Beispiel #4
0
        public void ExecuteTest()
        {
            Func <List <PointTest> > linqForEachSelectForSelectMany = () =>
            {
                var rnd      = new Random();
                var range    = Enumerable.Range(1, 10);
                var minValue = 5;
                var maxValue = 600;
                var points   = range.Select(i =>
                {
                    var p = new PointTest {
                        X = rnd.Next(minValue, maxValue), Y = rnd.Next(minValue, maxValue)
                    };
                    return(p);
                });

                var map = new GraphTest(points);
                Func <List <LineTest> > GetAllPoints = () =>
                {
                    var result = new List <LineTest>();
                    foreach (var p in map.Points)
                    {
                        for (var i = 0; i < map.Points.Count; i++)
                        {
                            if (p != map.Points[i])
                            {
                                var ln = new LineTest(p, map.Points[i]);
                                if (!result.Any(x => x == ln))
                                {
                                    result.Add(ln);
                                }
                            }
                        }
                    }
                    return(result);
                };

                var res = GetAllPoints().Distinct().SelectMany(x => new[] { x.A, x.B }).ToList();
                return(res);
            };

            var engine = new ILEngine.ILInstructionEngine();

            var expected = linqForEachSelectForSelectMany();

            var IlExecuted = engine.ExecuteTyped <List <PointTest> >(linqForEachSelectForSelectMany.Method, linqForEachSelectForSelectMany);

            Assert.IsNotNull(IlExecuted);
            Assert.IsInstanceOfType(IlExecuted, typeof(List <PointTest>));
            Assert.IsTrue(IlExecuted.Count == expected.Count); // <-- TODO: Implemented distinct to deal with duplicate points.
            //Assert.IsTrue(expected.SequenceEqual(IlExecuted)); <-- points are random

            ExecuteTestInline1();
            ExecuteTestInline();


            Func <List <PointTest> > listCtor = () =>
            {
                var pta = new PointTest()
                {
                    X = 0, Y = 2
                };
                var ptb = new PointTest()
                {
                    X = 2, Y = 2
                };

                var l = new List <PointTest>(new[] { pta, ptb });
                return(l);
            };


            var listCtorExpected = listCtor();

            var listCtorResult = engine.ExecuteTyped <List <PointTest> >(listCtor.Method, listCtor.Target);

            Assert.IsNotNull(listCtorResult);
            Assert.IsTrue(listCtorResult.SequenceEqual(listCtorExpected));

            Func <bool[]> linqListComp = () =>
            {
                var pta = new PointTest()
                {
                    X = 0, Y = 2
                };
                var ptb = new PointTest()
                {
                    X = 2, Y = 2
                };

                var l = new List <PointTest>(new[] { pta, ptb });    //a is getting overwrote with b;

                var cmpLtResult  = l.FirstOrDefault(x => x < ptb) == pta;
                var cmpLteResult = l.FirstOrDefault(x => x <= ptb) == pta;
                var cmpEqResult  = l.FirstOrDefault(x => x == ptb) == ptb;
                var cmpGteResult = l.FirstOrDefault(x => x >= ptb) == ptb;
                var cmpGtResult  = l.FirstOrDefault(x => x > ptb) == PointTest.Empty;


                return(new[] { cmpLtResult, cmpLteResult, cmpEqResult, cmpGteResult, cmpGtResult });
            };

            var linqCmpExpected = linqListComp();

            var linqCmpResult = engine.ExecuteTyped <bool[]>(linqListComp.Method, linqListComp.Target);
            var cmpExpected   = new bool[] { true, true, true, true, true };

            Assert.IsNotNull(linqCmpResult);
            Assert.IsTrue(linqCmpResult.Length == 5);
            Assert.IsTrue(linqCmpResult.All(x => x));
        }