TaskManager refactoring
This commit is contained in:
@@ -13,7 +13,7 @@ type
|
||||
[TestFixture]
|
||||
TTestDataArray = class(TObject)
|
||||
private
|
||||
FArray: IDataArray<TAskBidItem>;
|
||||
FArray: TDataSeries<TAskBidItem>;
|
||||
procedure SetupSeriesWithData(ItemCount: Integer = 10; MaxLookBack: Int64 = 0);
|
||||
public
|
||||
[Setup]
|
||||
@@ -67,7 +67,6 @@ type
|
||||
[TestFixture]
|
||||
TTestDataSeries = class(TObject)
|
||||
private
|
||||
FArray: IDataArray<TAskBidItem>;
|
||||
FSeries: TDataSeries<TAskBidItem>;
|
||||
procedure SetupSeriesWithData(ItemCount: Integer = 10; MaxLookBack: Int64 = 0);
|
||||
public
|
||||
@@ -111,7 +110,7 @@ implementation
|
||||
|
||||
procedure TTestDataArray.Setup;
|
||||
begin
|
||||
FArray := TDataSeries<TAskBidItem>.CreateArray(0);
|
||||
FArray := TDataSeries<TAskBidItem>.CreateWriteable(0);
|
||||
end;
|
||||
|
||||
procedure TTestDataArray.Teardown;
|
||||
@@ -125,7 +124,7 @@ var
|
||||
DataPoint: TDataPoint<TAskBidItem>;
|
||||
baseTime: TDateTime;
|
||||
begin
|
||||
FArray := TDataSeries<TAskBidItem>.CreateArray(MaxLookBack);
|
||||
FArray := TDataSeries<TAskBidItem>.CreateWriteable(MaxLookBack);
|
||||
baseTime := EncodeDate(2020, 7, 7);
|
||||
|
||||
// Add data points with increasing timestamps.
|
||||
@@ -410,14 +409,12 @@ end;
|
||||
|
||||
procedure TTestDataSeries.Setup;
|
||||
begin
|
||||
FArray := TDataSeries<TAskBidItem>.CreateArray(0);
|
||||
FSeries := FArray;
|
||||
FSeries := TDataSeries<TAskBidItem>.CreateWriteable(0);
|
||||
end;
|
||||
|
||||
procedure TTestDataSeries.Teardown;
|
||||
begin
|
||||
FSeries := Default(TDataSeries<TAskBidItem>);
|
||||
FArray := nil;
|
||||
end;
|
||||
|
||||
procedure TTestDataSeries.SetupSeriesWithData(ItemCount: Integer = 10; MaxLookBack: Int64 = 0);
|
||||
@@ -426,15 +423,14 @@ var
|
||||
DataPoint: TDataPoint<TAskBidItem>;
|
||||
baseTime: TDateTime;
|
||||
begin
|
||||
FArray := TDataSeries<TAskBidItem>.CreateArray(MaxLookBack);
|
||||
FSeries := FArray;
|
||||
FSeries := TDataSeries<TAskBidItem>.CreateWriteable(MaxLookBack);
|
||||
baseTime := EncodeDate(2020, 7, 7);
|
||||
|
||||
// Add data points with increasing timestamps.
|
||||
for i := 0 to ItemCount - 1 do
|
||||
begin
|
||||
DataPoint := TDataPoint<TAskBidItem>.Create(baseTime + i, TAskBidItem.Create(i * 1.0, i * 1.0 + 0.1));
|
||||
FArray.Add(DataPoint);
|
||||
FSeries.Add(DataPoint);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -445,7 +441,7 @@ var
|
||||
begin
|
||||
SetupSeriesWithData(15);
|
||||
|
||||
copy := FSeries.Copy;
|
||||
copy := FSeries.Immutable;
|
||||
|
||||
Assert.AreEqual(FSeries.Count, copy.Count, 'Copy must have the same count as the original');
|
||||
Assert.AreEqual(FSeries.TotalCount, copy.TotalCount, 'Copy must have the same total count as the original');
|
||||
@@ -467,21 +463,21 @@ begin
|
||||
SetupSeriesWithData(10);
|
||||
|
||||
// Create the copy
|
||||
copy := FSeries.Copy;
|
||||
copy := FSeries.Immutable;
|
||||
originalCount := copy.Count;
|
||||
originalTotalCount := copy.TotalCount;
|
||||
|
||||
// Modify the original series
|
||||
lastTime := FArray[0].Time;
|
||||
lastTime := FSeries[0].Time;
|
||||
newPoint := TDataPoint<TAskBidItem>.Create(lastTime + 1, TAskBidItem.Create(99, 99.1));
|
||||
FArray.Add(newPoint);
|
||||
FSeries.Add(newPoint);
|
||||
|
||||
Assert.AreEqual(Int64(11), FArray.Count, 'Original array count should have increased');
|
||||
Assert.AreEqual(Int64(11), FSeries.Count, 'Original array count should have increased');
|
||||
|
||||
// Verify the copy remains unchanged
|
||||
Assert.AreEqual(originalCount, copy.Count, 'Copy count must not change after original is modified');
|
||||
Assert.AreEqual(originalTotalCount, copy.TotalCount, 'Copy total count must not change after original is modified');
|
||||
Assert.AreNotEqual(FArray[0].Time, copy[0].Time, 'Newest item in copy should not be the new item from original');
|
||||
Assert.AreNotEqual(FSeries[0].Time, copy[0].Time, 'Newest item in copy should not be the new item from original');
|
||||
end;
|
||||
|
||||
procedure TTestDataSeries.TestCopyRespectsMaxLookback;
|
||||
@@ -495,16 +491,16 @@ begin
|
||||
Assert.AreEqual(Int64(15), FSeries.Count, 'Pre-condition: Series count should be capped by MaxLookback');
|
||||
Assert.AreEqual(Int64(20), FSeries.TotalCount, 'Pre-condition: Series total count should be 20');
|
||||
|
||||
copy := FSeries.Copy;
|
||||
copy := FSeries.Immutable;
|
||||
|
||||
// Verify the copy reflects the MaxLookback state
|
||||
Assert.AreEqual(Int64(15), copy.Count, 'Copy count should be the MaxLookback value of the original');
|
||||
Assert.AreEqual(Int64(20), copy.TotalCount, 'Copy total count should be the total items added to the original');
|
||||
|
||||
// Modify original
|
||||
lastTime := FArray[0].Time;
|
||||
lastTime := FSeries[0].Time;
|
||||
newPoint := TDataPoint<TAskBidItem>.Create(lastTime + 1, TAskBidItem.Create(99, 99.1));
|
||||
FArray.Add(newPoint);
|
||||
FSeries.Add(newPoint);
|
||||
|
||||
// Verify the copy is still unchanged
|
||||
Assert.AreEqual(Int64(15), copy.Count, 'Copy count must remain unchanged after original is modified');
|
||||
@@ -606,7 +602,7 @@ begin
|
||||
// Use default setup, but add one item
|
||||
testTime := EncodeDate(2025, 1, 1);
|
||||
DataPoint := TDataPoint<TAskBidItem>.Create(testTime, TAskBidItem.Create(1.0, 2.0));
|
||||
FArray.Add(DataPoint);
|
||||
FSeries.Add(DataPoint);
|
||||
|
||||
Assert.AreEqual(Int64(1), FSeries.Count);
|
||||
Assert.AreEqual(Int64(0), FSeries.IndexOf(testTime), 'IndexOf for exact single item should be 0');
|
||||
|
||||
Reference in New Issue
Block a user