mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-14 00:28: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:
@@ -122,4 +122,70 @@ public class VarianceTests
|
||||
Assert.Equal(iterativeResults[i], batchResults[i], precision: 7);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_HandlesConstantValues_ZeroVariance()
|
||||
{
|
||||
var variance = new Variance(5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var result = variance.Update(new TValue(DateTime.UtcNow, 10));
|
||||
if (i >= 1) // Variance defined for N >= 2
|
||||
{
|
||||
Assert.Equal(0, result.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_HandlesNaN()
|
||||
{
|
||||
var variance = new Variance(5);
|
||||
variance.Update(new TValue(DateTime.UtcNow, 1));
|
||||
variance.Update(new TValue(DateTime.UtcNow, 2));
|
||||
variance.Update(new TValue(DateTime.UtcNow, double.NaN));
|
||||
|
||||
var result = variance.Last.Value;
|
||||
Assert.True(double.IsNaN(result));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Resync_DoesNotDrift()
|
||||
{
|
||||
// Run for > 1000 updates to trigger Resync
|
||||
var variance = new Variance(10);
|
||||
var random = new Random(123);
|
||||
|
||||
for (int i = 0; i < 1100; i++)
|
||||
{
|
||||
variance.Update(new TValue(DateTime.UtcNow, random.NextDouble() * 100));
|
||||
}
|
||||
|
||||
Assert.True(double.IsFinite(variance.Last.Value));
|
||||
Assert.True(variance.Last.Value >= 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Batch_LargeDataset_Simd()
|
||||
{
|
||||
// Create large dataset to trigger SIMD path (>= 256)
|
||||
int count = 1000;
|
||||
var data = new double[count];
|
||||
for (int i = 0; i < count; i++) data[i] = (double)i;
|
||||
|
||||
var series = new TSeries(new System.Collections.Generic.List<long>(new long[count]), new System.Collections.Generic.List<double>(data));
|
||||
|
||||
// Batch calculation
|
||||
var batchResult = Variance.Calculate(series, 10);
|
||||
|
||||
// Verify last value against streaming
|
||||
var variance = new Variance(10);
|
||||
double lastStreaming = 0;
|
||||
foreach (var val in data)
|
||||
{
|
||||
lastStreaming = variance.Update(new TValue(DateTime.UtcNow, val)).Value;
|
||||
}
|
||||
|
||||
Assert.Equal(lastStreaming, batchResult.Last.Value, precision: 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user