Пример #1
0
        public void SelectA()
        {
            var outputs  = new List <int>(10);
            var outputs2 = new List <int>(10);

            var array = new int[10];

            for (int i = 0; i < 10; i++)
            {
                array[i] = i;
            }

            Assert.That(() =>
            {
                Zinq <int> .FromArray(array)
                .Select(_x => _x * 5)
                .To(outputs);

                array.Zinq()
                .Select(_x => _x * 5)
                .To(outputs2);
            }, Is.Not.AllocatingGCMemory());

            Debug.Log(string.Join(", ", outputs));
            Assert.IsTrue(array.Select(x => 5 * x).SequenceEqual(outputs));
            Assert.IsTrue(array.Select(x => 5 * x).SequenceEqual(outputs2));
        }
Пример #2
0
        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);
        }