normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+5 -5
View File
@@ -439,7 +439,7 @@ public class MassiTests
// Span calculation
var output = new double[series.Count];
Massi.Calculate(series.Values, output, 9, 25);
Massi.Batch(series.Values, output, 9, 25);
// Compare last value
Assert.Equal(streamingLast, output[series.Count - 1], 1e-6);
@@ -530,7 +530,7 @@ public class MassiTests
var source = new double[10];
var output = new double[5]; // Wrong size
var ex = Assert.Throws<ArgumentException>(() => Massi.Calculate(source, output, 9, 25));
var ex = Assert.Throws<ArgumentException>(() => Massi.Batch(source, output, 9, 25));
Assert.Equal("output", ex.ParamName);
}
@@ -540,7 +540,7 @@ public class MassiTests
var source = Array.Empty<double>();
var output = Array.Empty<double>();
var exception = Record.Exception(() => Massi.Calculate(source, output, 9, 25));
var exception = Record.Exception(() => Massi.Batch(source, output, 9, 25));
Assert.Null(exception);
}
@@ -550,8 +550,8 @@ public class MassiTests
var source = new double[10];
var output = new double[10];
Assert.Throws<ArgumentOutOfRangeException>(() => Massi.Calculate(source, output, 0, 25));
Assert.Throws<ArgumentOutOfRangeException>(() => Massi.Calculate(source, output, 9, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => Massi.Batch(source, output, 0, 25));
Assert.Throws<ArgumentOutOfRangeException>(() => Massi.Batch(source, output, 9, 0));
}
// ============== Edge Cases ==============
+15 -3
View File
@@ -30,6 +30,7 @@ public sealed class Massi : AbstractBase
private readonly RingBuffer _sumBuffer;
private readonly TValuePublishedHandler _handler;
private readonly ITValuePublisher? _source;
private bool _disposed;
private State _s;
private State _ps;
@@ -324,9 +325,13 @@ public sealed class Massi : AbstractBase
protected override void Dispose(bool disposing)
{
if (disposing && _source != null)
if (!_disposed)
{
_source.Pub -= _handler;
if (disposing && _source != null)
{
_source.Pub -= _handler;
}
_disposed = true;
}
base.Dispose(disposing);
}
@@ -363,7 +368,7 @@ public sealed class Massi : AbstractBase
/// <summary>
/// Static helper for span-based calculation (assumes input is H-L range).
/// </summary>
public static void Calculate(ReadOnlySpan<double> source, Span<double> output,
public static void Batch(ReadOnlySpan<double> source, Span<double> output,
int emaLength = 9, int sumLength = 25)
{
if (output.Length != source.Length)
@@ -382,4 +387,11 @@ public sealed class Massi : AbstractBase
output[i] = massi.CalculateMassiStep(source[i]);
}
}
public static (TSeries Results, Massi Indicator) Calculate(TBarSeries source, int emaLength = 9, int sumLength = 25)
{
var indicator = new Massi(emaLength, sumLength);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}