Files
QuanTAlib/lib/oscillators/deco/Deco.Quantower.Tests.cs
Miha Kralj 3dd05f23e4 Refactor indicators to include "Ehlers" in names and descriptions for clarity
- Updated the name and description of the Hilbert Trendline (HTIT) to "Ehlers Hilbert Transform Instantaneous Trend (HTIT)".
- Changed the name and description of the MESA Adaptive Moving Average (MAMA) to "Ehlers MESA Adaptive Moving Average".
- Modified the Center of Gravity (CG) indicator to "Ehlers Center of Gravity (CG)".
- Renamed the Detrended Synthetic Price (DSP) to "Ehlers Detrended Synthetic Price (DSP)".
- Updated the Autocorrelation Periodogram (EACP) to "Ehlers Autocorrelation Periodogram (EACP)".
- Changed the Homodyne Discriminator (HOMOD) to "Ehlers Homodyne Discriminator (HOMOD)".
- Updated the Hilbert Transform Dominant Cycle Period and Phase indicators to include "Ehlers" in their names.
- Renamed the Hilbert Transform Phasor Components to "Ehlers Hilbert Transform Phasor Components (HT_PHASOR)".
- Updated the SineWave indicator to "Ehlers Hilbert Transform SineWave (HT_SINE)".
- Changed the Phasor Analysis indicator to "Ehlers Hilbert Transform Phasor Components (HT_PHASOR)".
- Updated the SSF-Based Detrended Synthetic Price to "Ehlers SSF Detrended Synthetic Price (SSFDSP)".
- Renamed the Ultimate Channel to "Ehlers Ultimate Channel (UCHANNEL)".
- Added new indicators: Moving Average Variable Period (MAVP), Ehlers Predictive Moving Average (PMA), Ehlers Reverse EMA (REVERSEEMA), and Ehlers Trendflex Indicator (TRENDFLEX).
- Updated various SVG badges to reflect changes in classes, comments, source files, lines of code, methods, and public types.
2026-02-18 19:08:15 -08:00

143 lines
4.7 KiB
C#

using TradingPlatform.BusinessLayer;
namespace QuanTAlib.Tests;
public sealed class DecoIndicatorTests
{
[Fact]
public void DecoIndicator_Constructor_SetsDefaults()
{
var indicator = new DecoIndicator();
Assert.Equal(30, indicator.ShortPeriod);
Assert.Equal(60, indicator.LongPeriod);
Assert.Equal(SourceType.Close, indicator.Source);
Assert.True(indicator.ShowColdValues);
Assert.Equal("DECO - Ehlers Decycler Oscillator", indicator.Name);
Assert.True(indicator.SeparateWindow);
Assert.True(indicator.OnBackGround);
}
[Fact]
public void DecoIndicator_MinHistoryDepths_EqualsZero()
{
var indicator = new DecoIndicator { ShortPeriod = 10, LongPeriod = 20 };
Assert.Equal(0, DecoIndicator.MinHistoryDepths);
IWatchlistIndicator watchlistIndicator = indicator;
Assert.Equal(0, watchlistIndicator.MinHistoryDepths);
}
[Fact]
public void DecoIndicator_ShortName_IncludesParameters()
{
var indicator = new DecoIndicator { ShortPeriod = 10, LongPeriod = 30 };
indicator.Initialize();
Assert.Contains("DECO", indicator.ShortName, StringComparison.Ordinal);
Assert.Contains("10", indicator.ShortName, StringComparison.Ordinal);
Assert.Contains("30", indicator.ShortName, StringComparison.Ordinal);
}
[Fact]
public void DecoIndicator_SourceCodeLink_IsValid()
{
var indicator = new DecoIndicator();
Assert.Contains("github.com", indicator.SourceCodeLink, StringComparison.Ordinal);
Assert.Contains("Deco.Quantower.cs", indicator.SourceCodeLink, StringComparison.Ordinal);
}
[Fact]
public void DecoIndicator_Initialize_CreatesInternalDeco()
{
var indicator = new DecoIndicator { ShortPeriod = 5, LongPeriod = 10 };
indicator.Initialize();
Assert.Single(indicator.LinesSeries);
}
[Fact]
public void DecoIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
{
var indicator = new DecoIndicator { ShortPeriod = 5, LongPeriod = 10 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
indicator.ProcessUpdate(args);
}
double value = indicator.LinesSeries[0].GetValue(0);
Assert.True(double.IsFinite(value));
}
[Fact]
public void DecoIndicator_ProcessUpdate_NewBar_ComputesValue()
{
var indicator = new DecoIndicator { ShortPeriod = 5, LongPeriod = 10 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
indicator.ProcessUpdate(args);
}
// Add a new bar
indicator.HistoricalData.AddBar(now.AddMinutes(20), 120, 130, 110, 125);
var newArgs = new UpdateArgs(UpdateReason.NewBar);
indicator.ProcessUpdate(newArgs);
double value = indicator.LinesSeries[0].GetValue(0);
Assert.True(double.IsFinite(value));
}
[Fact]
public void DecoIndicator_ProcessUpdate_DifferentSources()
{
foreach (SourceType source in new[] { SourceType.Close, SourceType.Open, SourceType.High, SourceType.Low })
{
var indicator = new DecoIndicator { ShortPeriod = 5, LongPeriod = 10, Source = source };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 15; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
indicator.ProcessUpdate(args);
}
double value = indicator.LinesSeries[0].GetValue(0);
Assert.True(double.IsFinite(value), $"Source {source} produced non-finite value");
}
}
[Fact]
public void DecoIndicator_Reinitialize_ResetsState()
{
var indicator = new DecoIndicator { ShortPeriod = 5, LongPeriod = 10 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 15; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
var args = new UpdateArgs(UpdateReason.HistoricalBar);
indicator.ProcessUpdate(args);
}
// Re-initialize should reset
indicator.Initialize();
Assert.Single(indicator.LinesSeries);
}
}