public void Count_NoInitialCollection_IsZero() { long capacity = Random.Next(10, MaxCapacity); CyclicConcurrentQueue <bool> cyclicConcurrentQueue = CreateCyclicConcurrentQueue <bool>(capacity); Assert.AreEqual(0, cyclicConcurrentQueue.Count()); }
public void Count_SomethingPeekedSuccessfully_ValueStaysTheSame() { List <int> initialValues = Enumerable.Range(1, Random.Next(10, 10000)).Select(n => Random.Next()).ToList(); long capacity = Random.Next(10, MaxCapacity); CyclicConcurrentQueue <int> cyclicConcurrentQueue = CreateCyclicConcurrentQueue(initialValues, capacity); int previousCount = cyclicConcurrentQueue.Count(); int peeked; if (cyclicConcurrentQueue.TryPeek(out peeked)) { Assert.AreEqual(previousCount, cyclicConcurrentQueue.Count()); } else { Assert.Inconclusive("Could not successfully peek at an item."); } }
public void Count_OneEntryAddedUsingEnqueue_IsOne() { long capacity = Random.Next(10, MaxCapacity); CyclicConcurrentQueue <bool> cyclicConcurrentQueue = CreateCyclicConcurrentQueue <bool>(capacity); cyclicConcurrentQueue.Enqueue(Random.NextDouble() < 0.5); Assert.AreEqual(1, cyclicConcurrentQueue.Count()); }
public void Count_InitialCollectionSmallerThanCapacity_MatchesInitialCollection() { List <Guid> initialValues = Enumerable.Range(1, Random.Next(10, 100)).Select(n => Guid.NewGuid()).ToList(); long capacity = initialValues.Count + (long)(Random.NextDouble() * (MaxCapacity - initialValues.Count)); CyclicConcurrentQueue <Guid> cyclicConcurrentQueue = CreateCyclicConcurrentQueue(initialValues, capacity); Assert.AreEqual(initialValues.Count, cyclicConcurrentQueue.Count()); }
public void Count_MoreAddedUsingEnqueueThanCapacityHolds_IsSameAsCapacity() { long capacity = Random.Next(10, 10000); int overlap = Random.Next(1, 9); CyclicConcurrentQueue <int> cyclicConcurrentQueue = CreateCyclicConcurrentQueue <int>(capacity); for (int i = 0; i < capacity + overlap; i++) { cyclicConcurrentQueue.Enqueue(Random.Next()); } Assert.AreEqual(capacity, cyclicConcurrentQueue.Count()); }
public void Count_MultipleEntriesAddedUsingEnqueue_IsOne() { long capacity = Random.Next(10, MaxCapacity); int count = Random.Next(2, capacity > 10000 ? 10000 : (int)capacity); CyclicConcurrentQueue <bool> cyclicConcurrentQueue = CreateCyclicConcurrentQueue <bool>(capacity); for (int i = 0; i < count; i++) { cyclicConcurrentQueue.Enqueue(Random.NextDouble() < 0.5); } Assert.AreEqual(count, cyclicConcurrentQueue.Count()); }