/// </summary>
protected virtual Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException);
+ /// <summary>
+ /// Used for the ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowsException test. Some implementations
+ /// throw a different exception type (e.g. RankException by ImmutableArray)
+ /// </summary>
+ protected virtual Type ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowType => typeof(ArgumentException);
+
#endregion
#region IEnumerable Helper Methods
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowsArgumentException(int count)
+ public void ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowsException(int count)
{
if (count > 0)
{
ICollection collection = NonGenericICollectionFactory(count);
- Array arr = new object[count,count];
+ Array arr = new object[count, count];
Assert.Equal(2, arr.Rank);
- Assert.Throws<ArgumentException>(() => collection.CopyTo(arr, 0));
+ Assert.Throws(ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowType, () => collection.CopyTo(arr, 0));
}
}
protected override ICollection<T> GenericICollectionFactory(int count) => GenericIListFactory(count);
+ protected virtual Type IList_Generic_Item_InvalidIndex_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
#region Item Getter
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_Generic_ItemGet_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_Generic_ItemGet_NegativeIndex_ThrowsException(int count)
{
IList<T> list = GenericIListFactory(count);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[-1]);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[int.MinValue]);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[-1]);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[int.MinValue]);
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_Generic_ItemGet_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_Generic_ItemGet_IndexGreaterThanListCount_ThrowsException(int count)
{
IList<T> list = GenericIListFactory(count);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count]);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count + 1]);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count]);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count + 1]);
}
[Theory]
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_Generic_ItemSet_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_Generic_ItemSet_NegativeIndex_ThrowsException(int count)
{
if (!IsReadOnly)
{
IList<T> list = GenericIListFactory(count);
T validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = validAdd);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[int.MinValue] = validAdd);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[-1] = validAdd);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[int.MinValue] = validAdd);
Assert.Equal(count, list.Count);
}
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_Generic_ItemSet_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_Generic_ItemSet_IndexGreaterThanListCount_ThrowsException(int count)
{
if (!IsReadOnly)
{
IList<T> list = GenericIListFactory(count);
T validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count] = validAdd);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count + 1] = validAdd);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count] = validAdd);
+ Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count + 1] = validAdd);
Assert.Equal(count, list.Count);
}
}
protected virtual bool ExpectedFixedSize => false;
+ protected virtual Type IList_NonGeneric_Item_InvalidIndex_ThrowType => typeof(ArgumentOutOfRangeException);
+
#endregion
#region ICollection Helper Methods
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_ItemGet_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_ItemGet_NegativeIndex_ThrowsException(int count)
{
IList list = NonGenericIListFactory(count);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[-1]);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[int.MinValue]);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[-1]);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[int.MinValue]);
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_ItemGet_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_ItemGet_IndexGreaterThanListCount_ThrowsException(int count)
{
IList list = NonGenericIListFactory(count);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count]);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count + 1]);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[count]);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[count + 1]);
}
[Theory]
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_ItemSet_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_ItemSet_NegativeIndex_ThrowsException(int count)
{
if (!IsReadOnly)
{
IList list = NonGenericIListFactory(count);
object validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = validAdd);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[int.MinValue] = validAdd);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[-1] = validAdd);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[int.MinValue] = validAdd);
Assert.Equal(count, list.Count);
}
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_ItemSet_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_ItemSet_IndexGreaterThanListCount_ThrowsException(int count)
{
if (!IsReadOnly)
{
IList list = NonGenericIListFactory(count);
object validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count] = validAdd);
- Assert.Throws<ArgumentOutOfRangeException>(() => list[count + 1] = validAdd);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[count] = validAdd);
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list[count + 1] = validAdd);
Assert.Equal(count, list.Count);
}
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_Insert_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_Insert_NegativeIndex_ThrowsException(int count)
{
if (!IsReadOnly && !ExpectedFixedSize)
{
IList list = NonGenericIListFactory(count);
object validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, validAdd));
- Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(int.MinValue, validAdd));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.Insert(-1, validAdd));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.Insert(int.MinValue, validAdd));
Assert.Equal(count, list.Count);
}
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_RemoveAt_NegativeIndex_ThrowsException(int count)
{
if (!IsReadOnly && !ExpectedFixedSize)
{
IList list = NonGenericIListFactory(count);
object validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
- Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(int.MinValue));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.RemoveAt(-1));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.RemoveAt(int.MinValue));
Assert.Equal(count, list.Count);
}
}
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
- public void IList_NonGeneric_RemoveAt_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
+ public void IList_NonGeneric_RemoveAt_IndexGreaterThanListCount_ThrowsException(int count)
{
if (!IsReadOnly && !ExpectedFixedSize)
{
IList list = NonGenericIListFactory(count);
object validAdd = CreateT(0);
- Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(count));
- Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(count + 1));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.RemoveAt(count));
+ Assert.Throws(IList_NonGeneric_Item_InvalidIndex_ThrowType, () => list.RemoveAt(count + 1));
Assert.Equal(count, list.Count);
}
}
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30723.0
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.Immutable", "src\System.Collections.Immutable.csproj", "{1DD0FF15-6234-4BD6-850A-317F05479554}"
EndProject
..\.nuget\packages.Windows_NT.config = ..\.nuget\packages.Windows_NT.config
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D7979177-679D-4E56-919B-479871FA1BDF}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E181070D-D93C-4B03-B1EB-133CEA43503E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {1DD0FF15-6234-4BD6-850A-317F05479554} = {D7979177-679D-4E56-919B-479871FA1BDF}
+ {95DFC527-4DC1-495E-97D7-E94EE1F7140D} = {E181070D-D93C-4B03-B1EB-133CEA43503E}
+ EndGlobalSection
EndGlobal
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+using System.Collections.Tests;
+
+namespace System.Collections.Immutable.Tests
+{
+ public class ImmutableArray_Generic_Int_Tests : ImmutableArray_Generic_Tests<int>
+ {
+ protected override int CreateT(int seed)
+ {
+ Random rand = new Random(seed);
+ return rand.Next();
+ }
+ }
+
+ public abstract class ImmutableArray_Generic_Tests<T> : IList_Generic_Tests<T>
+ {
+ protected override bool IsReadOnly => true;
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
+ protected override Type IList_Generic_Item_InvalidIndex_ThrowType => typeof(IndexOutOfRangeException);
+ protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
+
+ protected override IList<T> GenericIListFactory() => GenericIListFactory(0);
+ protected override IList<T> GenericIListFactory(int count)
+ {
+ T[] items = new T[count];
+ for (int i = 0; i < count; i++)
+ {
+ items[i] = CreateT(i);
+ }
+ return ImmutableArray.Create(items);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+using System.Collections.Tests;
+
+namespace System.Collections.Immutable.Tests
+{
+ public class ImmutableArray_NonGeneric_Tests : IList_NonGeneric_Tests
+ {
+ protected override bool IsReadOnly => true;
+ protected override bool ExpectedFixedSize => true;
+ protected override bool ExpectedIsSynchronized => true;
+ protected override bool ICollection_NonGeneric_SupportsSyncRoot => false;
+
+ protected override Type IList_NonGeneric_Item_InvalidIndex_ThrowType => typeof(IndexOutOfRangeException);
+ protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
+ protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
+
+ protected override Type ICollection_NonGeneric_CopyTo_TwoDimensionArray_ThrowType => typeof(RankException);
+ protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectReferenceType_ThrowType => typeof(InvalidCastException);
+ protected override Type ICollection_NonGeneric_CopyTo_ArrayOfIncorrectValueType_ThrowType => typeof(InvalidCastException);
+ protected override Type ICollection_NonGeneric_CopyTo_NonZeroLowerBound_ThrowType => typeof(ArgumentOutOfRangeException);
+
+ protected override IList NonGenericIListFactory() => NonGenericIListFactory(0);
+ protected override IList NonGenericIListFactory(int count)
+ {
+ object[] items = new object[count];
+ for (int i = 0; i < count; i++)
+ {
+ items[i] = CreateT(i);
+ }
+ return ImmutableArray.Create(items);
+ }
+ }
+}
Assert.Throws<InvalidOperationException>(() => ((IReadOnlyCollection<int>)s_emptyDefault).Count);
Assert.Equal(0, s_empty.Length);
- Assert.Equal(0, ((ICollection)s_empty).Count);
- Assert.Equal(0, ((ICollection<int>)s_empty).Count);
Assert.Equal(0, ((IReadOnlyCollection<int>)s_empty).Count);
Assert.Equal(1, s_oneElement.Length);
- Assert.Equal(1, ((ICollection)s_oneElement).Count);
- Assert.Equal(1, ((ICollection<int>)s_oneElement).Count);
Assert.Equal(1, ((IReadOnlyCollection<int>)s_oneElement).Count);
}
public void IndexGetter()
{
Assert.Equal(1, s_oneElement[0]);
- Assert.Equal(1, ((IList)s_oneElement)[0]);
- Assert.Equal(1, ((IList<int>)s_oneElement)[0]);
Assert.Equal(1, ((IReadOnlyList<int>)s_oneElement)[0]);
Assert.Throws<IndexOutOfRangeException>(() => s_oneElement[1]);
Assert.Throws<InvalidOperationException>(() => ((IList<int>)s_emptyDefault)[0]);
Assert.Throws<InvalidOperationException>(() => ((IReadOnlyList<int>)s_emptyDefault)[0]);
}
-
- [Fact]
- public void ExplicitMethods()
- {
- IList<int> c = s_oneElement;
- Assert.Throws<NotSupportedException>(() => c.Add(3));
- Assert.Throws<NotSupportedException>(() => c.Clear());
- Assert.Throws<NotSupportedException>(() => c.Remove(3));
- Assert.True(c.IsReadOnly);
- Assert.Throws<NotSupportedException>(() => c.Insert(0, 2));
- Assert.Throws<NotSupportedException>(() => c.RemoveAt(0));
- Assert.Equal(s_oneElement[0], c[0]);
- Assert.Throws<NotSupportedException>(() => c[0] = 8);
-
- var enumerator = c.GetEnumerator();
- Assert.True(enumerator.MoveNext());
- Assert.Equal(s_oneElement[0], enumerator.Current);
- Assert.False(enumerator.MoveNext());
- }
-
+
[Fact]
public void Sort()
{
Assert.Equal(new[] { 2, 4, 1, 3 }, array); // original array unaffected.
}
- [Fact]
- public void Sort_Comparison()
+ [Theory]
+ [InlineData(new int[] { 2, 4, 1, 3 }, new int[] { 4, 3, 2, 1 })]
+ [InlineData(new int[] { 1 }, new int[] { 1 })]
+ [InlineData(new int[0], new int[0])]
+ public void Sort_Comparison(int[] items, int[] expected)
{
- var array = ImmutableArray.Create(2, 4, 1, 3);
- Assert.Equal(new[] { 4, 3, 2, 1 }, array.Sort((x, y) => y.CompareTo(x)));
- Assert.Equal(new[] { 2, 4, 1, 3 }, array); // original array unaffected.
+ var array = ImmutableArray.Create(items);
+ Assert.Equal(expected, array.Sort((x, y) => y.CompareTo(x)));
+ Assert.Equal(items, array); // original array unaffected.
}
+
[Fact]
public void Sort_NullComparison_Throws()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableArray.Create(1, 2, 3)); // verify non-empty
}
- [Fact]
- public void ICollectionSyncRoot_NotSupported()
- {
- ICollection c = ImmutableArray.Create(1, 2, 3);
- Assert.Throws<NotSupportedException>(() => c.SyncRoot);
- }
-
protected override IEnumerable<T> GetEnumerableOf<T>(params T[] contents)
{
return ImmutableArray.Create(contents);
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Compile Include="ImmutableArrayExtensionsTest.cs" />
<Compile Include="ImmutableArrayTest.cs" />
<Compile Include="ImmutableArrayTestBase.cs" />
+ <Compile Include="ImmutableArray\ImmutableArray.NonGeneric.Tests .cs" />
<Compile Include="ImmutableDictionaryBuilderTestBase.cs" />
<Compile Include="GenericParameterHelper.cs" />
<Compile Include="ImmutableDictionaryBuilderTest.cs" />
<Compile Include="$(CommonTestPath)\System\ShouldNotBeInvokedException.cs">
<Link>Common\System\ShouldNotBeInvokedException.cs</Link>
</Compile>
+ <!-- Common Collections tests -->
+ <Compile Include="$(CommonTestPath)\System\Collections\CollectionAsserts.cs">
+ <Link>Common\System\Collections\CollectionAsserts.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\ICollection.NonGeneric.Tests.cs">
+ <Link>Common\System\Collections\ICollection.NonGeneric.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\ICollection.Generic.Tests.cs">
+ <Link>Common\System\Collections\ICollection.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IDictionary.NonGeneric.Tests.cs">
+ <Link>Common\System\Collections\IDictionary.NonGeneric.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IDictionary.Generic.Tests.cs">
+ <Link>Common\System\Collections\IDictionary.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IEnumerable.NonGeneric.Tests.cs">
+ <Link>Common\System\Collections\IEnumerable.NonGeneric.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IEnumerable.Generic.Tests.cs">
+ <Link>Common\System\Collections\IEnumerable.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IList.NonGeneric.Tests.cs">
+ <Link>Common\System\Collections\IList.NonGeneric.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IList.Generic.Tests.cs">
+ <Link>Common\System\Collections\IList.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\IGenericSharedAPI.Tests.cs">
+ <Link>Common\System\Collections\IGenericSharedAPI.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\ISet.Generic.Tests.cs">
+ <Link>Common\System\Collections\ISet.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\TestBase.NonGeneric.cs">
+ <Link>Common\System\Collections\TestBase.NonGeneric.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\TestBase.Generic.cs">
+ <Link>Common\System\Collections\TestBase.Generic.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\DebugView.Tests.cs">
+ <Link>Common\System\Collections\DebugView.Tests.cs</Link>
+ </Compile>
+ <Compile Include="$(CommonTestPath)\System\Collections\TestingTypes.cs">
+ <Link>Common\System\Collections\TestingTypes.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram1.cd" />
+ <Compile Include="ImmutableArray\ImmutableArray.Generic.Tests.cs" />
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
\ No newline at end of file