Generate.cs 977 B

12345678910111213141516171819202122232425262728
  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 Generate : Tests
  10. {
  11. [Fact]
  12. public void Generate_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.Generate<int, int>(0, null, _ => _, _ => _));
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Generate<int, int>(0, _ => true, null, _ => _));
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Generate<int, int>(0, _ => true, _ => _, null));
  17. }
  18. [Fact]
  19. public void Generate1()
  20. {
  21. var res = EnumerableEx.Generate(0, x => x < 5, x => x + 1, x => x * x).ToList();
  22. Assert.True(Enumerable.SequenceEqual(res, [0, 1, 4, 9, 16]));
  23. }
  24. }
  25. }