Skip to content

Commit

Permalink
chore: more tests (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender authored Jun 26, 2022
1 parent 869e8fe commit 4c8e83e
Show file tree
Hide file tree
Showing 70 changed files with 699 additions and 216 deletions.
17 changes: 6 additions & 11 deletions src/m-r/PivotPoints/PivotPoints.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ internal static List<PivotPointsResult> CalcPivotPoints<TQuote>(

int windowId = GetWindowNumber(h0.Date, windowSize);

if (windowId == 0)
{
throw new ArgumentOutOfRangeException(nameof(windowSize), windowSize,
string.Format(
EnglishCulture,
"Pivot Points does not support PeriodSize of {0}. See documentation for valid options.",
Enum.GetName(typeof(PeriodSize), windowSize)));
}

int windowEval;
bool firstWindow = true;

Expand Down Expand Up @@ -215,7 +206,7 @@ internal static TPivotPoint GetPivotPointWoodie<TPivotPoint>(
PivotPointType.Demark => GetPivotPointDemark<TPivotPoint>(open, high, low, close),
PivotPointType.Fibonacci => GetPivotPointFibonacci<TPivotPoint>(high, low, close),
PivotPointType.Woodie => GetPivotPointWoodie<TPivotPoint>(open, high, low),
_ => default
_ => throw new ArgumentOutOfRangeException(nameof(pointType), pointType, "Invalid pointType provided.")
};

// window size lookup
Expand All @@ -226,6 +217,10 @@ private static int GetWindowNumber(DateTime d, PeriodSize windowSize)
PeriodSize.Week => EnglishCalendar.GetWeekOfYear(d, EnglishCalendarWeekRule, EnglishFirstDayOfWeek),
PeriodSize.Day => d.Day,
PeriodSize.OneHour => d.Hour,
_ => 0
_ => throw new ArgumentOutOfRangeException(nameof(windowSize), windowSize,
string.Format(
EnglishCulture,
"Pivot Points does not support PeriodSize of {0}. See documentation for valid options.",
Enum.GetName(typeof(PeriodSize), windowSize)))
};
}
96 changes: 84 additions & 12 deletions tests/indicators/_common/Test.QuoteUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ public class QuoteUtility : TestBase
public void QuoteToBasicTuple()
{
DateTime d = DateTime.Parse("5/5/2055", EnglishCulture);
Random rand = new();

decimal o = 10000m * (decimal)rand.NextDouble();
decimal h = 10000m * (decimal)rand.NextDouble();
decimal l = 10000m * (decimal)rand.NextDouble();
decimal c = 10000m * (decimal)rand.NextDouble();
decimal v = 10000m * (decimal)rand.NextDouble();
decimal l = 111111111111111m;
decimal o = 222222222222222m;
decimal c = 333333333333333m;
decimal h = 444444444444444m;
decimal v = 555555555555555m;
decimal hl2 = (h + l) / 2m;
decimal hlc3 = (h + l + c) / 3m;
decimal oc2 = (o + c) / 2m;
Expand Down Expand Up @@ -63,19 +62,88 @@ public void QuoteToBasicTuple()
Assert.AreEqual(
NullMath.Round((double)ohlc4, 10),
NullMath.Round(q.ToBasicTuple(CandlePart.OHLC4).Item2, 10));

// bad argument
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
q.ToBasicTuple((CandlePart)999));

// bad argument
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
q.ToBasicData((CandlePart)999));
}

