public void TestMultipleElementSet() { var values = new[] { Generator.GetInt32().ToString(), Generator.GetInt32().ToString(), Generator.GetInt32().ToString() }; // Construction using ImmutableTreeSet.Create var set = ImmutableTreeSet.Create(values); Assert.Equal(values.OrderBy(EqualityComparer <string> .Default.GetHashCode), set); set = ImmutableTreeSet.Create <string>(equalityComparer: null, values); Assert.Same(EqualityComparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(EqualityComparer <string> .Default.GetHashCode), set); set = ImmutableTreeSet.Create(StringComparer.OrdinalIgnoreCase, values); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(values.OrderBy(StringComparer.OrdinalIgnoreCase.GetHashCode), set); // Construction using ImmutableTreeSet.ToImmutableTreeSet set = values.ToImmutableTreeSet(); Assert.Same(EqualityComparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(EqualityComparer <string> .Default.GetHashCode), set); set = values.ToImmutableTreeSet(equalityComparer: null); Assert.Same(EqualityComparer <string> .Default, set.KeyComparer); Assert.Equal(values.OrderBy(EqualityComparer <string> .Default.GetHashCode), set); set = values.ToImmutableTreeSet(StringComparer.OrdinalIgnoreCase); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(values.OrderBy(StringComparer.OrdinalIgnoreCase.GetHashCode), set); }
public void TestEmptyImmutableTreeSet() { var set = ImmutableTreeSet.Create <int>(); Assert.Same(ImmutableTreeSet <int> .Empty, set); Assert.Empty(set); }
public void TestUnsupportedISetOperations() { ISet <int> set = ImmutableTreeSet.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 TestICollectionTInterface() { TestICollectionTInterfaceImpl(ImmutableTreeSet.Create(600, 601), supportsNullValues: false); TestICollectionTInterfaceImpl(ImmutableTreeSet.Create <int?>(600, 601), supportsNullValues: true); TestICollectionTInterfaceImpl(ImmutableTreeSet.Create <object>(600, 601), supportsNullValues: true); // Run the same set of tests on ImmutableList<T> to ensure consistent behavior TestICollectionTInterfaceImpl(ImmutableList.Create(600, 601), supportsNullValues: false); TestICollectionTInterfaceImpl(ImmutableList.Create <int?>(600, 601), supportsNullValues: true); TestICollectionTInterfaceImpl(ImmutableList.Create <object>(600, 601), supportsNullValues: true); }
public void TestExplicitComparer() { ZeroHashCodeEqualityComparer <object> objComparer = ZeroHashCodeEqualityComparer <object> .Default; ZeroHashCodeEqualityComparer <int> intComparer = ZeroHashCodeEqualityComparer <int> .Default; ZeroHashCodeEqualityComparer <IComparable> comparableComparer = ZeroHashCodeEqualityComparer <IComparable> .Default; Assert.Same(objComparer, ImmutableTreeSet.Create <object>(equalityComparer: objComparer).KeyComparer); Assert.Same(intComparer, ImmutableTreeSet.Create <int>(equalityComparer: intComparer).KeyComparer); Assert.Same(comparableComparer, ImmutableTreeSet.Create <IComparable>(equalityComparer: comparableComparer).KeyComparer); Assert.Same(objComparer, ImmutableTreeSet.CreateRange <object>(equalityComparer: objComparer, Enumerable.Empty <object>()).KeyComparer); Assert.Same(intComparer, ImmutableTreeSet.CreateRange <int>(equalityComparer: intComparer, Enumerable.Empty <int>()).KeyComparer); Assert.Same(comparableComparer, ImmutableTreeSet.CreateRange <IComparable>(equalityComparer: comparableComparer, Enumerable.Empty <IComparable>()).KeyComparer); }
public void TestSingleElementSet() { var value = Generator.GetInt32().ToString(); var set = ImmutableTreeSet.Create(value); Assert.Equal(new[] { value }, set); set = ImmutableTreeSet.Create(equalityComparer: null, value); Assert.Same(EqualityComparer <string> .Default, set.KeyComparer); Assert.Equal(new[] { value }, set); set = ImmutableTreeSet.Create(StringComparer.OrdinalIgnoreCase, value); Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer); Assert.Equal(new[] { value }, set); }
public void TestCollectionConstructorUsesCorrectComparer() { object instance1 = new object(); object instance2 = new object(); var objectSet = ImmutableTreeSet.Create <object>(ZeroHashCodeEqualityComparer <object> .Default, new[] { instance1, instance2, instance1 }).ToBuilder(); Assert.Same(ZeroHashCodeEqualityComparer <object> .Default, objectSet.KeyComparer); Assert.Equal(2, objectSet.Count); Assert.Equal(new[] { instance1, instance2 }, objectSet); ImmutableTreeSet <string?> .Builder stringSet = ImmutableTreeSet.CreateBuilder <string?>(); Assert.Same(EqualityComparer <string> .Default, stringSet.KeyComparer); stringSet = ImmutableTreeSet.CreateBuilder(StringComparer.OrdinalIgnoreCase); Assert.Same(StringComparer.OrdinalIgnoreCase, stringSet.KeyComparer); }
public void TestICollectionInterface() { TestICollectionInterfaceImpl(ImmutableTreeSet.Create <int>(600, 601).ToBuilder(), isOwnSyncRoot: true, supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableTreeSet.Create <int?>(600, 601).ToBuilder(), isOwnSyncRoot: true, supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableTreeSet.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(EqualityComparer <object> .Default, ImmutableTreeSet.Create <object>().KeyComparer); Assert.Same(EqualityComparer <int> .Default, ImmutableTreeSet.Create <int>().KeyComparer); Assert.Same(EqualityComparer <IComparable> .Default, ImmutableTreeSet.Create <IComparable>().KeyComparer); Assert.Same(EqualityComparer <object> .Default, ImmutableTreeSet.CreateRange <object>(Enumerable.Empty <object>()).KeyComparer); Assert.Same(EqualityComparer <int> .Default, ImmutableTreeSet.CreateRange <int>(Enumerable.Empty <int>()).KeyComparer); Assert.Same(EqualityComparer <IComparable> .Default, ImmutableTreeSet.CreateRange <IComparable>(Enumerable.Empty <IComparable>()).KeyComparer); Assert.Same(EqualityComparer <object> .Default, ImmutableTreeSet.Create <object>(equalityComparer: null).KeyComparer); Assert.Same(EqualityComparer <int> .Default, ImmutableTreeSet.Create <int>(equalityComparer: null).KeyComparer); Assert.Same(EqualityComparer <IComparable> .Default, ImmutableTreeSet.Create <IComparable>(equalityComparer: null).KeyComparer); Assert.Same(EqualityComparer <object> .Default, ImmutableTreeSet.CreateRange <object>(equalityComparer: null, Enumerable.Empty <object>()).KeyComparer); Assert.Same(EqualityComparer <int> .Default, ImmutableTreeSet.CreateRange <int>(equalityComparer: null, Enumerable.Empty <int>()).KeyComparer); Assert.Same(EqualityComparer <IComparable> .Default, ImmutableTreeSet.CreateRange <IComparable>(equalityComparer: null, Enumerable.Empty <IComparable>()).KeyComparer); }
private bool AddChildParentNeedsWatch(IActorRef parent, IActorRef child) { const bool weDontHaveTailRecursion = true; while (weDontHaveTailRecursion) { if (_parent2Children.TryAdd(parent, ImmutableTreeSet <IActorRef> .Create(child))) { return(true); //child was successfully added } IImmutableSet <IActorRef> children; if (_parent2Children.TryGetValue(parent, out children)) { if (_parent2Children.TryUpdate(parent, children.Add(child), children)) { return(false); //child successfully added } } } }
public void TestICollectionInterface() { TestICollectionInterfaceImpl(ImmutableTreeSet.Create(600, 601), supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableTreeSet.Create <int?>(600, 601), supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableTreeSet.Create <object>(600, 601), supportsNullValues: true); ICollection collection = ImmutableTreeSet <int> .Empty; collection.CopyTo(new int[0], 0); // Type checks are only performed if the collection has items collection.CopyTo(new string[0], 0); collection = ImmutableTreeSet.CreateRange(Enumerable.Range(0, 100)); var array = new int[collection.Count]; collection.CopyTo(array, 0); Assert.Equal(array, collection); // Run the same set of tests on ImmutableList<T> to ensure consistent behavior TestICollectionInterfaceImpl(ImmutableList.Create(600, 601), supportsNullValues: false); TestICollectionInterfaceImpl(ImmutableList.Create <int?>(600, 601), supportsNullValues: true); TestICollectionInterfaceImpl(ImmutableList.Create <object>(600, 601), supportsNullValues: true); }
public TerminatingChildrenContainer(IImmutableMap <string, IChildStats> children, IActorRef toDie, SuspendReason reason) : this(children, ImmutableTreeSet <IActorRef> .Create(toDie), reason) { //Intentionally left blank }
public void TestImmutableTreeSetCreateValidation() { Assert.Throws <ArgumentNullException>("other", () => ImmutableTreeSet.Create(default(int[]) !)); Assert.Throws <ArgumentNullException>("other", () => ImmutableTreeSet.Create(EqualityComparer <int> .Default, default(int[]) !)); }