Skip to content

Commit

Permalink
#2811: Add tests for SortedSet and ImmutableSortedSet overloads for A…
Browse files Browse the repository at this point in the history
…ssert.Contains/DoesNotContain (v2)
  • Loading branch information
bradwilson committed Dec 7, 2023
1 parent 51851a6 commit c4e29fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/xunit.assert/Asserts
Submodule Asserts updated 1 files
+48 −0 SetAsserts.cs
10 changes: 9 additions & 1 deletion test/test.xunit.assert/Asserts/SetAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public static void ValueInSet()

Assert.Contains("FORTY-two", set);
Assert.Contains("FORTY-two", (ISet<string>)set);
Assert.Contains("FORTY-two", set.ToSortedSet(StringComparer.OrdinalIgnoreCase));
#if NET5_0_OR_GREATER
Assert.Contains("FORTY-two", (IReadOnlySet<string>)set);
#endif
#if XUNIT_IMMUTABLE_COLLECTIONS
Assert.Contains("FORTY-two", set.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase));
Assert.Contains("FORTY-two", set.ToImmutableSortedSet(StringComparer.OrdinalIgnoreCase));
#endif
}

Expand All @@ -46,11 +48,13 @@ void assertFailure(Action action)

assertFailure(() => Assert.Contains("FORTY-two", set));
assertFailure(() => Assert.Contains("FORTY-two", (ISet<string>)set));
assertFailure(() => Assert.Contains("FORTY-two", set.ToSortedSet()));
#if NET5_0_OR_GREATER
assertFailure(() => Assert.Contains("FORTY-two", (IReadOnlySet<string>)set));
#endif
#if XUNIT_IMMUTABLE_COLLECTIONS
assertFailure(() => Assert.Contains("FORTY-two", set.ToImmutableHashSet()));
assertFailure(() => Assert.Contains("FORTY-two", set.ToImmutableSortedSet()));
#endif
}
}
Expand All @@ -64,11 +68,13 @@ public static void ValueNotInSet()

Assert.DoesNotContain("FORTY-two", set);
Assert.DoesNotContain("FORTY-two", (ISet<string>)set);
Assert.DoesNotContain("FORTY-two", set.ToSortedSet());
#if NET5_0_OR_GREATER
Assert.DoesNotContain("FORTY-two", (IReadOnlySet<string>)set);
#endif
#if XUNIT_IMMUTABLE_COLLECTIONS
Assert.DoesNotContain("FORTY-two", set.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase));
Assert.DoesNotContain("FORTY-two", set.ToImmutableHashSet());
Assert.DoesNotContain("FORTY-two", set.ToImmutableSortedSet());
#endif
}

Expand All @@ -92,11 +98,13 @@ void assertFailure(Action action)

assertFailure(() => Assert.DoesNotContain("FORTY-two", set));
assertFailure(() => Assert.DoesNotContain("FORTY-two", (ISet<string>)set));
assertFailure(() => Assert.DoesNotContain("FORTY-two", set.ToSortedSet(StringComparer.OrdinalIgnoreCase)));
#if NET5_0_OR_GREATER
assertFailure(() => Assert.DoesNotContain("FORTY-two", (IReadOnlySet<string>)set));
#endif
#if XUNIT_IMMUTABLE_COLLECTIONS
assertFailure(() => Assert.DoesNotContain("FORTY-two", set.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase)));
assertFailure(() => Assert.DoesNotContain("FORTY-two", set.ToImmutableSortedSet(StringComparer.OrdinalIgnoreCase)));
#endif
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/test.xunit.assert/Extensions/SetExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Collections.Generic;

internal static class SetExtensions
{
public static SortedSet<T> ToSortedSet<T>(this ISet<T> set, IComparer<T>? comparer = null) =>
new SortedSet<T>(set, comparer);
}

0 comments on commit c4e29fd

Please sign in to comment.