Esempio n. 1
0
        public void ContainsTest([ValueSource("list0")] QueryArg arg)
        {
            Assert.That(arg.ToQuery().Contains(3), Is.EqualTo(
                            arg.ToList().Contains(3)));

            Assert.That(arg.ToQuery().Contains(9), Is.EqualTo(
                            arg.ToList().Contains(9)));
        }
Esempio n. 2
0
        public void CountTests([ValueSource("list0")] QueryArg arg)
        {
            Assert.That(arg.ToQuery().Count(), Is.EqualTo(
                            arg.ToList().Count()));

            Assert.That(arg.ToQuery().Count(i => i % 2 == 0), Is.EqualTo(
                            arg.ToList().Count(i => i % 2 == 0)));
        }
Esempio n. 3
0
        public void AllTest([ValueSource("list0")] QueryArg arg)
        {
            Assert.That(arg.ToQuery().All(i => i < 5), Is.EqualTo(
                            arg.ToList().All(i => i < 5)));

            Assert.That(arg.ToQuery().All(i => i != 8), Is.EqualTo(
                            arg.ToList().All(i => i != 8)));
        }
Esempio n. 4
0
        public void IndexOfTests([ValueSource("list0")] QueryArg arg)
        {
            Assert.That(arg.ToQuery().IndexOf(3), Is.EqualTo(
                            arg.ToList().IndexOf(3)));

            Assert.That(arg.ToQuery().IndexOf(100), Is.EqualTo(
                            arg.ToList().IndexOf(100)));
        }
Esempio n. 5
0
        public void ConcatTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list0")] QueryArg arg1)
        {
            Assert.That(arg0.ToQuery().Concat(arg1.ToList()).ToList(), Is.EquivalentTo(
                            arg0.ToList().Concat(arg1.ToList()).ToList()));

            Assert.That(arg0.ToQuery().Concat(arg1.ToQuery()).ToList(), Is.EquivalentTo(
                            arg0.ToList().Concat(arg1.ToList()).ToList()));
        }
Esempio n. 6
0
        public void SelectManyTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list0")] QueryArg arg1)
        {
            Assert.That(arg0.ToQuery().SelectMany(i => arg1.ToQuery().Select(j => j * i)).ToList(), Is.EquivalentTo(
                            arg0.ToList().SelectMany(i => arg1.ToList().Select(j => j * i)).ToList()));

            Assert.That(arg0.ToQuery().SelectMany(i => arg1.ToList().Select(j => j * i).ToList()).ToList(), Is.EquivalentTo(
                            arg0.ToList().SelectMany(i => arg1.ToList().Select(j => j * i)).ToList()));
        }
Esempio n. 7
0
        public void AverageTest([ValueSource("list0")] QueryArg arg0)
        {
            if (arg0.ToList().Count == 0)
            {
                Assert.Ignore("Ignore empty queries for average test.");
                return;
            }

            Assert.That(arg0.ToQuery().Select(t => (double)t).Average(), Is.EqualTo(
                            arg0.ToList().Average()).Within(0.001).Percent);
        }
Esempio n. 8
0
        public void FirstOrDefaultTests([ValueSource("list0")] QueryArg arg)
        {
            Assert.That(arg.ToQuery().FirstOrDefault(), Is.EqualTo(
                            arg.ToList().FirstOrDefault()));

            Assert.That(arg.ToQuery().FirstOrDefault(i => i % 2 == 0), Is.EqualTo(
                            arg.ToList().FirstOrDefault(i => i % 2 == 0)));

            Assert.That(arg.ToQuery().FirstOrDefault(i => i > 10), Is.EqualTo(
                            arg.ToList().FirstOrDefault(i => i > 10)));
        }
Esempio n. 9
0
        public void SumTests([ValueSource("list0")] QueryArg arg)
        {
            if (arg.ToList().Count == 0)
            {
                Assert.Ignore("Ignore empty queries for sum tests.");
                return;
            }

            Assert.That(arg.ToQuery().Sum(), Is.EqualTo(
                            arg.ToList().Sum()));
        }
