public void Reverse() { var actual = MyEnumerable .Range(0, 5) .Reverse(); Assert.Equal(new[] { 4, 3, 2, 1, 0 }, actual); }
public void Select() { var actual = MyEnumerable .Range(0, 3) .Select(i => i * 2); Assert.Equal(new[] { 0, 2, 4 }, actual); }
public void Where() { var actual = MyEnumerable .Range(0, 5) .Where(i => i % 2 == 0); Assert.Equal(new[] { 0, 2, 4 }, actual); }
public void Take() { var actual = MyEnumerable .Range(0, 5) .Take(3); Assert.Equal(new[] { 0, 1, 2 }, actual); }
public void SelectMany() { var numbers = MyEnumerable.Range(1, 2); var letters = new[] { 'A', 'B' }; var actual = numbers.SelectMany(num => letters, Tuple.Create); Assert.Equal(new[] { Tuple.Create(1, 'A'), Tuple.Create(1, 'B'), Tuple.Create(2, 'A'), Tuple.Create(2, 'B') }, actual); }
public void SelectManyCartesianProduct() { var numbers = MyEnumerable.Range(1, 3); var letters = new[] { 'x', 'y', 'z' }; var actual = numbers.SelectMany( number => letters, Tuple.Create ); CollectionAssert.AreEqual( new[] { Tuple.Create(1, 'x'), Tuple.Create(1, 'y'), Tuple.Create(1, 'z'), Tuple.Create(2, 'x'), Tuple.Create(2, 'y'), Tuple.Create(2, 'z'), Tuple.Create(3, 'x'), Tuple.Create(3, 'y'), Tuple.Create(3, 'z') }, actual); }
public void ReverseTest() { var actual = MyEnumerable.Range(1, 5).Reverse(); CollectionAssert.AreEqual(new[] { 5, 4, 3, 2, 1 }, actual); }
public void RangeTest() { var actual = MyEnumerable.Range(1, 10); CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual); }
public void Range() { var actual = MyEnumerable.Range(0, 5); Assert.Equal(new[] { 0, 1, 2, 3, 4 }, actual); }