feat(tests): update tests to use GBM for random data generation; improve consistency and realism in Skew and Variance tests; refine validation logic in Beta tests

This commit is contained in:
Miha Kralj
2025-12-26 12:05:07 -08:00
parent c2bc665ecf
commit 9c113767ec
5 changed files with 30 additions and 17 deletions
+6
View File
@@ -11,6 +11,12 @@ These tests verify the internal logic, state management, and API contract of the
- **`Constructor_ValidatesInput`**: Verify that invalid parameters (e.g., `period <= 0`) throw `ArgumentException`. - **`Constructor_ValidatesInput`**: Verify that invalid parameters (e.g., `period <= 0`) throw `ArgumentException`.
- **`Constructor_ValidatesOptionalArgs`**: If applicable, verify other parameters (e.g., `alpha`, `sigma`). - **`Constructor_ValidatesOptionalArgs`**: If applicable, verify other parameters (e.g., `alpha`, `sigma`).
### Random Data Generation
- **Use `GBM` Helper**: Always use the `GBM` (Geometric Brownian Motion) helper class for generating random test data.
- **Avoid `System.Random`**: Do not use `System.Random` directly in tests to ensure consistency and realism.
- **Example**: `var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);`
### Basic Functionality ### Basic Functionality
- **`Calc_ReturnsValue`**: Verify `Update` returns a valid `TValue` and updates the `Last` property. - **`Calc_ReturnsValue`**: Verify `Update` returns a valid `TValue` and updates the `Last` property.
+19 -12
View File
@@ -19,12 +19,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
permissions: permissions: {}
contents: write
pull-requests: read
security-events: write
checks: write
actions: read
env: env:
DOTNET_VERSION: '10.x' DOTNET_VERSION: '10.x'
@@ -37,6 +32,8 @@ jobs:
# ============================================================================== # ==============================================================================
Build_Test_Coverage: Build_Test_Coverage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -94,6 +91,8 @@ jobs:
Sonar_Analysis: Sonar_Analysis:
needs: Build_Test_Coverage needs: Build_Test_Coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -167,6 +166,11 @@ jobs:
Qodana_Scan: Qodana_Scan:
needs: Build_Test_Coverage needs: Build_Test_Coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
checks: write
security-events: write
pull-requests: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
@@ -191,6 +195,8 @@ jobs:
Codacy_Upload: Codacy_Upload:
needs: Build_Test_Coverage needs: Build_Test_Coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
@@ -230,6 +236,8 @@ jobs:
# ============================================================================== # ==============================================================================
Snyk_Scan: Snyk_Scan:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
@@ -292,13 +300,12 @@ jobs:
# ============================================================================== # ==============================================================================
Publish_Package: Publish_Package:
needs: [Build_Test_Coverage, Sonar_Analysis, Qodana_Scan, Codacy_Upload, Snyk_Scan, CodeQL_Analysis] needs: [Build_Test_Coverage, Sonar_Analysis, Qodana_Scan, Codacy_Upload, Snyk_Scan, CodeQL_Analysis]
if: | if: >-
success() && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || endsWith(github.ref, '-dev'))) ||
( github.event_name == 'workflow_dispatch'
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || endsWith(github.ref, '-dev'))) ||
github.event_name == 'workflow_dispatch'
)
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
+1 -1
View File
@@ -93,7 +93,7 @@ public class BetaValidationTests : IDisposable
double ql = qlBeta[i]; double ql = qlBeta[i];
// Skender might return null/0 for warmup. // Skender might return null/0 for warmup.
if (sk != 0) if (Math.Abs(sk) > 1e-10)
{ {
Assert.Equal(sk, ql, ValidationHelper.DefaultTolerance); Assert.Equal(sk, ql, ValidationHelper.DefaultTolerance);
} }
+2 -2
View File
@@ -176,11 +176,11 @@ public class SkewTests
{ {
// Run for > 1000 updates to trigger Resync // Run for > 1000 updates to trigger Resync
var skew = new Skew(10); var skew = new Skew(10);
var random = new Random(123); var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
for (int i = 0; i < 1100; i++) for (int i = 0; i < 1100; i++)
{ {
skew.Update(new TValue(DateTime.UtcNow, random.NextDouble() * 100)); skew.Update(new TValue(DateTime.UtcNow, gbm.Next().Close));
} }
Assert.True(double.IsFinite(skew.Last.Value)); Assert.True(double.IsFinite(skew.Last.Value));
+2 -2
View File
@@ -154,11 +154,11 @@ public class VarianceTests
{ {
// Run for > 1000 updates to trigger Resync // Run for > 1000 updates to trigger Resync
var variance = new Variance(10); var variance = new Variance(10);
var random = new Random(123); var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 123);
for (int i = 0; i < 1100; i++) for (int i = 0; i < 1100; i++)
{ {
variance.Update(new TValue(DateTime.UtcNow, random.NextDouble() * 100)); variance.Update(new TValue(DateTime.UtcNow, gbm.Next().Close));
} }
Assert.True(double.IsFinite(variance.Last.Value)); Assert.True(double.IsFinite(variance.Last.Value));