Expand.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Linq;
  6. using Xunit;
  7. namespace Tests
  8. {
  9. public class Expand : Tests
  10. {
  11. [Fact]
  12. public void Expand_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.Expand<int>(null, _ => new[] { _ }));
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Expand<int>(new[] { 1 }, null));
  16. }
  17. [Fact]
  18. public void Expand1()
  19. {
  20. var res = new[] { 0 }.Expand(x => new[] { x + 1 }).Take(10).ToList();
  21. Assert.True(Enumerable.SequenceEqual(res, Enumerable.Range(0, 10)));
  22. }
  23. [Fact]
  24. public void Expand2()
  25. {
  26. var res = new[] { 3 }.Expand(x => Enumerable.Range(0, x)).ToList();
  27. var exp = new[] {
  28. 3,
  29. 0, 1, 2,
  30. 0,
  31. 0, 1,
  32. 0
  33. };
  34. Assert.True(Enumerable.SequenceEqual(res, exp));
  35. }
  36. }
  37. }