mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 16:18:05 +00:00
feat(tests): add comprehensive tests for LinReg, StdDev, Variance, and Mama indicators; enhance Pwma constructor with null check; improve coverage path mappings in Qodana configuration
This commit is contained in:
@@ -178,4 +178,57 @@ public class MamaTests
|
||||
Assert.Equal(series1[i].Value, series2[i].Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Calculate_Span_Matches_Update()
|
||||
{
|
||||
int count = 100;
|
||||
var data = new double[count];
|
||||
var gbm = new GBM(startPrice: 100, seed: 42);
|
||||
for (int i = 0; i < count; i++) data[i] = gbm.Next().Close;
|
||||
|
||||
var output = new double[count];
|
||||
Mama.Calculate(data, output);
|
||||
|
||||
var mama = new Mama();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var res = mama.Update(new TValue(DateTime.UtcNow, data[i]));
|
||||
Assert.Equal(res.Value, output[i], precision: 8);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Calculate_Span_ThrowsOnSmallOutput()
|
||||
{
|
||||
var data = new double[10];
|
||||
var output = new double[5];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Mama.Calculate(data, output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Prime_PreloadsState()
|
||||
{
|
||||
var data = new double[60];
|
||||
var gbm = new GBM(startPrice: 100, seed: 42);
|
||||
for (int i = 0; i < 60; i++) data[i] = gbm.Next().Close;
|
||||
|
||||
// 1. Prime with all but last value
|
||||
var mamaPrimed = new Mama();
|
||||
mamaPrimed.Prime(data.AsSpan().Slice(0, 59));
|
||||
|
||||
// 2. Update with last value
|
||||
var resultPrimed = mamaPrimed.Update(new TValue(DateTime.UtcNow, data[59]));
|
||||
|
||||
// 3. Run normal updates for comparison
|
||||
var mamaNormal = new Mama();
|
||||
TValue resultNormal = default;
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
resultNormal = mamaNormal.Update(new TValue(DateTime.UtcNow, data[i]));
|
||||
}
|
||||
|
||||
Assert.True(mamaPrimed.IsHot);
|
||||
Assert.Equal(resultNormal.Value, resultPrimed.Value, precision: 9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public class PwmaTests
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new Pwma(0));
|
||||
Assert.Throws<ArgumentException>(() => new Pwma(-1));
|
||||
Assert.Throws<ArgumentNullException>(() => new Pwma(null!, 10));
|
||||
|
||||
var pwma = new Pwma(10);
|
||||
Assert.NotNull(pwma);
|
||||
|
||||
@@ -56,6 +56,7 @@ public sealed class Pwma : AbstractBase
|
||||
|
||||
public Pwma(ITValuePublisher source, int period) : this(period)
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
source.Pub += (item) => Update(item);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user