sonarcloud workflow

This commit is contained in:
Miha Kralj
2024-10-05 19:36:01 -07:00
parent b6ecf537cd
commit 2dd680e9ee
15 changed files with 1389 additions and 1267 deletions
+5 -1
View File
@@ -2,7 +2,11 @@ using Xunit;
using Trady.Analysis.Indicator;
using Trady.Core;
using Trady.Core.Infrastructure;
using QuanTAlib;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class TradyTests
{
+4 -4
View File
@@ -1,7 +1,10 @@
using Xunit;
using Tulip;
using QuanTAlib;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class TulipTests
{
private readonly TBarSeries bars;
@@ -71,10 +74,7 @@ public class TulipTests
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}");
}
}
}
}
+46 -44
View File
@@ -1,58 +1,60 @@
using Xunit;
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class BarIndicatorTests
{
public class BarIndicatorTests
private readonly Random rnd;
private const int SeriesLen = 1000;
private const int Corrections = 100;
public BarIndicatorTests()
{
private readonly Random rnd;
private const int SeriesLen = 1000;
private const int Corrections = 100;
rnd = new Random((int)DateTime.Now.Ticks);
}
public BarIndicatorTests()
{
rnd = new Random((int)DateTime.Now.Ticks);
}
private static readonly iTValue[] indicators = new iTValue[]
{
private static readonly iTValue[] indicators = new iTValue[]
{
new Atr(period: 14),
};
};
[Theory]
[MemberData(nameof(GetIndicators))]
public void IndicatorIsNew(iTValue indicator)
[Theory]
[MemberData(nameof(GetIndicators))]
public void IndicatorIsNew(iTValue indicator)
{
var indicator1 = indicator;
var indicator2 = indicator;
MethodInfo calcMethod = indicator.GetType().GetMethod("Calc")!;
if (calcMethod == null)
{
var indicator1 = indicator;
var indicator2 = indicator;
MethodInfo calcMethod = indicator.GetType().GetMethod("Calc")!;
if (calcMethod == null)
{
throw new Exception($"Calc method not found for indicator type: {indicator.GetType().Name}");
}
for (int i = 0; i < SeriesLen; i++)
{
TBar item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: true);
calcMethod.Invoke(indicator1, new object[] { item1 });
for (int j = 0; j < Corrections; j++)
{
item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: false);
calcMethod.Invoke(indicator1, new object[] { item1 });
}
var item2 = new TBar (item1.Time, item1.Open, item1.High, item1.Low, item1.Close, item1.Volume , IsNew: true);
calcMethod.Invoke(indicator2, new object[] { item2 });
Assert.Equal(indicator1.Value, indicator2.Value);
}
throw new Exception($"Calc method not found for indicator type: {indicator.GetType().Name}");
}
public static IEnumerable<object[]> GetIndicators()
for (int i = 0; i < SeriesLen; i++)
{
return indicators.Select(indicator => new object[] { indicator });
TBar item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: true);
calcMethod.Invoke(indicator1, new object[] { item1 });
for (int j = 0; j < Corrections; j++)
{
item1 = new(Time: DateTime.Now, Open: rnd.Next(-100, 100), High: rnd.Next(-100, 100), Low: rnd.Next(-100, 100), Close: rnd.Next(-100, 100), Volume: rnd.Next(-1000, 1000), IsNew: false);
calcMethod.Invoke(indicator1, new object[] { item1 });
}
var item2 = new TBar(item1.Time, item1.Open, item1.High, item1.Low, item1.Close, item1.Volume, IsNew: true);
calcMethod.Invoke(indicator2, new object[] { item2 });
Assert.Equal(indicator1.Value, indicator2.Value);
}
}
}
public static IEnumerable<object[]> GetIndicators()
{
return indicators.Select(indicator => new object[] { indicator });
}
}
+47 -45
View File
@@ -1,22 +1,25 @@
using Xunit;
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class IndicatorTests
{
public class IndicatorTests
private readonly Random rnd;
private const int SeriesLen = 1000;
private const int Corrections = 100;
public IndicatorTests()
{
private readonly Random rnd;
private const int SeriesLen = 1000;
private const int Corrections = 100;
rnd = new Random((int)DateTime.Now.Ticks);
}
public IndicatorTests()
{
rnd = new Random((int)DateTime.Now.Ticks);
}
private static readonly iTValue[] indicators =
[
new Ema(period: 10, useSma: true),
private static readonly iTValue[] indicators =
[
new Ema(period: 10, useSma: true),
new Alma(period: 14, offset: 0.85, sigma: 6),
new Afirma(periods: 4, taps: 4, window: Afirma.WindowType.Blackman),
new Convolution(new double[] { 1.0, 2, 3, 2, 1 }),
@@ -57,42 +60,41 @@ namespace QuanTAlib
new Variance(period: 14),
new Zscore(period: 14)
];
];
[Theory]
[MemberData(nameof(GetIndicators))]
public void IndicatorIsNew(iTValue indicator)
[Theory]
[MemberData(nameof(GetIndicators))]
public void IndicatorIsNew(iTValue indicator)
{
var indicator1 = indicator;
var indicator2 = indicator;
MethodInfo calcMethod = indicator.GetType().GetMethod("Calc")!;
if (calcMethod == null)
{
var indicator1 = indicator;
var indicator2 = indicator;
MethodInfo calcMethod = indicator.GetType().GetMethod("Calc")!;
if (calcMethod == null)
{
throw new Exception($"Calc method not found for indicator type: {indicator.GetType().Name}");
}
for (int i = 0; i < SeriesLen; i++)
{
TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
calcMethod.Invoke(indicator1, new object[] { item1 });
for (int j = 0; j < Corrections; j++)
{
item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
calcMethod.Invoke(indicator1, new object[] { item1 });
}
var item2 = new TValue(item1.Time, item1.Value, IsNew: true);
calcMethod.Invoke(indicator2, new object[] { item2 });
Assert.Equal(indicator1.Value, indicator2.Value);
}
throw new Exception($"Calc method not found for indicator type: {indicator.GetType().Name}");
}
public static IEnumerable<object[]> GetIndicators()
for (int i = 0; i < SeriesLen; i++)
{
return indicators.Select(indicator => new object[] { indicator });
TValue item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: true);
calcMethod.Invoke(indicator1, new object[] { item1 });
for (int j = 0; j < Corrections; j++)
{
item1 = new(Time: DateTime.Now, Value: rnd.Next(-100, 100), IsNew: false);
calcMethod.Invoke(indicator1, new object[] { item1 });
}
var item2 = new TValue(item1.Time, item1.Value, IsNew: true);
calcMethod.Invoke(indicator2, new object[] { item2 });
Assert.Equal(indicator1.Value, indicator2.Value);
}
}
}
public static IEnumerable<object[]> GetIndicators()
{
return indicators.Select(indicator => new object[] { indicator });
}
}
+5 -1
View File
@@ -1,6 +1,10 @@
using Xunit;
using Skender.Stock.Indicators;
using QuanTAlib;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class SkenderTests
{
+5 -1
View File
@@ -1,6 +1,10 @@
using Xunit;
using TALib;
using QuanTAlib;
using System.Diagnostics.CodeAnalysis;
namespace QuanTAlib;
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
public class TAlibTests
{