Test completeness

This commit is contained in:
Miha Kralj
2025-12-14 21:55:40 -08:00
parent f761cc5712
commit a67ad65fa5
35 changed files with 2437 additions and 1405 deletions
+24 -9
View File
@@ -28,18 +28,18 @@ public class JmaTests
}
[Fact]
public void Jma_Calc_IsNew_AcceptsParameter()
public void Jma_SpanCalc_ValidatesInput()
{
var jma = new Jma(10);
double[] source = [1, 2, 3, 4, 5];
double[] output = new double[5];
double[] wrongSizeOutput = new double[3];
jma.Update(new TValue(DateTime.UtcNow, 100), isNew: true);
double value1 = jma.Last.Value;
// Period must be > 0
Assert.Throws<ArgumentOutOfRangeException>(() => Jma.Calculate(source.AsSpan(), output.AsSpan(), 0, 0, 1.0));
Assert.Throws<ArgumentOutOfRangeException>(() => Jma.Calculate(source.AsSpan(), output.AsSpan(), -1, 0, 1.0));
jma.Update(new TValue(DateTime.UtcNow, 200), isNew: true);
double value2 = jma.Last.Value;
// Values should change with new bars
Assert.NotEqual(value1, value2);
// Output must be same length as source
Assert.Throws<ArgumentException>(() => Jma.Calculate(source.AsSpan(), wrongSizeOutput.AsSpan(), 3, 0, 1.0));
}
[Fact]
@@ -236,4 +236,19 @@ public class JmaTests
Assert.NotEqual(jmaPhase0.Last.Value, jmaPhase100.Last.Value);
Assert.NotEqual(jmaPhase0.Last.Value, jmaPhaseMinus100.Last.Value);
}
[Fact]
public void Jma_SpanCalc_HandlesNaN()
{
double[] source = [100, 110, double.NaN, 120, 130];
double[] output = new double[5];
Jma.Calculate(source.AsSpan(), output.AsSpan(), 3);
foreach (var val in output)
{
Assert.True(double.IsFinite(val));
}
}
}