瀏覽代碼

Moving and splitting Distinct tests.

Bart De Smet 8 年之前
父節點
當前提交
39ad7449d3

+ 0 - 125
Ix.NET/Source/System.Interactive.Async.Tests/AsyncTests.Single.cs

@@ -291,131 +291,6 @@ namespace Tests
             AssertThrows<Exception>(() => xs.ForEachAsync((x, i) => { throw ex; }).Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
         }
 
-        [Fact]
-        public void Distinct_Null()
-        {
-            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>(() => AsyncEnumerableEx.Distinct<int, int>(AsyncEnumerable.Return(42), (Func<int, int>)null));
-        }
-
-        [Fact]
-        public void Distinct1()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
-
-            var e = xs.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, 2);
-            HasNext(e, 3);
-            HasNext(e, 5);
-            HasNext(e, 4);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Distinct2()
-        {
-            var xs = new[] { 1, -2, -1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(new Eq());
-
-            var e = xs.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, -2);
-            HasNext(e, 3);
-            HasNext(e, 5);
-            HasNext(e, 4);
-            NoNext(e);
-        }
-
-        [Fact]
-        public async Task Distinct3()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
-
-            var res = new[] { 1, 2, 3, 5, 4 };
-            Assert.True(res.SequenceEqual(await xs.ToArray()));
-        }
-
-        [Fact]
-        public async Task Distinct4()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
-
-            var res = new List<int> { 1, 2, 3, 5, 4 };
-            Assert.True(res.SequenceEqual(await xs.ToList()));
-        }
-
-        [Fact]
-        public async Task Distinct5()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
-
-            Assert.Equal(5, await xs.Count());
-        }
-
-        [Fact]
-        public async Task Distinct6()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
-
-            var res = new[] { 1, 2, 3, 5, 4 };
-            Assert.True(res.SequenceEqual(await xs.ToArray()));
-        }
-
-        [Fact]
-        public async Task Distinct7()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
-
-            var res = new List<int> { 1, 2, 3, 5, 4 };
-            Assert.True(res.SequenceEqual(await xs.ToList()));
-        }
-
-        [Fact]
-        public async Task Distinct8()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
-
-            Assert.Equal(5, await xs.Count());
-        }
-
-        [Fact]
-        public async Task Distinct9()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
-
-            await SequenceIdentity(xs);
-        }
-
-        [Fact]
-        public async Task Distinct10()
-        {
-            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
-
-            await SequenceIdentity(xs);
-        }
-
-        [Fact]
-        public void Distinct11()
-        {
-            var xs = AsyncEnumerable.Empty<int>().Distinct(k => k);
-
-            var e = xs.GetAsyncEnumerator();
-
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Distinct12()
-        {
-            var xs = AsyncEnumerable.Empty<int>().Distinct();
-
-            var e = xs.GetAsyncEnumerator();
-
-            NoNext(e);
-        }
-
         [Fact]
         public void GroupBy_Null()
         {

+ 65 - 0
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Distinct.cs

@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Tests
+{
+    public class Distinct : AsyncEnumerableExTests
+    {
+        [Fact]
+        public void Distinct_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerableEx.Distinct<int, int>(AsyncEnumerable.Return(42), (Func<int, int>)null));
+        }
+
+        [Fact]
+        public async Task Distinct6()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
+
+            var res = new[] { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToArray()));
+        }
+
+        [Fact]
+        public async Task Distinct7()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
+
+            var res = new List<int> { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToList()));
+        }
+
+        [Fact]
+        public async Task Distinct8()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
+
+            Assert.Equal(5, await xs.Count());
+        }
+
+        [Fact]
+        public async Task Distinct9()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(k => k);
+
+            await SequenceIdentity(xs);
+        }
+
+        [Fact]
+        public void Distinct11()
+        {
+            var xs = AsyncEnumerable.Empty<int>().Distinct(k => k);
+
+            var e = xs.GetAsyncEnumerator();
+
+            NoNext(e);
+        }
+    }
+}

+ 108 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Distinct.cs

@@ -0,0 +1,108 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Tests
+{
+    public class Distinct : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Distinct_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(null));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(null, EqualityComparer<int>.Default));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Distinct<int>(AsyncEnumerable.Return(42), null));
+        }
+
+        [Fact]
+        public void Distinct1()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            var e = xs.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, 2);
+            HasNext(e, 3);
+            HasNext(e, 5);
+            HasNext(e, 4);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Distinct2()
+        {
+            var xs = new[] { 1, -2, -1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct(new Eq());
+
+            var e = xs.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, -2);
+            HasNext(e, 3);
+            HasNext(e, 5);
+            HasNext(e, 4);
+            NoNext(e);
+        }
+
+        [Fact]
+        public async Task Distinct3()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            var res = new[] { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToArray()));
+        }
+
+        [Fact]
+        public async Task Distinct4()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            var res = new List<int> { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToList()));
+        }
+
+        [Fact]
+        public async Task Distinct5()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            Assert.Equal(5, await xs.Count());
+        }
+
+        [Fact]
+        public async Task Distinct10()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            await SequenceIdentity(xs);
+        }
+
+        [Fact]
+        public void Distinct12()
+        {
+            var xs = AsyncEnumerable.Empty<int>().Distinct();
+
+            var e = xs.GetAsyncEnumerator();
+
+            NoNext(e);
+        }
+
+        private sealed class Eq : IEqualityComparer<int>
+        {
+            public bool Equals(int x, int y)
+            {
+                return EqualityComparer<int>.Default.Equals(Math.Abs(x), Math.Abs(y));
+            }
+
+            public int GetHashCode(int obj)
+            {
+                return EqualityComparer<int>.Default.GetHashCode(Math.Abs(obj));
+            }
+        }
+    }
+}