Example #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)));
        }
Example #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)));
        }
Example #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)));
        }
Example #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)));
        }
Example #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()));
        }
Example #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()));
        }
Example #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);
        }
Example #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)));
        }
Example #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()));
        }
Example #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()));
            }
        }
Example #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)));
            }
        }
Example #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++;
            }
        }
Example #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()));
        }
Example #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));
        }
Example #15
0
        public void SortTest([ValueSource("list0")] QueryArg arg)
        {
            var expected = arg.ToList();

            expected.Sort();

            Assert.That(arg.ToQuery().Sort().ToList(), Is.EquivalentTo(
                            expected));
        }
Example #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()));
        }
Example #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++;
            }
        }
Example #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));
        }
Example #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)));
            }
        }
Example #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));
        }
Example #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()));
 }
Example #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()));
 }
Example #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()));
 }
Example #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()));
 }
Example #25
0
 public void SkipTest([ValueSource("list0")] QueryArg arg)
 {
     Assert.That(arg.ToQuery().Skip(3).ToList(), Is.EquivalentTo(
                     arg.ToList().Skip(3).ToList()));
 }
Example #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()));
 }
Example #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)));
 }