Ejemplo n.º 1
0
        public void ListLastDoesntCheckAll()
        {
            var source = Enumerable.Range(0, 10).ToList();
            var pred   = new CountedFunction <int, bool>(i => i < 7);

            Assert.Equal(6, source.Last(pred.Func));
            Assert.Equal(4, pred.Calls);
        }
Ejemplo n.º 2
0
        void SingleOrDefaultWithPredicateDoesntCheckAll()
        {
            var tracker = new TrackingEnumerable(10);
            var pred    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker.SingleOrDefault(pred.Func));
            Assert.Equal(4, tracker.Moves);
            Assert.Equal(4, pred.Calls);
        }
Ejemplo n.º 3
0
        public void ListLastDoesntCheckAll()
        {
            var source = Enumerable.Range(0, 10).ToList();
            var pred   = new CountedFunction <int, bool>(i => i < 7);

            Assert.Equal(6, source.Last(pred.Func));

            // .NET Core shortcircuits as an optimization.
            // See https://github.com/dotnet/corefx/pull/2350.
            Assert.Equal(PlatformDetection.IsFullFramework ? 10 : 4, pred.Calls);
        }
Ejemplo n.º 4
0
        void SingleOrDefaultWithPredicateDoesntCheckAll()
        {
            var tracker = new TrackingEnumerable(10);
            var pred    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker.SingleOrDefault(pred.Func));

            // .NET Core shortcircuits as an optimization.
            // See https://github.com/dotnet/corefx/pull/2350.
            Assert.Equal(PlatformDetection.IsFullFramework ? 10 : 4, tracker.Moves);
            Assert.Equal(PlatformDetection.IsFullFramework ? 10 : 4, pred.Calls);
        }
Ejemplo n.º 5
0
        void SingleOrDefaultWithPredicateWorksLikeWhereFollowedBySingleOrDefault()
        {
            var tracker0 = new TrackingEnumerable(10);
            var pred0    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker0.SingleOrDefault(pred0.Func));
            var tracker1 = new TrackingEnumerable(10);
            var pred1    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker1.Where(pred1.Func).SingleOrDefault());
            Assert.Equal(tracker0.Moves, tracker1.Moves);
            Assert.Equal(pred0.Calls, pred1.Calls);
        }
Ejemplo n.º 6
0
        void SingleOrDefaultWithPredicateWorksLikeWhereFollowedBySingleOrDefault()
        {
            var tracker0 = new TrackingEnumerable(10);
            var pred0    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker0.SingleOrDefault(pred0.Func));
            var tracker1 = new TrackingEnumerable(10);
            var pred1    = new CountedFunction <int, bool>(i => i > 2);

            Assert.Throws <InvalidOperationException>(() => tracker1.Where(pred1.Func).SingleOrDefault());

            // .NET Core shortcircuits as an optimization.
            // See https://github.com/dotnet/corefx/pull/2350.
            Assert.Equal(PlatformDetection.IsFullFramework ? 4 : tracker0.Moves, tracker1.Moves);
            Assert.Equal(PlatformDetection.IsFullFramework ? 4 : pred0.Calls, pred1.Calls);
        }