ScanTest.cs 1.3 KB

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