public void AverageSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Average()
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            double result = linq.Evaluate <double>();

            Assert.AreEqual(4.5, result);
        }
        public void AverageProjection()
        {
            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Average(w => w.Length)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            double result = linq.Evaluate <double>();

            Assert.AreEqual(6.66666666666667, result);
        }
        public void MaxSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Max()
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(9, result);
        }
        public void MaxProjection()
        {
            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Max(w => w.Length)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(9, result);
        }
        public void CountIndexed()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Count((n, index) => n % 2 == index % 2)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(4, result);
        }
        public void CountConditional()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Count(n => n % 2 == 1)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(5, result);
        }
        public void CountSimple()
        {
            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                factorsOf300.Distinct().Count() 
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("factorsOf300", factorsOf300);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(3, result);
        }
        public void First()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.First((num, index) => (num % 2 == 0) && (index % 2 == 0))"
                                   );

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(6, result);
        }
        public void ElementAt()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                (from n in numbers
                where n < 5
                select n ).ElementAt(3)"
                                   );

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate <int>();

            Assert.AreEqual(2, result);
        }
Exemplo n.º 10
0
        public void MaxProjection()
        {
            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Max(w => w.Length)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(9, result);
        }
Exemplo n.º 11
0
        public void MaxSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Max()
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(9, result);
        }
Exemplo n.º 12
0
        public void CountIndexed()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Count((n, index) => n % 2 == index % 2)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(4, result);
        }
Exemplo n.º 13
0
        public void CountConditional()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 

            query = new NLinqQuery(@"
                numbers.Count(n => n % 2 == 1)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(5, result);
        }
Exemplo n.º 14
0
        public void CountSimple()
        {
            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                factorsOf300.Distinct().Count() 
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("factorsOf300", factorsOf300);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(3, result);
        }
Exemplo n.º 15
0
        public void ElementAt()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                (from n in numbers
                where n < 5
                select n ).ElementAt(3)"
                );

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(2, result);
        }
Exemplo n.º 16
0
        public void AverageSimple()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Average()
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            double result = linq.Evaluate<double>();

            Assert.AreEqual(4.5, result);
        }
Exemplo n.º 17
0
        public void AverageProjection()
        {
            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Average(w => w.Length)
            ");

            linq = new LinqToMemory(query);
            linq.AddSource("words", words);

            double result = linq.Evaluate<double>();

            Assert.AreEqual(6.66666666666667, result);
        }
Exemplo n.º 18
0
        public void First()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.First((num, index) => (num % 2 == 0) && (index % 2 == 0))"
                );

            linq = new LinqToMemory(query);
            linq.AddSource("numbers", numbers);

            int result = linq.Evaluate<int>();

            Assert.AreEqual(6, result);
        }