Optimizations.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Linq;
  5. using Xunit;
  6. namespace Tests
  7. {
  8. public class Optimizations : AsyncEnumerableTests
  9. {
  10. [Fact]
  11. public void SelectWhere2()
  12. {
  13. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  14. var ys = xs.Select(i => i + 2).Where(i => i % 2 == 0);
  15. var e = ys.GetAsyncEnumerator();
  16. HasNext(e, 2);
  17. HasNext(e, 4);
  18. NoNext(e);
  19. }
  20. [Fact]
  21. public void WhereSelect2()
  22. {
  23. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  24. var ys = xs.Where(i => i % 2 == 0).Select(i => i + 2);
  25. var e = ys.GetAsyncEnumerator();
  26. HasNext(e, 2);
  27. HasNext(e, 4);
  28. NoNext(e);
  29. }
  30. [Fact]
  31. public void WhereSelect3()
  32. {
  33. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  34. var ys = xs.Where(i => i % 2 == 0).Select(i => i + 2).Select(i => i + 2);
  35. var e = ys.GetAsyncEnumerator();
  36. HasNext(e, 4);
  37. HasNext(e, 6);
  38. NoNext(e);
  39. }
  40. }
  41. }