[TestMethod]
public void QuoteToBasicData()
{
DateTime d = DateTime.Parse("5/5/2055", EnglishCulture);

decimal l = 111111111111111m;
decimal o = 222222222222222m;
decimal c = 333333333333333m;
decimal h = 444444444444444m;
decimal v = 555555555555555m;
decimal hl2 = (h + l) / 2m;
decimal hlc3 = (h + l + c) / 3m;
decimal oc2 = (o + c) / 2m;
decimal ohl3 = (o + h + l) / 3m;
decimal ohlc4 = (o + h + l + c) / 4m;

Quote q = new()
{
Date = d,
Open = o,
High = h,
Low = l,
Close = c,
Volume = v
};

Assert.AreEqual(
NullMath.Round((double)o, 10),
NullMath.Round(q.ToBasicData(CandlePart.Open).Value, 10));
Assert.AreEqual(
NullMath.Round((double)h, 10),
NullMath.Round(q.ToBasicData(CandlePart.High).Value, 10));
Assert.AreEqual(
NullMath.Round((double)l, 10),
NullMath.Round(q.ToBasicData(CandlePart.Low).Value, 10));
Assert.AreEqual(
NullMath.Round((double)c, 10),
NullMath.Round(q.ToBasicData(CandlePart.Close).Value, 10));
Assert.AreEqual(
NullMath.Round((double)v, 10),
NullMath.Round(q.ToBasicData(CandlePart.Volume).Value, 10));
Assert.AreEqual(
NullMath.Round((double)hl2, 10),
NullMath.Round(q.ToBasicData(CandlePart.HL2).Value, 10));
Assert.AreEqual(
NullMath.Round((double)hlc3, 10),
NullMath.Round(q.ToBasicData(CandlePart.HLC3).Value, 10));
Assert.AreEqual(
NullMath.Round((double)oc2, 10),
NullMath.Round(q.ToBasicData(CandlePart.OC2).Value, 10));
Assert.AreEqual(
NullMath.Round((double)ohl3, 10),
NullMath.Round(q.ToBasicData(CandlePart.OHL3).Value, 10));
Assert.AreEqual(
NullMath.Round((double)ohlc4, 10),
NullMath.Round(q.ToBasicData(CandlePart.OHLC4).Value, 10));

// bad argument
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
q.ToBasicData((CandlePart)999));
}

[TestMethod]
public void QuoteDToBasicTuple()
{
DateTime d = DateTime.Parse("5/5/2055", EnglishCulture);
Random rand = new();

double o = 10000 * rand.NextDouble();
double h = 10000 * rand.NextDouble();
double l = 10000 * rand.NextDouble();
double c = 10000 * rand.NextDouble();
double v = 10000 * rand.NextDouble();
double l = 111111111111111;
double o = 222222222222222;
double c = 333333333333333;
double h = 444444444444444;
double v = 555555555555555;
double hl2 = (h + l) / 2;
double hlc3 = (h + l + c) / 3;
double oc2 = (o + c) / 2;
Expand Down Expand Up @@ -122,5 +190,9 @@ public void QuoteDToBasicTuple()
Assert.AreEqual(
NullMath.Round((double)ohlc4, 10),
NullMath.Round(q.ToBasicTuple(CandlePart.OHLC4).Item2, 10));

// bad argument
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
q.ToBasicTuple((CandlePart)999));
}
}
2 changes: 1 addition & 1 deletion tests/indicators/a-d/Adl/Adl.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void WithSma()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetAdl()
Expand Down
2 changes: 1 addition & 1 deletion tests/indicators/a-d/Adx/Adx.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Standard()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetAdx(14)
Expand Down
18 changes: 16 additions & 2 deletions tests/indicators/a-d/Alligator/Alligator.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,24 @@ public void Standard()
}

[TestMethod]
public void Use()
public void UseTuple()
{
IEnumerable<AlligatorResult> results = quotes
.Use(CandlePart.Close)
.Use(CandlePart.HL2)
.GetAlligator();

Assert.AreEqual(502, results.Count());
Assert.AreEqual(482, results.Where(x => x.Jaw != null).Count());

AlligatorResult last = results.LastOrDefault();
Assert.AreEqual(244.29591, NullMath.Round(last.Lips, 5));
}

[TestMethod]
public void Chainee()
{
IEnumerable<AlligatorResult> results = quotes
.GetSma(1)
.GetAlligator();

Assert.AreEqual(502, results.Count());
Expand Down
42 changes: 21 additions & 21 deletions tests/indicators/a-d/Alma/Alma.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,44 @@ public void Standard()
}

[TestMethod]
public void Use()
public void UseTuple()
{
IEnumerable<AlmaResult> results = quotes
.Use(CandlePart.Close)
.GetAlma(10, 0.86, 6);
.GetAlma(10, 0.85, 6);

Assert.AreEqual(502, results.Count());
Assert.AreEqual(493, results.Where(x => x.Alma != null).Count());

AlmaResult last = results.LastOrDefault();
Assert.AreEqual(242.1871, NullMath.Round(last.Alma, 4));
}

