GenerateTest.cs 1.0 KB

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