public void RemoveAtTest() { try { int[] removeAt = Enumerable.Range(0, 5).RemoveAt(-1).ToArray(); Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString()))); } catch (ArgumentOutOfRangeException exception) { Assert.AreEqual("index", exception.ParamName); } EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(0)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(1)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).RemoveAt(2)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).RemoveAt(3)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).RemoveAt(4)); try { int[] removeAt = Enumerable.Range(0, 5).RemoveAt(5).ToArray(); Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString()))); } catch (ArgumentOutOfRangeException exception) { Assert.AreEqual("index", exception.ParamName); } try { int[] removeAt = Enumerable.Range(0, 5).RemoveAt(6).ToArray(); Assert.Fail(string.Join(", ", removeAt.Select(int32 => int32.ToString()))); } catch (ArgumentOutOfRangeException exception) { Assert.AreEqual("index", exception.ParamName); } }
public void TakeTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Take(enumerable, 2), EnumerableExtensions.Take(enumerable, 2)); enumerable = new int[] { 0, 1, 1, 1, 2, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Take(enumerable, 0), EnumerableExtensions.Take(enumerable, 0)); enumerable = new int[] { 0, 1, 1, 1, 2, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Take(enumerable, -1), EnumerableExtensions.Take(enumerable, -1)); enumerable = new int[] { 0, 1, 1, 1, 2, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Take(enumerable, 100), EnumerableExtensions.Take(enumerable, 100)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Take(enumerable, 100), EnumerableExtensions.Take(enumerable, 100)); }
public void InsertTest() { try { int[] insert = Enumerable.Range(0, 5).Insert(-1, 5).ToArray(); Assert.Fail(string.Join(", ", insert.Select(int32 => int32.ToString()))); } catch (ArgumentOutOfRangeException exception) { Assert.AreEqual("index", exception.ParamName); } EnumerableAssert.AreSequentialEqual(new int[] { 5, 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(0, 5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 5, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(1, 5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 5, 2, 3, 4 }, Enumerable.Range(0, 5).Insert(2, 5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 5, 3, 4 }, Enumerable.Range(0, 5).Insert(3, 5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 5, 4 }, Enumerable.Range(0, 5).Insert(4, 5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4, 5 }, Enumerable.Range(0, 5).Insert(5, 5)); try { int[] insert = Enumerable.Range(0, 5).Insert(6, 5).ToArray(); Assert.Fail(string.Join(", ", insert.Select(int32 => int32.ToString()))); } catch (ArgumentOutOfRangeException exception) { Assert.AreEqual("index", exception.ParamName); } }
public void ExceptTest() { int[] first = new int[] { 0, 1, 2 }; int[] second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Except(first, second), EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default)); first = new int[] { 0, 1, 2 }; second = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Except(first, second), EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default)); first = new int[] { }; second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Except(first, second), EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default)); first = new int[] { 0, 1, 2 }; second = new int[] { 2, 3, 4 }; EnumerableAssert.AreSequentialEqual( Enumerable.Except(first, second), EnumerableExtensions.Except(first, second, EqualityComparer <int> .Default)); }
public void RemoveTest() { EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(-1)); EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(0)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(1)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).Remove(2)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).Remove(3)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).Remove(4)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Remove(6)); }
public void Reverse2Test() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Reverse(enumerable), DeferredExecution.CompiledReverseGenerator(enumerable)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Reverse(enumerable), DeferredExecution.CompiledReverseGenerator(enumerable)); }
public void EnumerableTest() { EnumerableAssert.AreSequentialEqual( EnumerableEx.Return(1), IteratorPattern.FromValue(1)); object value = new object(); EnumerableAssert.AreSequentialEqual( EnumerableEx.Return(value), IteratorPattern.FromValue(value)); }
public void WhereTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), IteratorPattern.Where(enumerable, x => x > 0)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), IteratorPattern.Where(enumerable, x => x > 0)); }
public void DistinctTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Distinct(enumerable), EnumerableExtensions.Distinct(enumerable, EqualityComparer <int> .Default)); enumerable = new int[] { 0, 1, 1, 1, 2, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Distinct(enumerable), EnumerableExtensions.Distinct(enumerable, EqualityComparer <int> .Default)); }
public void WhereTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), EnumerableExtensions.Where(enumerable, x => x > 0)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), EnumerableExtensions.Where(enumerable, x => x > 0)); }
public void SelectTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Select(enumerable, x => x.ToString()), EnumerableExtensions.Select(enumerable, x => x.ToString())); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Select(enumerable, x => x.ToString()), EnumerableExtensions.Select(enumerable, x => x.ToString())); }
public void SelectTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Select(enumerable, x => x.ToString()), IteratorPattern.Select(enumerable, x => x.ToString())); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Select(enumerable, x => x.ToString()), IteratorPattern.Select(enumerable, x => x.ToString())); }
public void MultipleTest() { SinglyLinkedListNode <int> head = new SinglyLinkedListNode <int>(0, new SinglyLinkedListNode <int>(1, new SinglyLinkedListNode <int>(2, new SinglyLinkedListNode <int>(3)))); LinkedListSequence <int> sequence = new LinkedListSequence <int>(head); List <int> list = new List <int>(); foreach (int value in sequence) { list.Add(value); } EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, list); }
public void RemoveAllTest() { EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(-1)); EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(0)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(1)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(2)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 4 }, Enumerable.Range(0, 5).RemoveAll(3)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3 }, Enumerable.Range(0, 5).RemoveAll(4)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(5)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 4 }, Enumerable.Range(0, 5).RemoveAll(6)); EnumerableAssert.AreSequentialEqual(new int[] { }, Enumerable.Repeat(0, 5).RemoveAll(0)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 0, 0, 0, 0 }, Enumerable.Repeat(0, 5).RemoveAll(1)); EnumerableAssert.AreSequentialEqual(new int[] { 0, 1, 2, 3, 0, 1, 2, 3 }, Enumerable.Range(0, 5).Concat(Enumerable.Range(0, 5)).RemoveAll(4)); EnumerableAssert.AreSequentialEqual(new int[] { 1, 2, 3, 4, 1, 2, 3, 4 }, Enumerable.Range(0, 5).Concat(Enumerable.Range(0, 5)).RemoveAll(0)); }
public void TakeWhileTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.TakeWhile(enumerable, x => x > 0), EnumerableExtensions.TakeWhile(enumerable, x => x > 0)); enumerable = new int[] { 2, 1, 0, -1 }; EnumerableAssert.AreSequentialEqual( Enumerable.TakeWhile(enumerable, x => x > 0), EnumerableExtensions.TakeWhile(enumerable, x => x > 0)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.TakeWhile(enumerable, x => x > 0), EnumerableExtensions.TakeWhile(enumerable, x => x > 0)); }
public void RetryTest() { int count = 0; int[] retry = EnumerableX.Create(() => { count++; if (count < 5) { throw new OperationCanceledException(); } return(count); }) .Take(2) .Retry <int, OperationCanceledException>(5) .ToArray(); EnumerableAssert.AreSequentialEqual(new int[] { 5, 6 }, retry); }
public void RepeatTest() { EnumerableAssert.AreSequentialEqual( Enumerable.Repeat(1, 5), IteratorPattern.Repeat(1, 5)); EnumerableAssert.AreSequentialEqual( Enumerable.Repeat(1, 0), IteratorPattern.Repeat(1, 0)); EnumerableAssert.AreSequentialEqual( Enumerable.Repeat(1, 1), IteratorPattern.Repeat(1, 1)); object value = new object(); EnumerableAssert.AreSequentialEqual( Enumerable.Repeat(value, 10), IteratorPattern.Repeat(value, 10)); }
public void ConcatTest() { int[] first = new int[] { 0, 1, 2 }; int[] second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Concat(first, second), EnumerableExtensions.Concat(first, second)); first = new int[] { }; second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Concat(first, second), EnumerableExtensions.Concat(first, second)); first = new int[] { 0, 1, 2 }; second = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Concat(first, second), EnumerableExtensions.Concat(first, second)); }
public void GroupByTest() { int[] enumerable = new int[] { 0, 1, 2, 4, 5, 6 }; IGrouping <int, int>[] expected = Enumerable.ToArray(Enumerable.GroupBy(enumerable, value => value % 3, value => value)); IGrouping <int, int>[] actual = Enumerable.ToArray(EnumerableExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default)); Assert.AreEqual(Enumerable.Count(expected), Enumerable.Count(actual)); expected.ForEach((group, index) => { Assert.AreEqual(group.Key, actual[index].Key); EnumerableAssert.AreSequentialEqual(group, actual[index]); }); enumerable = new int[] { }; expected = Enumerable.ToArray(Enumerable.GroupBy(enumerable, value => value % 3, value => value)); actual = Enumerable.ToArray(EnumerableExtensions.GroupBy(enumerable, value => value % 3, value => value, EqualityComparer <int> .Default)); Assert.AreEqual(Enumerable.Count(expected), Enumerable.Count(actual)); expected.ForEach((group, index) => { Assert.AreEqual(group.Key, actual[index].Key); EnumerableAssert.AreSequentialEqual(group, actual[index]); }); }
public void ZipTest() { int[] first = new int[] { 0, 1, 2 }; int[] second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); first = new int[] { 0, 1, 2 }; second = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); first = new int[] { }; second = new int[] { 3, 4, 5 }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); first = new int[] { 0, 1, 2 }; second = new int[] { 2, 3, 4 }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); first = new int[] { 0, 1 }; second = new int[] { 2, 3, 4 }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); first = new int[] { 0, 1, 2 }; second = new int[] { 2, 3 }; EnumerableAssert.AreSequentialEqual( Enumerable.Zip(first, second, (x, y) => x * y), EnumerableExtensions.Zip(first, second, (x, y) => x * y)); }