public void TestMultipleElementSet() { var values = new[] { Generator.GetInt32().ToString(), Generator.GetInt32().ToString(), Generator.GetInt32().ToString() }; // Construction using ImmutableSortedTreeSet.Create var set = ImmutableSortedTreeSet.Create(values); Assert.Equal(values.OrderBy(x => x, Comparer <string> .Default), set); set = ImmutableSortedTreeSet.Create <string>(comparer: null, values); Assert.Same(Comparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(x => x, Comparer <string> .Default), set); set = ImmutableSortedTreeSet.Create(StringComparer.OrdinalIgnoreCase, values); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(values.OrderBy(x => x, StringComparer.OrdinalIgnoreCase), set); // Construction using ImmutableSortedTreeSet.ToImmutableSortedTreeSet set = values.ToImmutableSortedTreeSet(); Assert.Same(Comparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(x => x, Comparer <string> .Default), set); set = values.ToImmutableSortedTreeSet(comparer: null); Assert.Same(Comparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(x => x, Comparer <string> .Default), set); set = values.ToImmutableSortedTreeSet(StringComparer.OrdinalIgnoreCase); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(values.OrderBy(x => x, StringComparer.OrdinalIgnoreCase), set); }
public void TestEmptyImmutableSortedTreeSet() { var set = ImmutableSortedTreeSet.Create <int>(); Assert.Same(ImmutableSortedTreeSet <int> .Empty, set); Assert.Empty(set); }
public void TestUnsupportedISetOperations() { ISet <int> set = ImmutableSortedTreeSet.Create <int>(); Assert.Throws <NotSupportedException>(() => set.Add(1)); Assert.Throws <NotSupportedException>(() => set.UnionWith(Enumerable.Empty <int>())); Assert.Throws <NotSupportedException>(() => set.IntersectWith(Enumerable.Empty <int>())); Assert.Throws <NotSupportedException>(() => set.ExceptWith(Enumerable.Empty <int>())); Assert.Throws <NotSupportedException>(() => set.SymmetricExceptWith(Enumerable.Empty <int>())); }
public void TestIListTInterface() { TestIListTInterfaceImpl(ImmutableSortedTreeSet.Create(600, 601), supportsNullValues: false); TestIListTInterfaceImpl(ImmutableSortedTreeSet.Create <int?>(600, 601), supportsNullValues: true); TestIListTInterfaceImpl(ImmutableSortedTreeSet.Create <object>(600, 601), supportsNullValues: true); // Run the same set of tests on List<T> to ensure consistent behavior TestIListTInterfaceImpl(ImmutableList.Create(600, 601), supportsNullValues: false); TestIListTInterfaceImpl(ImmutableList.Create <int?>(600, 601), supportsNullValues: true); TestIListTInterfaceImpl(ImmutableList.Create <object>(600, 601), supportsNullValues: true); }
public void TestExplicitComparer() { var objComparer = new ComparisonComparer <object>((x, y) => 0); var intComparer = new ComparisonComparer <int>((x, y) => 0); var comparableComparer = new ComparisonComparer <IComparable>((x, y) => 0); Assert.Same(objComparer, ImmutableSortedTreeSet.Create <object>(comparer: objComparer).KeyComparer); Assert.Same(intComparer, ImmutableSortedTreeSet.Create <int>(comparer: intComparer).KeyComparer); Assert.Same(comparableComparer, ImmutableSortedTreeSet.Create <IComparable>(comparer: comparableComparer).KeyComparer); Assert.Same(objComparer, ImmutableSortedTreeSet.CreateRange <object>(comparer: objComparer, Enumerable.Empty <object>()).KeyComparer); Assert.Same(intComparer, ImmutableSortedTreeSet.CreateRange <int>(comparer: intComparer, Enumerable.Empty <int>()).KeyComparer); Assert.Same(comparableComparer, ImmutableSortedTreeSet.CreateRange <IComparable>(comparer: comparableComparer, Enumerable.Empty <IComparable>()).KeyComparer); }
public void TestSingleElementSet() { var value = Generator.GetInt32().ToString(); var set = ImmutableSortedTreeSet.Create(value); Assert.Equal(new[] { value }, set); set = ImmutableSortedTreeSet.Create(comparer: null, value); Assert.Same(Comparer <string> .Default, set.KeyComparer); Assert.Equal(new[] { value }, set); set = ImmutableSortedTreeSet.Create(StringComparer.OrdinalIgnoreCase, value); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(new[] { value }, set); }
public void TestCollectionConstructorUsesCorrectComparer() { var instance1 = new StrongBox <int>(1); var instance2 = new StrongBox <int>(2); var comparer = new ComparisonComparer <StrongBox <int> >((x, y) => Comparer <int> .Default.Compare(x.Value, y.Value)); var objectSet = ImmutableSortedTreeSet.Create(comparer, new[] { instance1, instance2, instance1 }).ToBuilder(); Assert.Same(comparer, objectSet.KeyComparer); Assert.Equal(2, objectSet.Count); Assert.Equal(new[] { instance1, instance2 }, objectSet); ImmutableSortedTreeSet <string?> .Builder stringSet = ImmutableSortedTreeSet.CreateBuilder <string?>(); Assert.Same(Comparer <string> .Default, stringSet.KeyComparer); stringSet = ImmutableSortedTreeSet.CreateBuilder(StringComparer.OrdinalIgnoreCase); Assert.Same(StringComparer.OrdinalIgnoreCase, stringSet.KeyComparer); }
public void TestICollectionInterface() { TestICollectionInterfaceImpl(ImmutableSortedTreeSet.Create <int>(600, 601).ToBuilder(), isOwnSyncRoot: true, supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableSortedTreeSet.Create <int?>(600, 601).ToBuilder(), isOwnSyncRoot: true, supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableSortedTreeSet.Create <object>(600, 601).ToBuilder(), isOwnSyncRoot: true, supportsNullValues: true); // Run the same set of tests on SortedSet<T> to ensure consistent behavior TestICollectionInterfaceImpl(new SortedSet <int> { 600, 601 }, isOwnSyncRoot: false, supportsNullValues: false); TestICollectionInterfaceImpl(new SortedSet <int?> { 600, 601 }, isOwnSyncRoot: false, supportsNullValues: true); TestICollectionInterfaceImpl(new SortedSet <object> { 600, 601 }, isOwnSyncRoot: false, supportsNullValues: true); }
public void TestDefaultComparer() { Assert.Same(Comparer <object> .Default, ImmutableSortedTreeSet.Create <object>().KeyComparer); Assert.Same(Comparer <int> .Default, ImmutableSortedTreeSet.Create <int>().KeyComparer); Assert.Same(Comparer <IComparable> .Default, ImmutableSortedTreeSet.Create <IComparable>().KeyComparer); Assert.Same(Comparer <object> .Default, ImmutableSortedTreeSet.CreateRange <object>(Enumerable.Empty <object>()).KeyComparer); Assert.Same(Comparer <int> .Default, ImmutableSortedTreeSet.CreateRange <int>(Enumerable.Empty <int>()).KeyComparer); Assert.Same(Comparer <IComparable> .Default, ImmutableSortedTreeSet.CreateRange <IComparable>(Enumerable.Empty <IComparable>()).KeyComparer); Assert.Same(Comparer <object> .Default, ImmutableSortedTreeSet.Create <object>(comparer: null).KeyComparer); Assert.Same(Comparer <int> .Default, ImmutableSortedTreeSet.Create <int>(comparer: null).KeyComparer); Assert.Same(Comparer <IComparable> .Default, ImmutableSortedTreeSet.Create <IComparable>(comparer: null).KeyComparer); Assert.Same(Comparer <object> .Default, ImmutableSortedTreeSet.CreateRange <object>(comparer: null, Enumerable.Empty <object>()).KeyComparer); Assert.Same(Comparer <int> .Default, ImmutableSortedTreeSet.CreateRange <int>(comparer: null, Enumerable.Empty <int>()).KeyComparer); Assert.Same(Comparer <IComparable> .Default, ImmutableSortedTreeSet.CreateRange <IComparable>(comparer: null, Enumerable.Empty <IComparable>()).KeyComparer); }
public void TestImmutableSortedTreeSetCreateValidation() { Assert.Throws <ArgumentNullException>("other", () => ImmutableSortedTreeSet.Create(default(int[]) !)); Assert.Throws <ArgumentNullException>("other", () => ImmutableSortedTreeSet.Create(Comparer <int> .Default, default(int[]) !)); }
public void TestIListInterface() { TestIListInterfaceImpl(ImmutableSortedTreeSet.Create <int>(600, 601), supportsNullValues: false); TestIListInterfaceImpl(ImmutableSortedTreeSet.Create <int?>(600, 601), supportsNullValues: true); TestIListInterfaceImpl(ImmutableSortedTreeSet.Create <ValueType>(600, 601), supportsNullValues: true); }