mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
Enhance code quality and stability across various modules
- Updated .coderabbit.yaml to exclude additional file types from reviews, improving the focus on relevant code changes. - Modified scanner.sh to handle test failures more gracefully, ensuring that analysis stops on test failures and improving logging. - Improved sonarscanner.sh to ensure build and test failures are properly reported, enhancing CI reliability. - Refined SimdExtensions.cs documentation for clarity on variance calculation methods. - Cleaned up TSeries.Tests.cs by simplifying the test structure and ensuring proper namespace usage. - Fixed potential issues in tseries.cs by ensuring correct handling of DateTime values. - Enhanced CsvFeed.cs to improve error handling during CSV parsing, ensuring robustness against malformed data. - Updated GBM.cs to correctly calculate volume in the current bar, ensuring accurate simulation. - Adjusted index.html to use globalThis for better compatibility across environments. - Refined quantalib.csproj to exclude unnecessary files from compilation, streamlining the build process. - Added comprehensive tests for the Mama class to ensure correct behavior during updates and state management. - Improved error handling in various trend classes (Kama, Dema, Ema, T3, Tema, Wma) to ensure NaN values are managed correctly. - Removed redundant Mama.Repro.Tests.cs file and consolidated tests into Mama.Tests.cs for better organization. - Enhanced T3 and Tema classes to maintain state integrity during updates, particularly with NaN values.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
@@ -101,4 +103,29 @@ public class T3Tests
|
||||
// Check last values match
|
||||
Assert.Equal(resSeries.Last.Value, resSpan[count-1], 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void T3_BarCorrection_WithNaN_RestoresPreviousValidValue()
|
||||
{
|
||||
var t3 = new T3(10);
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
// Step 1: Update with valid value
|
||||
t3.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Step 2: Update with another valid value
|
||||
t3.Update(new TValue(time.AddMinutes(1), 200), isNew: true);
|
||||
double valAfter200 = t3.Last.Value;
|
||||
|
||||
// Step 3: Correct with NaN (should use 100)
|
||||
t3.Update(new TValue(time.AddMinutes(1), double.NaN), isNew: false);
|
||||
double valAfterNaN = t3.Last.Value;
|
||||
|
||||
// Step 4: Correct with 100 (should match NaN result)
|
||||
t3.Update(new TValue(time.AddMinutes(1), 100), isNew: false);
|
||||
double valAfter100 = t3.Last.Value;
|
||||
|
||||
Assert.NotEqual(valAfter200, valAfterNaN); // Should not be the same as 200
|
||||
Assert.Equal(valAfter100, valAfterNaN, 1e-9); // Should be the same as using 100
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ public sealed class T3 : ITValuePublisher
|
||||
private State _state = State.New();
|
||||
private State _p_state = State.New();
|
||||
private double _lastValidValue;
|
||||
private double _p_lastValidValue;
|
||||
|
||||
/// <summary>
|
||||
/// Display name for the indicator.
|
||||
@@ -157,10 +158,12 @@ public sealed class T3 : ITValuePublisher
|
||||
if (isNew)
|
||||
{
|
||||
_p_state = _state;
|
||||
_p_lastValidValue = _lastValidValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = _p_state;
|
||||
_lastValidValue = _p_lastValidValue;
|
||||
}
|
||||
|
||||
double val = GetValidValue(input.Value);
|
||||
@@ -196,6 +199,7 @@ public sealed class T3 : ITValuePublisher
|
||||
sourceTimes.CopyTo(tSpan);
|
||||
|
||||
_p_state = _state;
|
||||
_p_lastValidValue = _lastValidValue;
|
||||
Last = new TValue(tSpan[len - 1], vSpan[len - 1]);
|
||||
|
||||
return new TSeries(t, v);
|
||||
@@ -283,6 +287,7 @@ public sealed class T3 : ITValuePublisher
|
||||
_state = State.New();
|
||||
_p_state = _state;
|
||||
_lastValidValue = 0;
|
||||
_p_lastValidValue = 0;
|
||||
Last = default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user