mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 18:48:05 +00:00
feat: update Qodana configuration to disable failure conditions and improve build stability
refactor: enhance Bilateral and SMA indicators to handle edge cases and improve state management refactor: clean up whitespace and formatting in various test files for consistency
This commit is contained in:
@@ -113,7 +113,6 @@ public class BilateralIndicatorTests
|
||||
Assert.True(double.IsFinite(secondValue));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void BilateralIndicator_MultipleUpdates_ProducesCorrectSequence()
|
||||
{
|
||||
|
||||
@@ -106,6 +106,37 @@ public class BilateralTests
|
||||
Assert.False(indicator.IsHot);
|
||||
Assert.Equal(1, indicator.Update(new TValue(DateTime.UtcNow, 1)).Value); // Center val 1, weights 0? No, center val is returned if weights 0.
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_IsNew_False_OnEmptyBuffer_DoesNotCrash()
|
||||
{
|
||||
// Test edge case: calling Update with isNew:false before any isNew:true
|
||||
var indicator = new Bilateral(3);
|
||||
|
||||
// This should not crash - buffer is empty, so we treat it as first value
|
||||
var result = indicator.Update(new TValue(DateTime.UtcNow, 5.0), isNew: false);
|
||||
|
||||
// Should have added the value to the buffer
|
||||
Assert.True(double.IsFinite(result.Value));
|
||||
Assert.Equal(5.0, result.Value); // Single value, so result is that value
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_IsNew_False_AfterReset_DoesNotCrash()
|
||||
{
|
||||
// Test edge case: calling Update with isNew:false after Reset
|
||||
var indicator = new Bilateral(3);
|
||||
|
||||
indicator.Update(new TValue(DateTime.UtcNow, 1));
|
||||
indicator.Update(new TValue(DateTime.UtcNow, 2));
|
||||
indicator.Reset();
|
||||
|
||||
// Buffer is now empty, isNew:false should not crash
|
||||
var result = indicator.Update(new TValue(DateTime.UtcNow, 7.0), isNew: false);
|
||||
|
||||
Assert.True(double.IsFinite(result.Value));
|
||||
Assert.Equal(7.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllModes_ProduceSameResult()
|
||||
|
||||
@@ -191,4 +191,3 @@ public sealed class BilateralValidationTests : IDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,11 +168,21 @@ public sealed class Bilateral : AbstractBase
|
||||
_state.SumSq = currentSumSq;
|
||||
|
||||
double val = GetValidValue(input.Value);
|
||||
double oldNewest = _buffer.Newest; // Get current newest before overwriting
|
||||
_buffer.UpdateNewest(val);
|
||||
|
||||
_state.SumSq -= (oldNewest * oldNewest);
|
||||
_state.SumSq += (val * val);
|
||||
// Defensive check: if buffer is empty, treat as first value
|
||||
if (_buffer.Count == 0)
|
||||
{
|
||||
_buffer.Add(val);
|
||||
_state.SumSq += (val * val);
|
||||
}
|
||||
else
|
||||
{
|
||||
double oldNewest = _buffer.Newest; // Get current newest before overwriting
|
||||
_buffer.UpdateNewest(val);
|
||||
|
||||
_state.SumSq -= (oldNewest * oldNewest);
|
||||
_state.SumSq += (val * val);
|
||||
}
|
||||
}
|
||||
|
||||
double result = CalculateBilateral();
|
||||
|
||||
Reference in New Issue
Block a user