For.cs 828 B

123456789101112131415161718192021222324252627
  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 For : Tests
  10. {
  11. [Fact]
  12. public void For_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.For<int, int>(null, x => new[] { 1 }));
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.For<int, int>(new[] { 1 }, null));
  16. }
  17. [Fact]
  18. public void For1()
  19. {
  20. var res = EnumerableEx.For(new[] { 1, 2, 3 }, x => Enumerable.Range(0, x)).ToList();
  21. Assert.True(res.SequenceEqual(new[] { 0, 0, 1, 0, 1, 2 }));
  22. }
  23. }
  24. }