Skip to content

Commit

Permalink
add AdlAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Nov 9, 2023
1 parent 18a2002 commit ca10bc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/a-d/Adl/Adl.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ public static IEnumerable<AdlResult> GetAdl<TQuote>(
where TQuote : IQuote => quotes
.ToQuoteD()
.CalcAdl(smaPeriods);

// TASK, from TQuote
/// <include file='./info.xml' path='info/*' />
///
public static Task<IEnumerable<AdlResult>> GetAdlAsync<TQuote>(
this IEnumerable<TQuote> quotes,
int? smaPeriods = null)
where TQuote : IQuote => Task.Run(() => quotes
.GetAdl(smaPeriods));
}
25 changes: 25 additions & 0 deletions tests/indicators/a-d/Adl/Adl.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ public void Standard()
Assert.AreEqual(null, r2.AdlSma);
}

[TestMethod]
public async Task Async()
{
List<AdlResult> ogList = quotes
.GetAdl()
.ToList();

IEnumerable<AdlResult> results = await quotes
.GetAdlAsync()
.ConfigureAwait(false);

List<AdlResult> rsList = results.ToList();

Assert.AreEqual(ogList.Count, rsList.Count);

for (int i = 0; i < rsList.Count; i++)
{
AdlResult o = ogList[i];
AdlResult r = rsList[i];

Assert.AreEqual(o.Date, r.Date);
Assert.AreEqual(o.Adl, r.Adl);
}
}

[TestMethod]
public void WithSma()
{
Expand Down

0 comments on commit ca10bc9

Please sign in to comment.