public void TestEmptyFull() { LinkedBlockingDeque <String> q = new LinkedBlockingDeque <String>(2); Assert.IsTrue(q.IsEmpty()); Assert.AreEqual(2, q.RemainingCapacity(), "should have room for 2"); q.Add(one); Assert.IsFalse(q.IsEmpty()); q.Add(two); Assert.IsFalse(q.IsEmpty()); Assert.AreEqual(0, q.RemainingCapacity()); Assert.IsFalse(q.Offer(three)); }
public void TestRemainingCapacity() { LinkedBlockingDeque <String> q = PopulatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { Assert.AreEqual(i, q.RemainingCapacity()); Assert.AreEqual(SIZE - i, q.Size()); q.Remove(); } for (int i = 0; i < SIZE; ++i) { Assert.AreEqual(SIZE - i, q.RemainingCapacity()); Assert.AreEqual(i, q.Size()); q.Add(i.ToString()); } }
private LinkedBlockingDeque <String> PopulatedDeque(int n) { LinkedBlockingDeque <String> q = new LinkedBlockingDeque <String>(n); Assert.IsTrue(q.IsEmpty()); for (int i = 0; i < n; i++) { Assert.IsTrue(q.Offer(i.ToString())); } Assert.IsFalse(q.IsEmpty()); Assert.AreEqual(0, q.RemainingCapacity()); Assert.AreEqual(n, q.Size()); return(q); }
public void TestAdd() { try { LinkedBlockingDeque <String> q = new LinkedBlockingDeque <String>(SIZE); for (int i = 0; i < SIZE; ++i) { Assert.IsTrue(q.Add(i.ToString())); } Assert.AreEqual(0, q.RemainingCapacity()); q.Add(SIZE.ToString()); } catch (IllegalStateException) { } }
public void TestPut() { try { LinkedBlockingDeque <String> q = new LinkedBlockingDeque <String>(SIZE); for (int i = 0; i < SIZE; ++i) { q.Put(i.ToString()); Assert.IsTrue(q.Contains(i.ToString())); } Assert.AreEqual(0, q.RemainingCapacity()); } catch (Exception) { UnexpectedException(); } }