Skip to content

Commit 004284b

Browse files
committed
Recover size check to pass the same test
1 parent bef0aae commit 004284b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

LLama/Common/FixedSizeQueue.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,25 @@ public FixedSizeQueue(int size, IEnumerable<T> data)
6767
throw new ArgumentException($"The max size set for the queue is {size}, but got {dataCount} initial values.");
6868
#endif
6969

70+
if (data is ICollection<T> collection)
71+
{
72+
if (collection.Count > size)
73+
throw new ArgumentException($"The max size set for the queue is {size}, but got {collection.Count} initial values.");
74+
75+
foreach (var item in collection)
76+
Enqueue(item);
77+
return;
78+
}
79+
80+
var index = 0;
7081
foreach (var item in data)
82+
{
83+
if (index >= size)
84+
throw new ArgumentException($"The max size set for the queue is {size}, but got {index + 1} initial values.");
85+
7186
Enqueue(item);
87+
index++;
88+
}
7289
}
7390

7491
/// <summary>

0 commit comments

Comments
 (0)