From 124df5ae643bb8a5da84e29c9baaf9f253039539 Mon Sep 17 00:00:00 2001 From: James Ko Date: Thu, 5 Jan 2017 00:39:28 -0500 Subject: [PATCH] Finish first pass --- .../tests/ImmutableArrayTest.cs | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/System.Collections.Immutable/tests/ImmutableArrayTest.cs b/src/System.Collections.Immutable/tests/ImmutableArrayTest.cs index e7f0c3cc2d7c..90667d5add3f 100644 --- a/src/System.Collections.Immutable/tests/ImmutableArrayTest.cs +++ b/src/System.Collections.Immutable/tests/ImmutableArrayTest.cs @@ -2141,16 +2141,10 @@ public static IEnumerable IStructuralComparableCompareToInvalidData() } [Theory] - [InlineData(new int[0], 5)] - [InlineData(new int[] { 3 }, 5)] - [InlineData(new int[] { 5 }, 5)] - [InlineData(new int[] { 1, 2, 3 }, 1)] - [InlineData(new int[] { 1, 2, 3 }, 2)] - [InlineData(new int[] { 1, 2, 3 }, 3)] - [InlineData(new int[] { 1, 2, 3, 4 }, 4)] - public void BinarySearch(int[] array, int value) + [MemberData(nameof(BinarySearchData))] + public void BinarySearch(IEnumerable source, int value) { - Assert.Throws("array", () => ImmutableArray.BinarySearch(s_emptyDefault, value)); + var array = source.ToArray(); Assert.Equal( Array.BinarySearch(array, value), @@ -2176,17 +2170,35 @@ public void BinarySearch(int[] array, int value) ImmutableArray.BinarySearch(ImmutableArray.Create(array), 0, array.Length, value, Comparer.Default)); } + public static IEnumerable BinarySearchData() + { + yield return new object[] { new int[0], 5 }; + yield return new object[] { new[] { 3 }, 5 }; + yield return new object[] { new[] { 5 }, 5 }; + yield return new object[] { new[] { 1, 2, 3 }, 1 }; + yield return new object[] { new[] { 1, 2, 3 }, 2 }; + yield return new object[] { new[] { 1, 2, 3 }, 3 }; + yield return new object[] { new[] { 1, 2, 3, 4 }, 4 }; + } + + [Theory] + [MemberData(nameof(BinarySearchData))] + public void BinarySearchDefaultInvalid(IEnumerable source, int value) + { + Assert.Throws("array", () => ImmutableArray.BinarySearch(s_emptyDefault, value)); + } + [Fact] public void OfType() { - Assert.Equal(0, s_emptyDefault.OfType().Count()); - Assert.Equal(0, s_empty.OfType().Count()); - Assert.Equal(1, s_oneElement.OfType().Count()); - Assert.Equal(1, s_twoElementRefTypeWithNull.OfType().Count()); + Assert.Equal(new int[0], s_emptyDefault.OfType()); + Assert.Equal(new int[0], s_empty.OfType()); + Assert.Equal(s_oneElement, s_oneElement.OfType()); + Assert.Equal(new[] { "1" }, s_twoElementRefTypeWithNull.OfType()); } [Fact] - public void Add_ThreadSafety() + public void AddThreadSafety() { // Note the point of this thread-safety test is *not* to test the thread-safety of the test itself. // This test has a known issue where the two threads will stomp on each others updates, but that's not the point. @@ -2207,11 +2219,11 @@ public void Add_ThreadSafety() Task.WaitAll(Task.Run(mutator), Task.Run(mutator)); } - [Fact] - public void DebuggerAttributesValid() + [Theory] + [MemberData(nameof(Int32EnumerableData))] + public void DebuggerAttributesValid(IEnumerable source) { - DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableArray.Create()); // verify empty - DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableArray.Create(1, 2, 3)); // verify non-empty + DebuggerAttributes.ValidateDebuggerDisplayReferences(source.ToImmutableArray()); } protected override IEnumerable GetEnumerableOf(params T[] contents)