mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 20:18:05 +00:00
feat(validation): add input validation for Bilateral and Blma constructors; enhance Butter and Mgdi calculations with NaN handling
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user