Refactor code formatting and improve consistency across various test files

- Removed unnecessary blank lines in multiple test files to enhance readability.
- Ensured consistent spacing and formatting in the `Trima`, `Usf`, `Vidya`, `Wma`, and `Atr` test classes.
- Updated comments for clarity and consistency in the `Atr` and `Adl` classes.
- Adjusted project files for better structure and maintainability.
This commit is contained in:
Miha Kralj
2025-12-28 17:44:08 -08:00
parent ad6eebf812
commit 13d7c1215d
169 changed files with 10815 additions and 10814 deletions
+11 -11
View File
@@ -472,7 +472,7 @@ public class SmaTests
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
var bars = gbm.Fetch(1000, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
var series = bars.Close;
// 1. Batch Mode
var batchSeries = Sma.Batch(series, period);
double expected = batchSeries.Last.Value;
@@ -512,7 +512,7 @@ public class SmaTests
{
var source = new TSeries();
var sma = new Sma(source, 10);
source.Add(new TValue(DateTime.UtcNow, 100));
Assert.Equal(100, sma.Last.Value);
}
@@ -529,12 +529,12 @@ public class SmaTests
{
var sma = new Sma(5);
double[] history = [10, 20, 30, 40, 50]; // SMA(5) = 30
sma.Prime(history);
Assert.True(sma.IsHot);
Assert.Equal(30.0, sma.Last.Value, 1e-10);
// Verify it continues correctly
sma.Update(new TValue(DateTime.UtcNow, 60)); // 20,30,40,50,60 -> 40
Assert.Equal(40.0, sma.Last.Value, 1e-10);
@@ -544,8 +544,8 @@ public class SmaTests
public void Prime_WithInsufficientHistory_IsNotHot()
{
var sma = new Sma(10);
double[] history = [10, 20, 30, 40, 50];
double[] history = [10, 20, 30, 40, 50];
sma.Prime(history);
Assert.False(sma.IsHot);
@@ -556,14 +556,14 @@ public class SmaTests
public void Prime_HandlesNaN_InHistory()
{
var sma = new Sma(3);
double[] history = [10, 20, double.NaN, 40];
double[] history = [10, 20, double.NaN, 40];
// 10
// 10, 20
// 10, 20, 20 (NaN replaced by 20) -> Avg(10,20,20) = 16.666...
// 20, 20, 40 -> Avg(20,20,40) = 26.666...
sma.Prime(history);
Assert.True(sma.IsHot);
Assert.Equal(80.0 / 3.0, sma.Last.Value, 1e-9);
}
@@ -574,7 +574,7 @@ public class SmaTests
var series = new TSeries();
for (int i = 1; i <= 10; i++) series.Add(DateTime.UtcNow, i * 10);
// 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
// SMA(5)
var (results, indicator) = Sma.Calculate(series, 5);
@@ -589,7 +589,7 @@ public class SmaTests
Assert.Equal(5, indicator.WarmupPeriod);
// Verify indicator continues correctly
indicator.Update(new TValue(DateTime.UtcNow, 110));
indicator.Update(new TValue(DateTime.UtcNow, 110));
// Window was [60, 70, 80, 90, 100] -> Avg 80
// New Window [70, 80, 90, 100, 110] -> Avg 90
Assert.Equal(90.0, indicator.Last.Value);
+1 -1
View File
@@ -29,7 +29,7 @@ public sealed class SmaToleranceTests : IDisposable
var sResult = _testData.SkenderQuotes.GetSma(period).ToList();
ValidationHelper.VerifyData(qResult, sResult, (s) => s.Sma);
// Add explicit assertion to satisfy SonarQube
Assert.True(qResult.Count > 0);
}
+5 -5
View File
@@ -10,13 +10,13 @@ public class SmaZeroDivTests
public void Sma_Update_WithIsNewFalse_OnEmptyBuffer_DoesNotThrow()
{
var sma = new Sma(10);
// Buffer is empty initially.
// Calling Update with isNew=false should not cause division by zero.
// It should return NaN or 0 or Last, but definitely not throw or return Infinity.
var result = sma.Update(new TValue(DateTime.UtcNow, 100), isNew: false);
// Since buffer count is 0, we expect NaN based on our fix.
Assert.True(double.IsNaN(result.Value), $"Expected NaN but got {result.Value}");
}
@@ -27,10 +27,10 @@ public class SmaZeroDivTests
var sma = new Sma(10);
sma.Update(new TValue(DateTime.UtcNow, 100));
sma.Reset();
// Buffer is empty after Reset.
var result = sma.Update(new TValue(DateTime.UtcNow, 200), isNew: false);
Assert.True(double.IsNaN(result.Value), $"Expected NaN but got {result.Value}");
}
}
+3 -3
View File
@@ -189,7 +189,7 @@ public sealed class Sma : AbstractBase
{
// Capture previous state BEFORE any mutation
_p_state = _state;
double val = GetValidValue(input.Value);
UpdateState(val);
_state.LastInput = val;
@@ -199,11 +199,11 @@ public sealed class Sma : AbstractBase
{
// Restore scalar state to pre-mutation values
_state = _p_state;
double val = GetValidValue(input.Value);
// Update sum: remove the value that was added during isNew=true, add the new correction value
_state.Sum = _state.Sum - _currentBarValue + val;
// Update the buffer's newest value and sync its internal sum with our state sum
_buffer.UpdateNewest(val);
_state.Sum = _buffer.RecalculateSum(); // Ensure sums stay in sync