public void RemoveRangeEnumerableTest() { var list = ImmutableTrieList.Create(1, 2, 3); Assert.Throws <ArgumentNullException>("items", () => list.RemoveRange(null)); ImmutableTrieList <int> removed2 = list.RemoveRange(new[] { 2 }); Assert.Equal(2, removed2.Count); Assert.Equal(new[] { 1, 3 }, removed2); ImmutableTrieList <int> removed13 = list.RemoveRange(new[] { 1, 3, 5 }); Assert.Equal(1, removed13.Count); Assert.Equal(new[] { 2 }, removed13); Assert.Equal(new[] { 2 }, ((IImmutableList <int>)list).RemoveRange(new[] { 1, 3, 5 })); Assert.Same(list, list.RemoveRange(new[] { 5 })); Assert.Same(ImmutableTrieList.Create <int>(), ImmutableTrieList.Create <int>().RemoveRange(new[] { 1 })); var listWithDuplicates = ImmutableTrieList.Create(1, 2, 2, 3); Assert.Equal(new[] { 1, 2, 3 }, listWithDuplicates.RemoveRange(new[] { 2 })); Assert.Equal(new[] { 1, 3 }, listWithDuplicates.RemoveRange(new[] { 2, 2 })); Assert.Throws <ArgumentNullException>("items", () => ((IImmutableList <int>)ImmutableTrieList.Create(1, 2, 3)).RemoveRange(null)); Assert.Equal(new[] { 1, 3 }, ((IImmutableList <int>)ImmutableTrieList.Create(1, 2, 3)).RemoveRange(new[] { 2 })); }
public void CopyToTest() { var listQuery = this.GetListQuery(ImmutableTrieList.Create(1, 2)); var list = (IEnumerable <int>)listQuery; var array = new int[2]; listQuery.CopyTo(array); Assert.Equal(list, array); array = new int[2]; listQuery.CopyTo(array, 0); Assert.Equal(list, array); array = new int[2]; listQuery.CopyTo(0, array, 0, listQuery.Count); Assert.Equal(list, array); array = new int[1]; // shorter than source length listQuery.CopyTo(0, array, 0, array.Length); Assert.Equal(list.Take(array.Length), array); array = new int[3]; listQuery.CopyTo(1, array, 2, 1); Assert.Equal(new[] { 0, 0, 2 }, array); array = new int[2]; ((ICollection)listQuery).CopyTo(array, 0); Assert.Equal(list, array); }
public void GetEnumeratorExplicit() { ICollection <int> builder = ImmutableTrieList.Create <int>().ToBuilder(); var enumerator = builder.GetEnumerator(); Assert.NotNull(enumerator); }
public void RemoveRange_EnumerableEqualityComparer_AcceptsNullEQ() { var list = ImmutableTrieList.Create(1, 2, 3); var removed2eq = list.RemoveRange(new[] { 2 }, null); Assert.Equal(2, removed2eq.Count); Assert.Equal(new[] { 1, 3 }, removed2eq); }
public void ReverseTest2() { var emptyList = ImmutableTrieList.Create <int>(); Assert.Same(emptyList, emptyList.Reverse()); var populatedList = ImmutableTrieList.Create(3, 2, 1); Assert.Equal(Enumerable.Range(1, 3), populatedList.Reverse()); }
public void IListOfTIsReadOnly() { IList <int> list = ImmutableTrieList.Create <int>(); Assert.True(list.IsReadOnly); Assert.Throws <NotSupportedException>(() => list.Add(1)); Assert.Throws <NotSupportedException>(() => list.Clear()); Assert.Throws <NotSupportedException>(() => list.Insert(0, 1)); Assert.Throws <NotSupportedException>(() => list.Remove(1)); Assert.Throws <NotSupportedException>(() => list.RemoveAt(0)); Assert.Throws <NotSupportedException>(() => list[0] = 1); }
/// <summary> /// Asserts that the <see cref="ImmutableList{T}"/> or <see cref="ImmutableList{T}.Builder"/>'s /// implementation of <see cref="IList"/> behave the same way <see cref="List{T}"/> does. /// </summary> /// <typeparam name="T">The type of the element for one collection to test with.</typeparam> /// <param name="operation"> /// The <see cref="IList"/> operation to perform. /// The function is provided with the <see cref="IList"/> implementation to test /// and the item to use as the argument to the operation. /// The function should return some equatable value by which to compare the effects /// of the operation across <see cref="IList"/> implementations. /// </param> /// <param name="item">The item to add to the collection.</param> /// <param name="other">The item to pass to the <paramref name="operation"/> function as the second parameter.</param> protected void AssertIListBaseline <T>(Func <IList, object, object> operation, T item, object other) { IList bclList = new List <T> { item }; IList testedList = (IList)this.GetListQuery(ImmutableTrieList.Create(item)); object expected = operation(bclList, other); object actual = operation(testedList, other); Assert.Equal(expected, actual); }
public void Remove_NullEqualityComparer() { var collection = ImmutableTrieList.Create(1, 2, 3); var modified = collection.Remove(2, null); Assert.Equal(new[] { 1, 3 }, modified); // Try again through the explicit interface implementation. IImmutableList <int> collectionIface = collection; var modified2 = collectionIface.Remove(2, null); Assert.Equal(new[] { 1, 3 }, modified2); }
public void RemoveRangeArrayTest() { Assert.True(ImmutableTrieList <int> .Empty.RemoveRange(0, 0).IsEmpty); var list = ImmutableTrieList.Create(1, 2, 3); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.RemoveRange(-1, 0)); Assert.Throws <ArgumentOutOfRangeException>("count", () => list.RemoveRange(0, -1)); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.RemoveRange(4, 0)); Assert.Throws <ArgumentOutOfRangeException>("count", () => list.RemoveRange(0, 4)); Assert.Throws <ArgumentOutOfRangeException>("count", () => list.RemoveRange(2, 2)); Assert.Equal(list, list.RemoveRange(3, 0)); }
public void SetItem() { var emptyList = ImmutableTrieList.Create <int>(); Assert.Throws <ArgumentOutOfRangeException>("index", () => emptyList[-1]); Assert.Throws <ArgumentOutOfRangeException>("index", () => emptyList[0]); Assert.Throws <ArgumentOutOfRangeException>("index", () => emptyList[1]); var listOfOne = emptyList.Add(5); Assert.Throws <ArgumentOutOfRangeException>("index", () => listOfOne[-1]); Assert.Equal(5, listOfOne[0]); Assert.Throws <ArgumentOutOfRangeException>("index", () => listOfOne[1]); }
public void InsertRangeImmutableTest() { var list = ImmutableTrieList <int> .Empty; var nonEmptyList = ImmutableTrieList.Create(1); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.InsertRange(1, nonEmptyList)); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.InsertRange(-1, nonEmptyList)); list = list.InsertRange(0, ImmutableTrieList.Create(1, 104, 105)); list = list.InsertRange(1, ImmutableTrieList.Create(2, 3)); list = list.InsertRange(2, ImmutableTrieList <int> .Empty); list = list.InsertRange(3, ImmutableTrieList <int> .Empty.InsertRange(0, Enumerable.Range(4, 100))); Assert.Equal(Enumerable.Range(1, 105), list); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.InsertRange(106, nonEmptyList)); Assert.Throws <ArgumentOutOfRangeException>("index", () => list.InsertRange(-1, nonEmptyList)); }
public void Create() { var comparer = StringComparer.OrdinalIgnoreCase; ImmutableTrieList <string> list = ImmutableTrieList.Create <string>(); Assert.Equal(0, list.Count); list = ImmutableTrieList.Create("a"); Assert.Equal(1, list.Count); list = ImmutableTrieList.Create("a", "b"); Assert.Equal(2, list.Count); list = ImmutableTrieList.CreateRange((IEnumerable <string>) new[] { "a", "b" }); Assert.Equal(2, list.Count); }
public void IListMembers() { IList list = ImmutableTrieList.Create <int>().ToBuilder(); Assert.False(list.IsReadOnly); Assert.False(list.IsFixedSize); Assert.Equal(0, list.Add(5)); Assert.Equal(1, list.Add(8)); Assert.True(list.Contains(5)); Assert.False(list.Contains(7)); list.Insert(1, 6); Assert.Equal(6, list[1]); list.Remove(5); list[0] = 9; Assert.Equal(new[] { 9, 8 }, list.Cast <int>().ToArray()); list.Clear(); Assert.Equal(0, list.Count); }
public void EnumeratorTest() { var list = ImmutableTrieList.Create("a"); var enumerator = list.GetEnumerator(); Assert.Throws <InvalidOperationException>(() => enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal("a", enumerator.Current); Assert.False(enumerator.MoveNext()); Assert.Throws <InvalidOperationException>(() => enumerator.Current); enumerator.Reset(); Assert.Throws <InvalidOperationException>(() => enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal("a", enumerator.Current); Assert.False(enumerator.MoveNext()); Assert.Throws <InvalidOperationException>(() => enumerator.Current); enumerator.Dispose(); Assert.Throws <ObjectDisposedException>(() => enumerator.Reset()); }
public void ReplaceWithEqualityComparerTest() { var list = ImmutableTrieList.Create(new Person { Name = "Andrew", Age = 20 }); var newAge = new Person { Name = "Andrew", Age = 21 }; var updatedList = list.Replace(newAge, newAge, new NameOnlyEqualityComparer()); Assert.Equal(newAge.Age, updatedList[0].Age); // Try again with a null equality comparer, which should use the default EQ. updatedList = list.Replace(list[0], newAge); Assert.NotSame(list, updatedList); // Finally, try one last time using the interface implementation. IImmutableList <Person> iface = list; var updatedIface = iface.Replace(list[0], newAge); Assert.NotSame(iface, updatedIface); }
public void EnumeratorRecyclingMisuse() { var collection = ImmutableTrieList.Create(1); var enumerator = collection.GetEnumerator(); var enumeratorCopy = enumerator; Assert.True(enumerator.MoveNext()); enumerator.Dispose(); Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext()); Assert.Throws <ObjectDisposedException>(() => enumerator.Reset()); Assert.Throws <ObjectDisposedException>(() => enumerator.Current); Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.MoveNext()); Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.Reset()); Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.Current); enumerator.Dispose(); // double-disposal should not throw enumeratorCopy.Dispose(); // We expect that acquiring a new enumerator will use the same underlying Stack<T> object, // but that it will not throw exceptions for the new enumerator. enumerator = collection.GetEnumerator(); Assert.True(enumerator.MoveNext()); Assert.Equal(collection[0], enumerator.Current); enumerator.Dispose(); }
public void IsReadOnly() { ICollection <int> builder = ImmutableTrieList.Create <int>().ToBuilder(); Assert.False(builder.IsReadOnly); }
public void IsSynchronized() { ICollection collection = ImmutableTrieList.Create <int>().ToBuilder(); Assert.False(collection.IsSynchronized); }
public void IsSynchronized() { ICollection collection = ImmutableTrieList.Create <int>(); Assert.True(collection.IsSynchronized); }
public void GetHashCodeVariesByInstance() { Assert.NotEqual(ImmutableTrieList.Create <int>().GetHashCode(), ImmutableTrieList.Create(5).GetHashCode()); }
public void ToImmutableListOfSameType() { var list = ImmutableTrieList.Create("a"); Assert.Same(list, list.ToImmutableTrieList()); }