[TestMethod]
public void Chainee()
{
IEnumerable<AlmaResult> results = quotes
.GetSma(1)
.GetAlma(10, 0.85, 6);

Assert.AreEqual(502, results.Count());
Assert.AreEqual(493, results.Where(x => x.Alma != null).Count());
}

[TestMethod]
public void Chaining()
public void Chainor()
{
int lookbackPeriods = 10;
double offset = 0.85;
double sigma = 6;

List<AlmaResult> standard = quotes
.GetAlma(lookbackPeriods, offset, sigma)
.ToList();

List<AlmaResult> results = quotes
.Use(CandlePart.Close)
List<SmaResult> results = quotes
.GetAlma(lookbackPeriods, offset, sigma)
.GetSma(10)
.ToList();

// assertions
Assert.AreEqual(502, results.Count);
Assert.AreEqual(493, results.Where(x => x.Alma != null).Count());

for (int i = 0; i < results.Count; i++)
{
AlmaResult s = standard[i];
AlmaResult c = results[i];

Assert.AreEqual(s.Date, c.Date);
Assert.AreEqual(s.Alma, c.Alma);
}
Assert.AreEqual(493, results.Count);
Assert.AreEqual(484, results.Where(x => x.Sma != null).Count());
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion tests/indicators/a-d/Aroon/Aroon.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Standard()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetAroon(25)
Expand Down
2 changes: 1 addition & 1 deletion tests/indicators/a-d/Atr/Atr.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Standard()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetAtr(10)
Expand Down
15 changes: 13 additions & 2 deletions tests/indicators/a-d/Awesome/Awesome.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Standard()
}

[TestMethod]
public void Use()
public void UseTuple()
{
IEnumerable<AwesomeResult> results = quotes
.Use(CandlePart.Close)
Expand All @@ -48,7 +48,18 @@ public void Use()
}

[TestMethod]
public void Chained()
public void Chainee()
{
IEnumerable<AwesomeResult> results = quotes
.GetSma(1)
.GetAwesome();

Assert.AreEqual(502, results.Count());
Assert.AreEqual(469, results.Where(x => x.Oscillator != null).Count());
}

[TestMethod]
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetAwesome()
Expand Down
6 changes: 3 additions & 3 deletions tests/indicators/a-d/BasicQuote/BasicQuote.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public void Standard()
}

[TestMethod]
public void Use()
public void UseTuple()
{
var results = quotes
IEnumerable<(DateTime Date, double Value)> results = quotes
.Use(CandlePart.Close);

Assert.AreEqual(502, results.Count());
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetBaseQuote(CandlePart.Close)
Expand Down
4 changes: 2 additions & 2 deletions tests/indicators/a-d/Beta/Beta.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void Down()
}

[TestMethod]
public void Use()
public void UseTuple()
{
IEnumerable<BetaResult> results = otherQuotes
.Use(CandlePart.Close)
Expand All @@ -123,7 +123,7 @@ public void Use()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = otherQuotes
.GetBeta(quotes, 20)
Expand Down
15 changes: 13 additions & 2 deletions tests/indicators/a-d/BollingerBands/BollingerBands.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Standard()
}

[TestMethod]
public void Use()
public void UseTuple()
{
IEnumerable<BollingerBandsResult> results = quotes
.Use(CandlePart.Close)
Expand All @@ -55,7 +55,18 @@ public void Use()
}

[TestMethod]
public void Chained()
public void Chainee()
{
IEnumerable<BollingerBandsResult> results = quotes
.GetSma(1)
.GetBollingerBands();

Assert.AreEqual(502, results.Count());
Assert.AreEqual(483, results.Where(x => x.UpperBand != null).Count());
}

[TestMethod]
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetBollingerBands()
Expand Down
2 changes: 1 addition & 1 deletion tests/indicators/a-d/Bop/Bop.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Standard()
}

[TestMethod]
public void Chained()
public void Chainor()
{
IEnumerable<SmaResult> results = quotes
.GetBop(14)
Expand Down
Loading

0 comments on commit 4c8e83e

Please sign in to comment.