Scan.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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 Scan : Tests
  10. {
  11. [Fact]
  12. public void Scan_Arguments()
  13. {
  14. AssertThrows<ArgumentNullException>(() => EnumerableEx.Scan<int>(null, (x, y) => x + y));
  15. AssertThrows<ArgumentNullException>(() => EnumerableEx.Scan<int>([1], null));
  16. AssertThrows<ArgumentNullException>(() => EnumerableEx.Scan<int, int>(null, 0, (x, y) => x + y));
  17. AssertThrows<ArgumentNullException>(() => EnumerableEx.Scan<int, int>([1], 0, null));
  18. }
  19. [Fact]
  20. public void Scan1()
  21. {
  22. var res = Enumerable.Range(0, 5).Scan((n, x) => n + x).ToList();
  23. Assert.True(Enumerable.SequenceEqual(res, [1, 3, 6, 10]));
  24. }
  25. [Fact]
  26. public void Scan2()
  27. {
  28. var res = Enumerable.Range(0, 5).Scan(10, (n, x) => n - x).ToList();
  29. Assert.True(Enumerable.SequenceEqual(res, [10, 9, 7, 4, 0]));
  30. }
  31. }
  32. }