Files
MycLib/Src/Myc.Test.Trade.DataServer.pas
T
2025-06-07 10:12:41 +02:00

113 lines
3.2 KiB
ObjectPascal

unit Myc.Test.Trade.DataServer;
interface
uses
System.SysUtils,
System.Generics.Collections, // E2003: Added for TList<T>
DUnitX.TestFramework,
Myc.Signals,
Myc.Lazy,
Myc.Futures,
Myc.Trade.DataPoint,
Myc.Trade.DataSeries,
Myc.Trade.DataServer;
type
[TestFixture]
[IgnoreMemoryLeaks(true)]
TTest_TABFileServer_Equivalence = class(TObject)
private
FServer: IDataServer<TDataPoint<TAskBidItem>>;
public
[SetupFixture]
procedure SetupFixture;
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
[TearDownFixture]
procedure TearDownFixture;
[Test]
procedure Test_ServerReturnsSameDataAs_LoadDataSeries;
end;
implementation
uses
Myc.TaskManager;
const
// The reference data file for this test.
C_TEST_FILENAME = '\\COFFEE\TickData\Pepperstone\GER40_2025_03.tab_zip';
// The chunk size for fetching data from the server.
C_MAX_FETCH = 200;
{ TTest_TABFileServer_Equivalence }
procedure TTest_TABFileServer_Equivalence.SetupFixture;
begin
// IsMemoryLow := function: Boolean begin exit(false); end;
// Load the ground truth data using the original LoadDataSeries function.
// SetupTaskManagerMock;
TAskBid.ClearCache;
end;
procedure TTest_TABFileServer_Equivalence.TearDownFixture;
begin
IsMemoryLow := nil;
end;
procedure TTest_TABFileServer_Equivalence.Setup;
begin
FServer := TTABFileServer.Create(C_TEST_FILENAME);
end;
procedure TTest_TABFileServer_Equivalence.TearDown;
begin
FServer := nil;
TAskBid.ClearCache;
end;
procedure TTest_TABFileServer_Equivalence.Test_ServerReturnsSameDataAs_LoadDataSeries;
var
chunk: array[0..C_MAX_FETCH-1] of TDataPoint<TAskBidItem>;
Dst: TArray<TDataPoint<TAskBidItem>>;
i: Int64;
begin
var ExpectedData := TAskBid.LoadDataSeries(C_TEST_FILENAME).WaitFor;
SetLength( Dst, Length( ExpectedData ) );
var cnt: Int64 := 0;
var n: Integer;
while not FServer.IsLiveData.Value and (cnt < Length(Dst)) do
begin
n := FServer.GetChunk(chunk);
if n > 0 then
Move( chunk[0], dst[cnt], n * sizeof( TDataPoint<TAskBidItem> ) );
inc( cnt, n );
end;
// --- Assertions ---
// 1. Verify that the total number of records matches.
Assert.AreEqual(Length(ExpectedData), cnt, 'Data record count mismatch');
// 2. Verify that the content of each record is identical.
for n := 0 to High(ExpectedData) div 1000 do
begin
i := n * 1000;
// E2003: Removed assertion for 'Index', as it's not part of the IDataPoint interface.
// The index is an implementation detail of the faulty ConvertTicks and cannot be tested here.
Assert.AreEqual(Dst[i].Idx, i, 'Index mismatch ');
Assert.AreEqual(ExpectedData[i].TimeStamp, Dst[i].Time, 'Timestamp mismatch ');
Assert.AreEqual(ExpectedData[i].Data.Ask, Dst[i].Data.Ask, 'Ask price mismatch');
Assert.AreEqual(ExpectedData[i].Data.Bid, Dst[i].Data.Bid, 'Bid price mismatch');
end;
end;
initialization
TDUnitX.RegisterTestFixture(TTest_TABFileServer_Equivalence);
end.