ExpandTest.cs 1.2 KB

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