public void SortDescendingTests([ValueSource("list0")] QueryArg arg) { var expected = arg.ToList(); expected.Sort(); expected.Reverse(); Assert.That(arg.ToQuery().SortDescending().ToList(), Is.EquivalentTo( expected)); }
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); }
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())); }
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++; } }
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())); }
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)); }
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))); } }
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)); }
public void MultiForeachTest([ValueSource("list0")] QueryArg arg) { List <int> a = new List <int>(); List <int> b = new List <int>(); var q = arg.ToQuery(); foreach (var item in q) { a.Add(item); } Assert.That(() => { foreach (var item in q) { b.Add(item); } }, Throws.InvalidOperationException); }
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)); }
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())); }
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())); }
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())); }
public void SkipTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Skip(3).ToList(), Is.EquivalentTo( arg.ToList().Skip(3).ToList())); }
public void AnyTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Any(i => i == 4), Is.EqualTo( arg.ToList().Query().Any(i => i == 4))); }
public void OrderByDescendingTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().OrderByDescending(i => i).ToList(), Is.EquivalentTo( arg.ToList().OrderByDescending(i => i).ToList())); }
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())); }