public void SelectE() { var outputs = new List <int>(10); var list = new List <int>(10); for (int i = 0; i < 10; i++) { list.Add(i); } Assert.That(() => { Zinq <int> .FromEnumerator(list.GetEnumerator()) .Select(_x => _x * 5) .To(outputs); }, Is.Not.AllocatingGCMemory()); Debug.Log(string.Join(", ", outputs)); Assert.IsTrue(list.Select(x => 5 * x).SequenceEqual(outputs)); }
public void FirstOrDefault() { int output1 = -1, output2 = -1, output3 = -1, output4 = -1; var list = new List <int>(10); var array = new int[10]; for (int i = 0; i < 10; i++) { list.Add(i); array[i] = i; } int context = 10; Assert.That(() => { output1 = Zinq <int> .FromEnumerator(list.GetEnumerator()) .Select((add: 10, mul: 2), (_c, _v) => _c.add + _v * _c.mul) .FirstOrDefault(); output2 = list.Zinq() .Select((add: 10, mul: 2), (_c, _v) => _c.add + _v * _c.mul) .FirstOrDefault(_x => _x % 3 == 0); output3 = Zinq <int> .FromArray(array) .Select((add: 10, mul: 2), (_c, _v) => _c.add + _v * _c.mul) .FirstOrDefault(); output4 = array.Zinq() .Select((add: 10, mul: 2), (_c, _v) => _c.add + _v * _c.mul) .FirstOrDefault(_x => _x % 3 == 0); }, Is.Not.AllocatingGCMemory()); Debug.Log($"{output1}, {output2}, {output3}, {output4}"); Assert.AreEqual(output1, list.Select(x => 10 + x * 2).FirstOrDefault()); Assert.AreEqual(output1, output3); Assert.AreEqual(output2, array.Select(x => 10 + x * 2).FirstOrDefault(_x => _x % 3 == 0)); Assert.AreEqual(output2, output4); }
public void AsEnumerable() { var outputs = new List <int>(10); var list = new List <int>(10); for (int i = 0; i < 10; i++) { list.Add(i); } Assert.That(() => { var query = Zinq <int> .FromEnumerator(list.GetEnumerator()) .Select(_x => _x * 5) .AsEnumerable(); foreach (var result in query) { outputs.Add(result); } }, Is.Not.AllocatingGCMemory()); Debug.Log(string.Join(", ", outputs)); Assert.IsTrue(list.Select(x => 5 * x).SequenceEqual(outputs)); }