Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lag : Add test #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions MoreLinq.Test/LagTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace MoreLinq.Test
{
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using System.Collections.Generic;

/// <summary>
/// Verify the behavior of the Lag operator
Expand Down Expand Up @@ -114,5 +133,20 @@ public void TestLagPassesCorrectLagValuesOffsetBy2()
Assert.IsTrue(result.Skip(2).All(x => x.B == (x.A - 2)));
Assert.IsTrue(result.Take(2).All(x => (x.A - x.B) == x.A));
}

public static readonly IEnumerable<ITestCaseData> TestData =
from e in new[]
{
new {s = new[] {1, 2, 3}, o = 1, r = new[] {(1, 0), (2, 1), (3, 2)}},
new {s = new[] {1, 2, 3}, o = 2, r = new[] {(1, 0), (2, 0), (3, 1)}},
new {s = new[] {1, 2, 3}, o = 3, r = new[] {(1, 0), (2, 0), (3, 0)}}
}
select new TestCaseData(e.s, e.o).Returns(e.r);

[Test, TestCaseSource(nameof(TestData))]
public (int e, int l)[] TestLagOnKnownInput(int[] source, int offset)
{
return source.AsTestingSequence().Lag(offset, (e, l) => (e, l)).ToArray();
}
}
}