Esempio n. 10
0
        public void FoldTest([ValueSource("list0")] QueryArg arg)
        {
            var list = arg.ToList();

            if (list.Count == 0)
            {
                Assert.That(() => arg.ToQuery().Fold((a, b) => a + b), Throws.InvalidOperationException);
            }
            else
            {
                Assert.That(arg.ToQuery().Fold((a, b) => a + b), Is.EqualTo(
                                arg.ToList().Sum()));
            }
        }
Esempio n. 11
0
        public void ElementAtTest([ValueSource("list0")] QueryArg arg, [Values(0, 3, 100)] int index)
        {
            var list = arg.ToList();

            if (index >= list.Count)
            {
                Assert.That(() => arg.ToQuery().ElementAt(index), Throws.InstanceOf <IndexOutOfRangeException>());
            }
            else
            {
                Assert.That(arg.ToQuery().ElementAt(index), Is.EqualTo(
                                arg.ToList().ElementAt(index)));
            }
        }
Esempio n. 12
0
        public void WithPreviousTest([ValueSource("list0")] QueryArg arg)
        {
            var list = arg.ToList();

            if (list.Count == 0)
            {
                Assert.That(arg.ToQuery().WithPrevious().Count(), Is.EqualTo(0));
                Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(), Is.EqualTo(0));
            }
            else if (list.Count == 1)
            {
                Assert.That(arg.ToQuery().WithPrevious().Count(), Is.EqualTo(0));
                Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(), Is.EqualTo(1));
            }
            else
            {
                Assert.That(arg.ToQuery().WithPrevious().Count(p => p.hasPrev), Is.EqualTo(list.Count - 1));
                Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(p => !p.hasPrev), Is.EqualTo(1));
                Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(p => p.hasPrev), Is.EqualTo(list.Count - 1));
            }

            int index = 0;

            foreach (var pair in arg.ToQuery().WithPrevious())
            {
                Assert.That(pair.prev, Is.EqualTo(list[index]));
                index++;
            }
        }
Esempio n. 13
0
        public void LastTests([ValueSource("list0")] QueryArg arg)
        {
            var list = arg.ToList();

            if (list.Count == 0)
            {
                Assert.That(() => arg.ToQuery().Last(), Throws.InvalidOperationException);
            }
            else
            {
                Assert.That(arg.ToQuery().Last(), Is.EqualTo(
                                arg.ToList().Last()));
            }

            Assert.That(arg.ToQuery().LastOrDefault(), Is.EqualTo(
                            arg.ToList().LastOrDefault()));
        }
Esempio n. 14
0
        public void ZipTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list1")] QueryArg arg1)
        {
            var list0 = arg0.ToList();
            var list1 = arg1.ToList();

            List <string> expected = new List <string>();

            for (int i = 0; i < Mathf.Min(list0.Count, list1.Count); i++)
            {
                expected.Add(list0[i].ToString() + list1[i].ToString());
            }

            Assert.That(arg0.ToQuery().Zip(arg1.ToQuery(), (a, b) => a.ToString() + b.ToString()).ToList(), Is.EquivalentTo(
                            expected));

            Assert.That(arg0.ToQuery().Zip(arg1.ToList(), (a, b) => a.ToString() + b.ToString()).ToList(), Is.EquivalentTo(
                            expected));
        }
Esempio n. 15
0
        public void SortTest([ValueSource("list0")] QueryArg arg)
        {
            var expected = arg.ToList();

            expected.Sort();

            Assert.That(arg.ToQuery().Sort().ToList(), Is.EquivalentTo(
                            expected));
        }
Esempio n. 16
0
        public void ForeachTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list1")] QueryArg arg1)
        {
            List <int> actual = new List <int>();

            foreach (var item in arg0.ToQuery().Concat(arg1.ToQuery()))
            {
                actual.Add(item);
            }
            Assert.That(actual, Is.EquivalentTo(
                            arg0.ToList().Concat(arg1.ToList()).ToList()));
        }
