feat(validation): add input validation for Bilateral and Blma constructors; enhance Butter and Mgdi calculations with NaN handling

This commit is contained in:
Miha Kralj
2025-12-25 20:53:56 -08:00
parent ac8b2dbb3f
commit 0d077c24d8
15 changed files with 195 additions and 66 deletions
+11
View File
@@ -551,6 +551,17 @@ public class EmaTests
Assert.Equal(verifyEma.Last.Value, ema.Last.Value, 1e-10);
}
[Fact]
public void Prime_AllNaNs_ReturnsNaN()
{
var ema = new Ema(5);
double[] history = [double.NaN, double.NaN, double.NaN];
ema.Prime(history);
Assert.True(double.IsNaN(ema.Last.Value));
}
[Fact]
public void Calculate_ReturnsCorrectResultsAndHotIndicator()
{
+10
View File
@@ -118,15 +118,25 @@ public sealed class Ema : AbstractBase
int i = 0;
// Find first valid value to seed lastValid
bool foundValid = false;
for (int k = 0; k < len; k++)
{
if (double.IsFinite(source[k]))
{
_lastValidValue = source[k];
foundValid = true;
break;
}
}
if (!foundValid)
{
Last = new TValue(DateTime.MinValue, double.NaN);
_p_state = _state;
_p_lastValidValue = _lastValidValue;
return;
}
if (!_state.IsCompensated)
{
for (; i < len && _state.E > COMPENSATOR_THRESHOLD; i++)