Implemented TLazy + Tests
This commit is contained in:
+22
-22
@@ -124,7 +124,7 @@ var
|
||||
latch: IMycLatch;
|
||||
begin
|
||||
// TMycLatch.CreateLatch returns TMycLatch.Null if InitialCount <= 0
|
||||
latch := TState.CreateLatch(InitialCount);
|
||||
latch := TLatch.Construct(InitialCount);
|
||||
Assert.AreEqual(ExpectedIsSet, latch.State.IsSet, 'Latch initial IsSet state mismatch for count ' + IntToStr(InitialCount) + '.');
|
||||
end;
|
||||
|
||||
@@ -133,7 +133,7 @@ var
|
||||
latch: IMycLatch;
|
||||
returnedValueFromNotify: Boolean;
|
||||
begin
|
||||
latch := TState.CreateLatch(InitialCount);
|
||||
latch := TLatch.Construct(InitialCount);
|
||||
returnedValueFromNotify := latch.Notify; // This is IMycLatch (as IMycSubscriber).Notify
|
||||
|
||||
Assert.AreEqual(ExpectedReturn, returnedValueFromNotify, 'Unexpected return value from Latch.Notify call for initial count ' + IntToStr(InitialCount) + '.');
|
||||
@@ -144,7 +144,7 @@ procedure TTestMycLatch.TestNotify_DecrementsCounter_StateChanges;
|
||||
var
|
||||
latch: IMycLatch;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
Assert.IsFalse(latch.State.IsSet, 'Latch should initially not be set (Count=1).');
|
||||
latch.Notify; // Count becomes 0
|
||||
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after Notify (Count became 0).');
|
||||
@@ -154,7 +154,7 @@ procedure TTestMycLatch.TestNotify_MultipleNotifies_CounterBecomesNegativeAndSta
|
||||
var
|
||||
latch: IMycLatch;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
latch.Notify; // Count becomes 0, IsSet = True
|
||||
Assert.IsTrue(latch.State.IsSet, 'Latch should be set after first Notify.');
|
||||
latch.Notify; // Count becomes -1, IsSet should remain True
|
||||
@@ -169,7 +169,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub := TMockSubscriber.Create;
|
||||
subscription := latch.State.Subscribe(mockSub); // Subscribing to the Latch's state
|
||||
|
||||
@@ -188,7 +188,7 @@ var
|
||||
mockSub1, mockSub2, mockSub3: TMockSubscriber;
|
||||
sub1, sub2, sub3: TMycSubscription; // Keep subscriptions in scope
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub1 := TMockSubscriber.Create;
|
||||
mockSub2 := TMockSubscriber.Create;
|
||||
mockSub3 := TMockSubscriber.Create;
|
||||
@@ -210,7 +210,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(2); // Count = 2
|
||||
latch := TLatch.Construct(2); // Count = 2
|
||||
mockSub := TMockSubscriber.Create;
|
||||
subscription := latch.State.Subscribe(mockSub);
|
||||
|
||||
@@ -225,7 +225,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub := TMockSubscriber.Create;
|
||||
subscription := latch.State.Subscribe(mockSub);
|
||||
|
||||
@@ -242,7 +242,7 @@ var
|
||||
mockSub1, mockSub2: TMockSubscriber;
|
||||
subscription1, subscription2: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1); // Create with count 1
|
||||
latch := TLatch.Construct(1); // Create with count 1
|
||||
mockSub1 := TMockSubscriber.Create;
|
||||
subscription1 := latch.State.Subscribe(mockSub1); // Subscribe before set
|
||||
|
||||
@@ -270,8 +270,8 @@ var
|
||||
mockSubForB: TMockSubscriber;
|
||||
subHandle_B_listens_A, subHandle_Mock_listens_B: TMycSubscription;
|
||||
begin
|
||||
latchA := TState.CreateLatch(1);
|
||||
latchB := TState.CreateLatch(1); // latchB is an IMycSubscriber
|
||||
latchA := TLatch.Construct(1);
|
||||
latchB := TLatch.Construct(1); // latchB is an IMycSubscriber
|
||||
mockSubForB := TMockSubscriber.Create;
|
||||
|
||||
subHandle_Mock_listens_B := latchB.State.Subscribe(mockSubForB);
|
||||
@@ -295,9 +295,9 @@ var
|
||||
mockSubForC: TMockSubscriber;
|
||||
sub_Mock_C, sub_C_B, sub_B_A: TMycSubscription;
|
||||
begin
|
||||
latchA := TState.CreateLatch(1);
|
||||
latchB := TState.CreateLatch(1);
|
||||
latchC := TState.CreateLatch(1);
|
||||
latchA := TLatch.Construct(1);
|
||||
latchB := TLatch.Construct(1);
|
||||
latchC := TLatch.Construct(1);
|
||||
mockSubForC := TMockSubscriber.Create;
|
||||
|
||||
sub_Mock_C := latchC.State.Subscribe(mockSubForC);
|
||||
@@ -320,8 +320,8 @@ var
|
||||
begin
|
||||
// LatchA needs 2 notifies to become set. LatchB needs 1 notify to become set.
|
||||
// LatchB subscribes to LatchA. So LatchB will be notified once LatchA becomes set.
|
||||
latchA := TState.CreateLatch(2);
|
||||
latchB := TState.CreateLatch(1);
|
||||
latchA := TLatch.Construct(2);
|
||||
latchB := TLatch.Construct(1);
|
||||
mockSubForB := TMockSubscriber.Create;
|
||||
|
||||
sub_Mock_B := latchB.State.Subscribe(mockSubForB);
|
||||
@@ -347,7 +347,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(0); // Returns TMycLatch.Null which is set.
|
||||
latch := TLatch.Construct(0); // Returns TMycLatch.Null which is set.
|
||||
mockSub := TMockSubscriber.Create;
|
||||
|
||||
subscription := latch.State.Subscribe(mockSub); // TMycLatch.Subscribe notifies immediately if already set.
|
||||
@@ -362,7 +362,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub := TMockSubscriber.Create;
|
||||
|
||||
subscription := latch.State.Subscribe(mockSub);
|
||||
@@ -381,7 +381,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
subscription: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(3);
|
||||
latch := TLatch.Construct(3);
|
||||
|
||||
latch.Notify; // Count -> 2
|
||||
latch.Notify; // Count -> 1
|
||||
@@ -404,7 +404,7 @@ var
|
||||
mockSub1, mockSub2: TMockSubscriber;
|
||||
subscription1, subscription2: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub1 := TMockSubscriber.Create;
|
||||
mockSub2 := TMockSubscriber.Create;
|
||||
|
||||
@@ -432,7 +432,7 @@ var
|
||||
mockSub: TMockSubscriber;
|
||||
// 'subscription' will be declared in an inner scope to control its finalization
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSub := TMockSubscriber.Create;
|
||||
|
||||
var noException: Boolean := True;
|
||||
@@ -468,7 +468,7 @@ var
|
||||
mockSubInitial, mockSubNew: TMockSubscriber;
|
||||
subscriptionInitial, subscriptionNew: TMycSubscription;
|
||||
begin
|
||||
latch := TState.CreateLatch(1);
|
||||
latch := TLatch.Construct(1);
|
||||
mockSubInitial := TMockSubscriber.Create;
|
||||
subscriptionInitial := latch.State.Subscribe(mockSubInitial);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user