Esempio n. 17
0
        public void WithIndicesTest([ValueSource("list0")] QueryArg arg)
        {
            int index = 0;

            foreach (var item in arg.ToQuery().WithIndices())
            {
                Assert.That(item.index, Is.EqualTo(index));
                Assert.That(item.value, Is.EqualTo(arg.ToList()[index]));
                index++;
            }
        }
Esempio n. 18
0
        public void Repeat([ValueSource("list0")] QueryArg arg, [Values(0, 1, 2, 3, 100)] int repetitions)
        {
            List <int> list = new List <int>();

            for (int i = 0; i < repetitions; i++)
            {
                list.AddRange(arg.ToList());
            }

            Assert.That(arg.ToQuery().Repeat(repetitions).ToList(), Is.EquivalentTo(
                            list));
        }
Esempio n. 19
0
        public void FirstTests([ValueSource("list0")] QueryArg arg)
        {
            var list = arg.ToList();

            if (list.Count == 0)
            {
                Assert.That(() => arg.ToQuery().First(), Throws.InvalidOperationException);
            }
            else
            {
                Assert.That(arg.ToQuery().First(), Is.EqualTo(
                                arg.ToList().First()));
            }

            if (list.Where(i => i % 2 == 0).Count() == 0)
            {
                Assert.That(() => arg.ToQuery().Where(i => i % 2 == 0).First(), Throws.InvalidOperationException);
            }
            else
            {
                Assert.That(arg.ToQuery().First(i => i % 2 == 0), Is.EqualTo(
                                arg.ToList().First(i => i % 2 == 0)));
            }
        }
Esempio n. 20
0
        public void WithPreviousOffsetTest([ValueSource("list0")] QueryArg arg)
        {
            var list = arg.ToList();

            if (list.Count == 0)
            {
                Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(0));
                Assert.That(arg.ToQuery().WithPrevious(offset: 4, includeStart: true).Count(), Is.EqualTo(0));
            }
            else if (list.Count == 1)
            {
                Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(0));
                Assert.That(arg.ToQuery().WithPrevious(offset: 4, includeStart: true).Count(), Is.EqualTo(1));
            }
            else
            {
                Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(Mathf.Max(0, list.Count - 4)));
                Assert.That(arg.ToQuery().WithPrevious(offset: list.Count + 1).Count(), Is.EqualTo(0));
                Assert.That(arg.ToQuery().WithPrevious(offset: int.MaxValue).Count(), Is.EqualTo(0));
            }

            Assert.That(Values.Range(0, 10).WithPrevious(offset: 2).All(i => i.value - i.prev == 2));
        }
Esempio n. 21
0
 public void SelectTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Select(i => i * 23).ToList(), Is.EquivalentTo(
                     arg.ToList().Select(i => i * 23).ToList()));
 }
Esempio n. 22
0
 public void WhereTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Where(i => i % 2 == 0).ToList(), Is.EquivalentTo(
                     arg.ToList().Where(i => i % 2 == 0).ToList()));
 }
Esempio n. 23
0
 public void TakeWhileTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().TakeWhile(i => i < 4).ToList(), Is.EquivalentTo(
                     arg.ToList().TakeWhile(i => i < 4).ToList()));
 }
Esempio n. 24
0
 public void OrderByDescendingTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().OrderByDescending(i => i).ToList(), Is.EquivalentTo(
                     arg.ToList().OrderByDescending(i => i).ToList()));
 }
Esempio n. 25
0
 public void SkipTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Skip(3).ToList(), Is.EquivalentTo(
                     arg.ToList().Skip(3).ToList()));
 }
Esempio n. 26
0
 public void DistinctTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Distinct().OrderBy(t => t).ToList(), Is.EquivalentTo(
                     arg.ToList().Distinct().OrderBy(t => t).ToList()));
 }
Esempio n. 27
0
 public void AnyTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Any(i => i == 4), Is.EqualTo(
                     arg.ToList().Query().Any(i => i == 4)));
 }