Skip to content

Commit

Permalink
add missing Average() test
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Nov 2, 2024
1 parent 6bc1cc1 commit 1d6e355
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/s-z/Sma/Sma.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ public static partial class Sma
/// if incalculable <see langword="double.NaN"/>
/// values are in range.
/// </returns>
internal static double? Average<T>(
public static double? Average<T>(
this IReadOnlyList<T> values,
int lookbackPeriods,
int? endIndex = null)
where T : IReusable
{
ArgumentNullException.ThrowIfNull(values);

// TODO: unused SMA utility, either make public or remove

=> Increment(
return Increment(
values,
lookbackPeriods,
endIndex ?? values.Count - 1)
.NaN2Null();
}

/// <summary>
/// Simple moving average calculation
Expand Down
2 changes: 1 addition & 1 deletion tests/external/integration/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
2 changes: 1 addition & 1 deletion tests/indicators/s-z/Sma/Sma.StaticSeries.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace StaticSeries;

[TestClass]
public class Sma : StaticSeriesTestBase
public partial class Sma : StaticSeriesTestBase
{
[TestMethod]
public override void Standard()
Expand Down
23 changes: 23 additions & 0 deletions tests/indicators/s-z/Sma/Sma.Utilities.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace StaticSeries;

public partial class Sma : StaticSeriesTestBase
{
[TestMethod]
public void Average()
{
QuotePart[] results = new[]
{
new QuotePart(Quotes[0].Timestamp, 0.0),
new QuotePart(Quotes[1].Timestamp, 4.0),
new QuotePart(Quotes[2].Timestamp, 8.0)
};

// sut
double? mid = results.Average(2, 1);
double? end = results.Average(2);

// assert
mid.Should().Be(2);
end.Should().Be(6);
}
}

0 comments on commit 1d6e355

Please sign in to comment.