Implemented TLazy + Tests
This commit is contained in:
+26
-26
@@ -23,7 +23,7 @@ type
|
||||
|
||||
[TestFixture]
|
||||
[IgnoreMemoryLeaks(true)]
|
||||
TTestMycInitStateFuncFuture = class(TObject)
|
||||
TTestMycGateFuncFuture = class(TObject)
|
||||
private
|
||||
FTaskFactory: IMycTaskFactory;
|
||||
FProcExecutionCount: Integer; // Counter for side effects of AProc
|
||||
@@ -67,16 +67,16 @@ begin
|
||||
Result := False; // This subscriber is typically one-shot for this purpose.
|
||||
end;
|
||||
|
||||
{ TTestMycInitStateFuncFuture }
|
||||
{ TTestMycGateFuncFuture }
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Setup;
|
||||
procedure TTestMycGateFuncFuture.Setup;
|
||||
begin
|
||||
FTaskFactory := TMycTaskFactory.Create; // Create a new task factory instance for each test [cite: 113, 235, 353]
|
||||
FProcExecutionCount := 0;
|
||||
FSharedCounter := 0;
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.TearDown;
|
||||
procedure TTestMycGateFuncFuture.TearDown;
|
||||
begin
|
||||
if Assigned(FTaskFactory) then
|
||||
begin
|
||||
@@ -85,7 +85,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_BasicSuccess_WithImmediateInitState;
|
||||
procedure TTestMycGateFuncFuture.Test_BasicSuccess_WithImmediateInitState;
|
||||
var
|
||||
LFuture: IMycFuture<Integer>;
|
||||
LInitStateAsState: IMycState; // Parameter for Create
|
||||
@@ -96,7 +96,7 @@ begin
|
||||
// Use TMycLatch.Null for an already set init state [cite: 71, 81, 206, 216, 324, 334]
|
||||
LInitStateAsState := TState.Null;
|
||||
|
||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
||||
LFuture := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateAsState,
|
||||
function: Integer
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount);
|
||||
@@ -112,7 +112,7 @@ begin
|
||||
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value.');
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_ChainedExecution_WithDelayedInitState;
|
||||
procedure TTestMycGateFuncFuture.Test_ChainedExecution_WithDelayedInitState;
|
||||
var
|
||||
LFuture: IMycFuture<string>;
|
||||
LInitLatch: IMycLatch;
|
||||
@@ -120,9 +120,9 @@ var
|
||||
const
|
||||
CExpectedResult = 'ChainCompleted';
|
||||
begin
|
||||
LInitLatch := TState.CreateLatch(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
||||
LInitLatch := TLatch.Construct(1); // Create an init state that is not yet set [cite: 77, 212, 330]
|
||||
|
||||
LFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
||||
LFuture := TMycGateFuncFuture<string>.Create(FTaskFactory, LInitLatch.State,
|
||||
function: string
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount);
|
||||
@@ -143,7 +143,7 @@ begin
|
||||
Assert.AreEqual(CExpectedResult, LResultValue, 'GetResult returned an unexpected value after delayed init.');
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
|
||||
procedure TTestMycGateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
|
||||
var
|
||||
LFuture: IMycFuture<Integer>;
|
||||
LLocalTaskFactory: IMycTaskFactory;
|
||||
@@ -157,7 +157,7 @@ begin
|
||||
LLocalTaskFactory := TMycTaskFactory.Create;
|
||||
LInitStateAsState := TState.Null; // Immediate execution
|
||||
|
||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
||||
LFuture := TMycGateFuncFuture<Integer>.Create(LLocalTaskFactory, LInitStateAsState,
|
||||
function: Integer
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount);
|
||||
@@ -203,14 +203,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
|
||||
procedure TTestMycGateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
|
||||
var
|
||||
LFuture: IMycFuture<Integer>;
|
||||
LInitLatch: IMycLatch;
|
||||
begin
|
||||
LInitLatch := TState.CreateLatch(1);
|
||||
LInitLatch := TLatch.Construct(1);
|
||||
|
||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
||||
LFuture := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
||||
function: Integer
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount);
|
||||
@@ -236,7 +236,7 @@ begin
|
||||
end );
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
|
||||
procedure TTestMycGateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
|
||||
var
|
||||
LPrerequisiteFuture1, LPrerequisiteFuture2: IMycFuture<Integer>;
|
||||
LMainFuture: IMycFuture<string>;
|
||||
@@ -250,10 +250,10 @@ begin
|
||||
FProcExecutionCount := 0; // Reset for this test
|
||||
|
||||
// Gate Latch: MainFuture waits for this latch, which needs 2 notifications.
|
||||
LGateLatch := TState.CreateLatch(2); // [cite: 77, 212, 330]
|
||||
LGateLatch := TLatch.Construct(2); // [cite: 77, 212, 330]
|
||||
|
||||
// Create MainFuture, AInitState is the GateLatch's state.
|
||||
LMainFuture := TMycInitStateFuncFuture<string>.Create(FTaskFactory, LGateLatch.State,
|
||||
LMainFuture := TMycGateFuncFuture<string>.Create(FTaskFactory, LGateLatch.State,
|
||||
function: string
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount, 10); // Indicate MainFuture's proc ran
|
||||
@@ -262,8 +262,8 @@ begin
|
||||
|
||||
// Setup Prerequisite Futures
|
||||
// PrerequisiteFuture1
|
||||
LInitStateP1 := TState.CreateLatch(1); // Controllable init state for PF1
|
||||
LPrerequisiteFuture1 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
||||
LInitStateP1 := TLatch.Construct(1); // Controllable init state for PF1
|
||||
LPrerequisiteFuture1 := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP1.State,
|
||||
function: Integer
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount, 1); // PF1 ran
|
||||
@@ -273,8 +273,8 @@ begin
|
||||
Subscriptions[1] := LPrerequisiteFuture1.Done.Subscribe(LSub1); // Subscribe to PF1's completion [cite: 56, 188, 306]
|
||||
|
||||
// PrerequisiteFuture2
|
||||
LInitStateP2 := TState.CreateLatch(1); // Controllable init state for PF2
|
||||
LPrerequisiteFuture2 := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
||||
LInitStateP2 := TLatch.Construct(1); // Controllable init state for PF2
|
||||
LPrerequisiteFuture2 := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LInitStateP2.State,
|
||||
function: Integer
|
||||
begin
|
||||
Inc(Self.FProcExecutionCount, 1); // PF2 ran
|
||||
@@ -312,7 +312,7 @@ begin
|
||||
Subscriptions[2].Unsubscribe; //
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_FanOut_MultipleFuturesWaitForOneTrigger;
|
||||
procedure TTestMycGateFuncFuture.Test_FanOut_MultipleFuturesWaitForOneTrigger;
|
||||
var
|
||||
LTriggerLatch: IMycLatch;
|
||||
LFutureA, LFutureB: IMycFuture<Integer>;
|
||||
@@ -322,10 +322,10 @@ begin
|
||||
LFlagFutureBRan := False;
|
||||
Self.FSharedCounter := 0; // Reset shared counter for this test
|
||||
|
||||
LTriggerLatch := TState.CreateLatch(1); // Single trigger [cite: 77, 212, 330]
|
||||
LTriggerLatch := TLatch.Construct(1); // Single trigger [cite: 77, 212, 330]
|
||||
|
||||
// Future A
|
||||
LFutureA := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||
LFutureA := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||
function: Integer
|
||||
begin
|
||||
LFlagFutureARan := True;
|
||||
@@ -334,7 +334,7 @@ begin
|
||||
end);
|
||||
|
||||
// Future B
|
||||
LFutureB := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||
LFutureB := TMycGateFuncFuture<Integer>.Create(FTaskFactory, LTriggerLatch.State,
|
||||
function: Integer
|
||||
begin
|
||||
LFlagFutureBRan := True;
|
||||
@@ -364,5 +364,5 @@ end;
|
||||
|
||||
initialization
|
||||
// For DUnitX, attributes typically handle registration.
|
||||
// If needed for older DUnit: RegisterTest(TTestMycInitStateFuncFuture.Suite);
|
||||
// If needed for older DUnit: RegisterTest(TTestMycGateFuncFuture.Suite);
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user