This directory contains comprehensive test coverage for the randomProcesses MATLAB class.
test_randomProcesses.m- Main test suite using MATLAB's unit testing frameworkrun_all_tests.m- Convenience script to run all tests with formatted output
>> run_all_tests>> results = runtests('test_randomProcesses')matlab -batch "run_all_tests">> results = runtests('test_randomProcesses', 'Name', 'testBrownianPrices')The test suite covers:
- Constructor with default values
- Constructor with custom values
- Dependent property
r0(initial rate) - Dependent property
dt(time delta)
- Brownian Motion (
brownian_prices) - Geometric Brownian Motion (
gbm_prices) - Merton Jump-Diffusion Model (
merton_prices) - Heston Model (
heston_prices) - Single path generation
- Vasicek Interest Rate Model (
vas_rates) - Cox-Ingersoll-Ross Model (
cir_rates)
- Order Flow (
order_flow) - Tick Imbalance Bars (
tib) - Volume Imbalance Bars (
vib) - Dollar Imbalance Bars (
dib)
- Invalid tick data format detection
- Invalid window size detection
- Parameter bounds checking (eta, M)
- Vector shape conversion
- Error message verification
- Exponential Weighted Moving Average (
ewma)
- Zero price differences handling
- Small dataset handling
- Brownian with constant volatility
- GBM with stochastic volatility
- Merton with stochastic volatility
Total: 29 test methods
Each test method follows this pattern:
function testMethodName(testCase)
% Test description
% 1. Setup: Create test data
% 2. Execute: Call the method being tested
% 3. Verify: Assert expected results
testCase.verifyEqual(actual, expected);
testCase.verifySize(result, expectedSize);
testCase.verifyError(@() method(), 'expectedErrorID');
endverifyEqual- Check exact equality (with tolerance)verifySize- Check array dimensionsverifyTrue/verifyFalse- Check boolean conditionsverifyError- Check that expected errors are thrownverifyGreaterThanOrEqual/verifyLessThanOrEqual- Check orderingverifyLessThan- Check strict inequality
To add a new test:
- Open
test_randomProcesses.m - Add a new test method in the appropriate section:
function testNewFeature(testCase)
% Test description
result = testCase.sim.newMethod();
testCase.verifyEqual(result, expectedValue);
end- Run the tests to verify the new test works
When you run tests, you'll see output like:
Running testConstructorDefaultValues
.
Running testBrownianPrices
.
...
Total Tests: 29
Passed: 29
Failed: 0
Incomplete: 0
Duration: 5.23 seconds
✓ All tests passed!
If a test fails, you'll see details:
Failed Tests:
- testBrownianPrices
Reason: Verification failed...
Expected: [252, 5]
Actual: [252, 4]
These tests can be integrated into CI/CD pipelines:
# Example GitHub Actions workflow
- name: Run MATLAB tests
run: matlab -batch "run_all_tests"Tests use randomly generated data with fixed parameters to ensure reproducibility. Each test method runs independently with fresh instances created in the setup phase.
- Tests use random number generation, so exact values may vary between runs
- Some stochastic processes may occasionally produce outliers
- Tests verify dimensions, ranges, and statistical properties rather than exact values
Error: "Undefined function or variable 'randomProcesses'"
- Solution: Make sure you're running from the repository root directory
Error: "Test framework not found"
- Solution: Requires MATLAB R2013a or later with the Testing Framework
Tests run but some fail intermittently
- This is expected with stochastic processes
- Failing tests should still pass on retry
- If consistently failing, check the implementation
- MATLAB Unit Testing Framework Documentation
- See
REVIEW_SUMMARY.mdfor details on recent code improvements - See
README.mdfor usage examples of each method