Browse Source

Moving Except, Intersect, and Union tests.

Bart De Smet 8 years ago
parent
commit
c20d4c2557

+ 0 - 136
Ix.NET/Source/System.Interactive.Async.Tests/AsyncTests.Multiple.cs

@@ -210,142 +210,6 @@ namespace Tests
             throw new Exception("Bang!");
             throw new Exception("Bang!");
         }
         }
 
 
-        [Fact]
-        public void Union_Null()
-        {
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(null, AsyncEnumerable.Return(42)));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), null));
-
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(null, AsyncEnumerable.Return(42), new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), null, new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
-        }
-
-        [Fact]
-        public void Union1()
-        {
-            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
-            var res = xs.Union(ys);
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, 2);
-            HasNext(e, 3);
-            HasNext(e, 5);
-            HasNext(e, 4);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Union2()
-        {
-            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
-            var res = xs.Union(ys, new Eq());
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, 2);
-            HasNext(e, -3);
-            HasNext(e, 5);
-            HasNext(e, 4);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Intersect_Null()
-        {
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(null, AsyncEnumerable.Return(42)));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), null));
-
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(null, AsyncEnumerable.Return(42), new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), null, new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
-        }
-
-        [Fact]
-        public void Intersect1()
-        {
-            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
-            var res = xs.Intersect(ys);
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, 3);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Intersect2()
-        {
-            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
-            var res = xs.Intersect(ys, new Eq());
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 1);
-            HasNext(e, -3);
-            NoNext(e);
-        }
-
-        [Fact]
-        public async Task Intersect3()
-        {
-            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
-            var res = xs.Intersect(ys);
-
-            await SequenceIdentity(res);
-        }
-
-
-        [Fact]
-        public void Except_Null()
-        {
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(null, AsyncEnumerable.Return(42)));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), null));
-
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(null, AsyncEnumerable.Return(42), new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), null, new Eq()));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
-        }
-
-        [Fact]
-        public void Except1()
-        {
-            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
-            var res = xs.Except(ys);
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 2);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Except2()
-        {
-            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
-            var res = xs.Except(ys, new Eq());
-
-            var e = res.GetAsyncEnumerator();
-            HasNext(e, 2);
-            NoNext(e);
-        }
-
-        [Fact]
-        public async Task Except3()
-        {
-            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
-            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
-            var res = xs.Except(ys);
-
-            await SequenceIdentity(res);
-        }
-
         [Fact]
         [Fact]
         public async Task SequenceEqual_Null()
         public async Task SequenceEqual_Null()
         {
         {

+ 73 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Except.cs

@@ -0,0 +1,73 @@
+// 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 Except : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Except_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(null, AsyncEnumerable.Return(42)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), null));
+
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(null, AsyncEnumerable.Return(42), new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), null, new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Except<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
+        }
+
+        [Fact]
+        public void Except1()
+        {
+            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
+            var res = xs.Except(ys);
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 2);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Except2()
+        {
+            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
+            var res = xs.Except(ys, new Eq());
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 2);
+            NoNext(e);
+        }
+
+        [Fact]
+        public async Task Except3()
+        {
+            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
+            var res = xs.Except(ys);
+
+            await SequenceIdentity(res);
+        }
+
+        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));
+            }
+        }
+    }
+}

+ 75 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Intersect.cs

@@ -0,0 +1,75 @@
+// 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 Intersect : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Intersect_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(null, AsyncEnumerable.Return(42)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), null));
+
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(null, AsyncEnumerable.Return(42), new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), null, new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Intersect<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
+        }
+
+        [Fact]
+        public void Intersect1()
+        {
+            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
+            var res = xs.Intersect(ys);
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, 3);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Intersect2()
+        {
+            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
+            var res = xs.Intersect(ys, new Eq());
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, -3);
+            NoNext(e);
+        }
+
+        [Fact]
+        public async Task Intersect3()
+        {
+            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
+            var res = xs.Intersect(ys);
+
+            await SequenceIdentity(res);
+        }
+
+        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));
+            }
+        }
+    }
+}

+ 70 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Union.cs

@@ -0,0 +1,70 @@
+// 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 Xunit;
+
+namespace Tests
+{
+    public class Union : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Union_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(null, AsyncEnumerable.Return(42)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), null));
+
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(null, AsyncEnumerable.Return(42), new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), null, new Eq()));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Union<int>(AsyncEnumerable.Return(42), AsyncEnumerable.Return(42), null));
+        }
+
+        [Fact]
+        public void Union1()
+        {
+            var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, 1, 4 }.ToAsyncEnumerable();
+            var res = xs.Union(ys);
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, 2);
+            HasNext(e, 3);
+            HasNext(e, 5);
+            HasNext(e, 4);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Union2()
+        {
+            var xs = new[] { 1, 2, -3 }.ToAsyncEnumerable();
+            var ys = new[] { 3, 5, -1, 4 }.ToAsyncEnumerable();
+            var res = xs.Union(ys, new Eq());
+
+            var e = res.GetAsyncEnumerator();
+            HasNext(e, 1);
+            HasNext(e, 2);
+            HasNext(e, -3);
+            HasNext(e, 5);
+            HasNext(e, 4);
+            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));
+            }
+        }
+    }
+}