From 6a5be417d8a0de5baffbef7274386d81478dd017 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:18:38 +0100 Subject: [PATCH] No infinite loopign in tests. only Operate_Minimal works --- BucketChain/Chain.cs | 8 +++----- BucketChain/Person.cs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/BucketChain/Chain.cs b/BucketChain/Chain.cs index 09a9e7f..dda3933 100644 --- a/BucketChain/Chain.cs +++ b/BucketChain/Chain.cs @@ -56,10 +56,8 @@ public sealed class Chain _fire.BurnHigher(); // step 3 - if (_firstPerson is { HasBucket: true }) - { - _firstPerson.UseWell(_well, null); - } + var bucket = new Bucket(_bucketSize); + _firstPerson.UseWell(_well, bucket); // step 4 var currentPerson = _firstPerson; @@ -88,7 +86,7 @@ public sealed class Chain } // Step 5 - if (lastPerson != null && lastPerson.HasBucket) + if (lastPerson is { HasBucket: true }) { lastPerson.FightFire(_fire); } diff --git a/BucketChain/Person.cs b/BucketChain/Person.cs index d60a006..eace2df 100644 --- a/BucketChain/Person.cs +++ b/BucketChain/Person.cs @@ -101,7 +101,7 @@ public sealed class Person return false; } - if (RightNeighbor._forwardBucket == null && _forwardBucket != null) + if ((RightNeighbor._forwardBucket == null || RightNeighbor._forwardBucket.IsEmpty) && _forwardBucket != null) { RightNeighbor._forwardBucket = _forwardBucket; _forwardBucket = null;