1
0

ForTest.cs 871 B

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