public void LimitedSizeQueueCanClearItems() { var q = new LimitedSizeQueue <int>(3); Assert.IsTrue(q.TryEnqueue(1)); Assert.IsTrue(q.TryEnqueue(2)); Assert.IsTrue(q.TryEnqueue(3)); Assert.IsFalse(q.TryEnqueue(4)); Assert.AreEqual(3, q.Count); Assert.AreEqual(3, q.Limit); q.Clear(); Assert.AreEqual(0, q.Count); Assert.AreEqual(3, q.Limit); var items = string.Join(", ", q.Select(i => i.ToString()).ToArray()); Assert.AreEqual(string.Empty, items); }
public void LimitedSizeQueueLimitsTheSizeOfTheInternalQueue() { var q = new LimitedSizeQueue <int>(3); Assert.AreEqual(0, q.Count); Assert.AreEqual(3, q.Limit); Assert.IsFalse(q.TryPeek(out _)); Assert.IsFalse(q.TryDequeue(out _)); Assert.IsTrue(q.TryEnqueue(1)); Assert.IsTrue(q.TryEnqueue(2)); Assert.IsTrue(q.TryEnqueue(3)); Assert.IsFalse(q.TryEnqueue(4)); Assert.IsFalse(q.TryEnqueue(5)); var items = string.Join(", ", q.Select(i => i.ToString()).ToArray()); Assert.AreEqual("1, 2, 3", items); Assert.IsTrue(q.TryDequeue(out var item)); Assert.AreEqual(1, item); Assert.IsTrue(q.TryEnqueue(6)); Assert.IsFalse(q.TryEnqueue(7)); Assert.IsTrue(q.TryDequeue(out item)); Assert.AreEqual(2, item); Assert.IsTrue(q.TryDequeue(out item)); Assert.AreEqual(3, item); Assert.IsTrue(q.TryPeek(out item)); Assert.AreEqual(6, item); Assert.IsTrue(q.TryDequeue(out item)); Assert.AreEqual(6, item); Assert.IsFalse(q.TryPeek(out _)); Assert.IsFalse(q.TryDequeue(out _)); }