-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathMockRandomProvider.cs
More file actions
73 lines (62 loc) · 1.87 KB
/
MockRandomProvider.cs
File metadata and controls
73 lines (62 loc) · 1.87 KB
Download raw file
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
namespace StockSharp.Tests;
using StockSharp.Algo.Testing;
/// <summary>
/// Mock random provider for testing with configurable behavior.
/// </summary>
public class MockRandomProvider : IRandomProvider
{
private Func<decimal> _nextVolume;
private Func<int, int> _nextSpreadStep;
private Func<bool> _shouldMatch;
private Func<double, bool> _shouldFail;
/// <summary>
/// Function to generate volume. Default returns 50.
/// </summary>
public Func<decimal> NextVolumeFunc
{
get => _nextVolume;
set => _nextVolume = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Function to generate spread step. Default returns 1.
/// </summary>
public Func<int, int> NextSpreadStepFunc
{
get => _nextSpreadStep;
set => _nextSpreadStep = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Function to determine if should match. Default returns false.
/// </summary>
public Func<bool> ShouldMatchFunc
{
get => _shouldMatch;
set => _shouldMatch = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Function to determine if should fail. Default returns false.
/// </summary>
public Func<double, bool> ShouldFailFunc
{
get => _shouldFail;
set => _shouldFail = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Creates mock provider with default deterministic behavior.
/// </summary>
public MockRandomProvider()
{
_nextVolume = () => 50;
_nextSpreadStep = max => 1;
_shouldMatch = () => false;
_shouldFail = _ => false;
}
/// <inheritdoc />
public decimal NextVolume() => _nextVolume();
/// <inheritdoc />
public int NextSpreadStep(int maxSpreadSize) => _nextSpreadStep(maxSpreadSize);
/// <inheritdoc />
public bool ShouldMatch() => _shouldMatch();
/// <inheritdoc />
public bool ShouldFail(double failingPercent) => _shouldFail(failingPercent);
}