diff options
author | Ian Hays <ianha@microsoft.com> | 2017-02-07 20:43:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-07 20:43:49 +0300 |
commit | 4677a0f7bf578cf39b2ca6ca86655ef7e449384a (patch) | |
tree | bbb81db884c8c77717e8a3fa86e10b1f343891c5 | |
parent | 29d7b6dee194e71bc5c98eec962bcac39bee8bb7 (diff) | |
parent | dd6339313d5d94186a7771dcd4398930379ac03c (diff) |
Merge pull request #15857 from hughbe/ss-tests
Add some SortedSet tests
4 files changed, 97 insertions, 4 deletions
diff --git a/src/Common/tests/System/Collections/ICollection.Generic.Tests.cs b/src/Common/tests/System/Collections/ICollection.Generic.Tests.cs index 3d2e37508c..7dda8a1591 100644 --- a/src/Common/tests/System/Collections/ICollection.Generic.Tests.cs +++ b/src/Common/tests/System/Collections/ICollection.Generic.Tests.cs @@ -141,7 +141,7 @@ namespace System.Collections.Tests [Theory] [MemberData(nameof(ValidCollectionSizes))] - public void ICollection_Generic_Add_DefaultValue(int count) + public virtual void ICollection_Generic_Add_DefaultValue(int count) { if (DefaultValueAllowed && !IsReadOnly && !AddRemoveClear_ThrowsNotSupported) { @@ -374,7 +374,7 @@ namespace System.Collections.Tests [Theory] [MemberData(nameof(ValidCollectionSizes))] - public void ICollection_Generic_Contains_DefaultValueOnCollectionContainingDefaultValue(int count) + public virtual void ICollection_Generic_Contains_DefaultValueOnCollectionContainingDefaultValue(int count) { if (DefaultValueAllowed && !IsReadOnly && !AddRemoveClear_ThrowsNotSupported) { @@ -549,7 +549,7 @@ namespace System.Collections.Tests [Theory] [MemberData(nameof(ValidCollectionSizes))] - public void ICollection_Generic_Remove_DefaultValueContainedInCollection(int count) + public virtual void ICollection_Generic_Remove_DefaultValueContainedInCollection(int count) { if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported && DefaultValueAllowed && !Enumerable.Contains(InvalidValues, default(T))) { diff --git a/src/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs b/src/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs index 4a8532fbf6..2d255fc7ab 100644 --- a/src/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs +++ b/src/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs @@ -83,14 +83,19 @@ namespace System.Collections.Tests [MemberData(nameof(ValidCollectionSizes))] public void SortedSet_Generic_MaxAndMin(int setLength) { + SortedSet<T> set = (SortedSet<T>)GenericISetFactory(setLength); if (setLength > 0) { - SortedSet<T> set = (SortedSet<T>)GenericISetFactory(setLength); List<T> expected = set.ToList(); expected.Sort(GetIComparer()); Assert.Equal(expected[0], set.Min); Assert.Equal(expected[setLength - 1], set.Max); } + else + { + Assert.Equal(default(T), set.Min); + Assert.Equal(default(T), set.Max); + } } #endregion @@ -197,6 +202,13 @@ namespace System.Collections.Tests Assert.Equal(setLength, set.Count); } + [Fact] + public void SortedSet_Generic_RemoveWhere_NullPredicate_ThrowsArgumentNullException() + { + SortedSet<T> set = (SortedSet<T>)GenericISetFactory(); + Assert.Throws<ArgumentNullException>("match", () => set.RemoveWhere(null)); + } + #endregion #region Enumeration and Ordering diff --git a/src/System.Collections/tests/Generic/SortedSet/SortedSet.TreeSubSet.Tests.cs b/src/System.Collections/tests/Generic/SortedSet/SortedSet.TreeSubSet.Tests.cs new file mode 100644 index 0000000000..196ab3cc97 --- /dev/null +++ b/src/System.Collections/tests/Generic/SortedSet/SortedSet.TreeSubSet.Tests.cs @@ -0,0 +1,80 @@ +// 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.Linq; +using Xunit; + +namespace System.Collections.Tests +{ + public class SortedSet_TreeSubset_Int_Tests : SortedSet_TreeSubset_Tests<int> + { + protected override int Min => int.MinValue; + protected override int Max => int.MaxValue; + + protected override bool DefaultValueAllowed => true; + + protected override int CreateT(int seed) + { + Random rand = new Random(seed); + return rand.Next(); + } + } + + public class SortedSet_TreeSubset_String_Tests : SortedSet_TreeSubset_Tests<string> + { + protected override string Min => 0.ToString().PadLeft(10); + protected override string Max => int.MaxValue.ToString().PadLeft(10); + private int _current = 1; + + protected override string CreateT(int seed) + { + return _current++.ToString().PadLeft(10); + } + + public override void ICollection_Generic_Remove_DefaultValueContainedInCollection(int count) + { + if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported && DefaultValueAllowed && !Enumerable.Contains(InvalidValues, default(string))) + { + int seed = count * 21; + ICollection<string> collection = GenericICollectionFactory(count); + Assert.Throws<ArgumentOutOfRangeException>("item", () => collection.Remove(default(string))); + } + } + + public override void ICollection_Generic_Contains_DefaultValueOnCollectionContainingDefaultValue(int count) + { + if (DefaultValueAllowed && !IsReadOnly && !AddRemoveClear_ThrowsNotSupported) + { + ICollection<string> collection = GenericICollectionFactory(count); + Assert.Throws<ArgumentOutOfRangeException>("item", () => collection.Add(default(string))); + } + } + } + + public abstract class SortedSet_TreeSubset_Tests<T> : SortedSet_Generic_Tests<T> + { + protected abstract T Min { get; } + protected abstract T Max { get; } + private SortedSet<T> OriginalSet { get; set; } + + protected override ISet<T> GenericISetFactory() + { + OriginalSet = new SortedSet<T>(); + return OriginalSet.GetViewBetween(Min, Max); + } + + public override void ICollection_Generic_Add_DefaultValue(int count) + { + // Adding an item to a TreeSubset does nothing - it updates the parent. + if (DefaultValueAllowed && !IsReadOnly && !AddRemoveClear_ThrowsNotSupported) + { + ICollection<T> collection = GenericICollectionFactory(count); + collection.Add(default(T)); + Assert.Equal(count, collection.Count); + Assert.Equal(count + 1, OriginalSet.Count); + } + } + } +} diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index 6ba7cbcb58..ba2001458b 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -67,6 +67,7 @@ <Link>Common\System\ObjectCloner.cs</Link> </Compile> <!-- Generic tests --> + <Compile Include="Generic\SortedSet\SortedSet.TreeSubSet.Tests.cs" /> <Compile Include="StructuralComparisonsTests.cs" /> <Compile Include="BitArray\BitArray_CtorTests.cs" /> <Compile Include="BitArray\BitArray_GetSetTests.cs" /> |