Exemple #1
0
        public void GetEnumerator_CollectionWithGroups_ReturnsCorrectResults()
        {
            var collection = new[]
            {
                1, 2, 3, 4, 5,
                7,
                10, 11,
                13,
                15,
                17, 18, 19
            };

            var output = CollectionExtensions.AggregateIf(collection,
                                                          (prev, current) => current == prev + 1,
                                                          () => string.Empty,
                                                          (aggregator, element) => (aggregator + ", " + element).TrimStart(',', ' '),
                                                          aggregator => aggregator).ToList();

            CollectionAssert.AreEqual(new[]
            {
                "1, 2, 3, 4, 5",
                "7",
                "10, 11",
                "13",
                "15",
                "17, 18, 19"
            }, output);
        }
Exemple #2
0
        public void Constructor_NullResultSelector_ThrowsArgumentNullException()
        {
            IEnumerable <int>     collection         = new int[0];
            Func <int, int, bool> aggregatePredicate = (i1, i2) => true;
            Func <int>            getSeed            = () => 0;
            Func <int, int, int>  aggregateFunc      = (i1, i2) => i1 + i2;
            Func <int, int>       resultSelector     = null;

            Assert.Throws <ArgumentNullException>(() => CollectionExtensions.AggregateIf(collection, aggregatePredicate, getSeed, aggregateFunc, resultSelector));
        }