mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 20:18:05 +00:00
feat(trends): implement IDisposable in Bessel and Conv classes to manage event subscriptions fix(trends): add validation for period and parameters in Kama and MGDI calculations fix(trends): clamp logarithmic calculations in JMA to avoid -Infinity
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using Xunit;
|
|
using QuanTAlib;
|
|
|
|
namespace QuanTAlib.Tests;
|
|
|
|
public class MgdiTests
|
|
{
|
|
[Fact]
|
|
public void NaN_FirstValue_DoesNotInitializeToZero()
|
|
{
|
|
var mgdi = new Mgdi(14, 0.6);
|
|
|
|
// First value is NaN
|
|
var result = mgdi.Update(new TValue(DateTime.UtcNow, double.NaN));
|
|
|
|
// Should be NaN, not 0.0
|
|
Assert.True(double.IsNaN(result.Value), $"Expected NaN but got {result.Value}");
|
|
}
|
|
|
|
[Fact]
|
|
public void NaN_Sequence_InitializesOnFirstValid()
|
|
{
|
|
var mgdi = new Mgdi(14, 0.6);
|
|
|
|
// Sequence of NaNs
|
|
mgdi.Update(new TValue(DateTime.UtcNow, double.NaN));
|
|
mgdi.Update(new TValue(DateTime.UtcNow, double.NaN));
|
|
|
|
// First valid value
|
|
double firstValid = 100.0;
|
|
var result = mgdi.Update(new TValue(DateTime.UtcNow, firstValid));
|
|
|
|
Assert.Equal(firstValid, result.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Standard_Calculation()
|
|
{
|
|
var mgdi = new Mgdi(14, 0.6);
|
|
mgdi.Update(new TValue(DateTime.UtcNow, 100.0));
|
|
var result = mgdi.Update(new TValue(DateTime.UtcNow, 101.0));
|
|
|
|
Assert.True(result.Value > 100.0);
|
|
Assert.True(result.Value < 101.0);
|
|
}
|
|
}
|