Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Finish first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesqo committed Jan 5, 2017
1 parent 78d57c3 commit 124df5a
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/System.Collections.Immutable/tests/ImmutableArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,16 +2141,10 @@ public static IEnumerable<object[]> 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<int> source, int value)
{
Assert.Throws<ArgumentNullException>("array", () => ImmutableArray.BinarySearch(s_emptyDefault, value));
var array = source.ToArray();

Assert.Equal(
Array.BinarySearch(array, value),
Expand All @@ -2176,17 +2170,35 @@ public void BinarySearch(int[] array, int value)
ImmutableArray.BinarySearch(ImmutableArray.Create(array), 0, array.Length, value, Comparer<int>.Default));
}

public static IEnumerable<object[]> 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<int> source, int value)
{
Assert.Throws<ArgumentNullException>("array", () => ImmutableArray.BinarySearch(s_emptyDefault, value));
}

[Fact]
public void OfType()
{
Assert.Equal(0, s_emptyDefault.OfType<int>().Count());
Assert.Equal(0, s_empty.OfType<int>().Count());
Assert.Equal(1, s_oneElement.OfType<int>().Count());
Assert.Equal(1, s_twoElementRefTypeWithNull.OfType<string>().Count());
Assert.Equal(new int[0], s_emptyDefault.OfType<int>());
Assert.Equal(new int[0], s_empty.OfType<int>());
Assert.Equal(s_oneElement, s_oneElement.OfType<int>());
Assert.Equal(new[] { "1" }, s_twoElementRefTypeWithNull.OfType<string>());
}

[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.
Expand All @@ -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<int> source)
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableArray.Create<string>()); // verify empty
DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableArray.Create(1, 2, 3)); // verify non-empty
DebuggerAttributes.ValidateDebuggerDisplayReferences(source.ToImmutableArray());
}

protected override IEnumerable<T> GetEnumerableOf<T>(params T[] contents)
Expand Down

0 comments on commit 124df5a

Please sign in to comment.