Sonarcloud fixes

This commit is contained in:
Miha Kralj
2024-09-30 15:53:48 -07:00
parent ad3aa37978
commit 697fa19cfa
17 changed files with 36 additions and 34 deletions
+8 -7
View File
@@ -6,12 +6,13 @@ public class TulipTests
{
private readonly TBarSeries bars;
private readonly GbmFeed feed;
private Random rnd;
private readonly Random rnd;
private readonly double range;
private int period, iterations;
private int period;
private int readonly iterations;
private readonly double[] data;
private readonly double[] outdata;
private int skip;
private readonly int skip;
public TulipTests()
{
@@ -44,7 +45,7 @@ public class TulipTests
for (int i = QL.Length - 1; i > skip; i--)
{
double QL_item = QL[i].Value;
double TU = i<period-1?double.NaN:arrout[0][i-period+1];
double TU = i < period - 1 ? double.NaN : arrout[0][i - period + 1];
Assert.InRange(TU - QL_item, -range, range);
}
}
@@ -60,18 +61,18 @@ public class TulipTests
Ema ma = new(period, useSma: false);
TSeries QL = new();
foreach (TBar item in feed)
{ QL.Add(ma.Calc(new TValue(item.Time, item.Close))); }
{ QL.Add(ma.Calc(new TValue(item.Time, item.Close))); }
double[][] arrin = [data];
double[][] arrout = [outdata];
Tulip.Indicators.ema.Run(inputs: arrin, options: [period], outputs: arrout);
Assert.Equal(QL.Length, arrout[0].Length);
for (int i = QL.Length - 1; i > skip*2; i--) //Initial Tulip Ema value is (wrongly) set to the first input value - therefore large skip
for (int i = QL.Length - 1; i > skip * 2; i--) //Initial Tulip Ema value is (wrongly) set to the first input value - therefore large skip
{
double QL_item = QL[i].Value;
double TU = arrout[0][i];
Assert.True(Math.Abs(TU - QL_item) <= range, $"Assertion failed at index {i} for period {period}: TU = {TU}, QL_item = {QL_item}, delta = {TU-QL_item}");
Assert.True(Math.Abs(TU - QL_item) <= range, $"Assertion failed at index {i} for period {period}: TU = {TU}, QL_item = {QL_item}, delta = {TU - QL_item}");
}
}