// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. // See the LICENSE file in the project root for more information. using System; using System.Linq; using Xunit; namespace Tests { public class Scan : Tests { [Fact] public void Scan_Arguments() { AssertThrows(() => EnumerableEx.Scan(null, (x, y) => x + y)); AssertThrows(() => EnumerableEx.Scan([1], null)); AssertThrows(() => EnumerableEx.Scan(null, 0, (x, y) => x + y)); AssertThrows(() => EnumerableEx.Scan([1], 0, null)); } [Fact] public void Scan1() { var res = Enumerable.Range(0, 5).Scan((n, x) => n + x).ToList(); Assert.True(Enumerable.SequenceEqual(res, [1, 3, 6, 10])); } [Fact] public void Scan2() { var res = Enumerable.Range(0, 5).Scan(10, (n, x) => n - x).ToList(); Assert.True(Enumerable.SequenceEqual(res, [10, 9, 7, 4, 0])); } } }