浏览代码

few more tests

Oren Novotny 9 年之前
父节点
当前提交
ea63796fb0
共有 1 个文件被更改,包括 79 次插入0 次删除
  1. 79 0
      Ix.NET/Source/Tests/AsyncTests.Single.cs

+ 79 - 0
Ix.NET/Source/Tests/AsyncTests.Single.cs

@@ -1128,6 +1128,15 @@ namespace Tests
             await SequenceIdentity(ys);
         }
 
+        [Fact]
+        public async Task TakeWhile11()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
+            var ys = xs.TakeWhile((x, i) => i < 2);
+
+            await SequenceIdentity(ys);
+        }
+
         [Fact]
         public void Skip_Null()
         {
@@ -1486,6 +1495,41 @@ namespace Tests
             Assert.Equal(4, await xs.Count());
         }
 
+        [Fact]
+        public async Task DefaultIfEmpty15()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);
+
+            await SequenceIdentity(xs);
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty16()
+        {
+            var xs = new CancellationTestAsyncEnumerable(10)
+                .Take(5)
+                .Reverse() // so we have an ilist provider 
+                .DefaultIfEmpty(24)
+                .Append(5); // for the onlyIsCheap to true
+
+            var r = new[] { 4, 3, 2, 1, 0, 5 };
+
+            Assert.Equal(r, await xs.ToArray());
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty17()
+        {
+            var xs = new CancellationTestAsyncEnumerable(10)
+                .Take(5)
+                .DefaultIfEmpty(24)
+                .Append(5); // for the onlyIsCheap to true
+
+            var r = new[] { 0, 1, 2, 3, 4, 5};
+
+            Assert.Equal(r, await xs.ToArray());
+        }
+
 
         [Fact]
         public void Distinct_Null()
@@ -1493,6 +1537,7 @@ namespace Tests
             AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(null));
             AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(null, new Eq()));
             AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(AsyncEnumerable.Return(42), null));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int, int>(AsyncEnumerable.Return(42), (Func<int, int>)null));
         }
 
         [Fact]
@@ -1591,6 +1636,26 @@ namespace Tests
             await SequenceIdentity(xs);
         }
 
+        [Fact]
+        public void Distinct11()
+        {
+            var xs = AsyncEnumerable.Empty<int>().Distinct(k => k);
+
+            var e = xs.GetEnumerator();
+            
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Distinct12()
+        {
+            var xs = AsyncEnumerable.Empty<int>().Distinct();
+
+            var e = xs.GetEnumerator();
+
+            NoNext(e);
+        }
+
         [Fact]
         public void Reverse_Null()
         {
@@ -3428,5 +3493,19 @@ namespace Tests
 
             await SequenceIdentity(xs);
         }
+
+        [Fact]
+        public void SkipLast4()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().SkipLast(0);
+
+            var e = xs.GetEnumerator();
+
+            HasNext(e, 1);
+            HasNext(e, 2);
+            HasNext(e, 3);
+            HasNext(e, 4);
+            NoNext(e);
+        }
     }
 }