public void TestOffer()
        {
            LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>(1);

            Assert.IsTrue(q.Offer(zero));
            Assert.IsFalse(q.Offer(one));
        }
 public void TestAddAllSelf()
 {
     try
     {
         LinkedBlockingQueue <String> q = PopulatedDeque(SIZE);
         q.AddAll(q);
         ShouldThrow();
     }
     catch (ArgumentException) {}
 }
 public void TestAddAll1()
 {
     try
     {
         LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>(1);
         q.AddAll(null);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestOfferNull()
 {
     try
     {
         LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>();
         q.Offer(null);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
        public void TestEmptyFull()
        {
            LinkedBlockingQueue <String> q = new LinkedBlockingQueue <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));
        }
        private LinkedBlockingQueue <String> PopulatedDeque(int n)
        {
            LinkedBlockingQueue <String> q = new LinkedBlockingQueue <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 TestAddAll2()
 {
     try
     {
         LinkedBlockingQueue <String> q       = new LinkedBlockingQueue <String>(SIZE);
         ArrayList <String>           strings = new ArrayList <String>();
         strings.Add(null);
         strings.Add(null);
         strings.Add(null);
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestAddAll4()
 {
     try
     {
         LinkedBlockingQueue <String> q       = new LinkedBlockingQueue <String>(1);
         ArrayList <String>           strings = new ArrayList <String>();
         for (int i = 0; i < SIZE - 1; ++i)
         {
             strings.Add(i.ToString());
         }
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (IllegalStateException) {}
 }
        public void TestConstructor6()
        {
            ArrayList <String> strings = new ArrayList <String>();

            for (int i = 0; i < SIZE; ++i)
            {
                strings.Add(i.ToString());
            }
            LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>(strings);

            for (int i = 0; i < SIZE; ++i)
            {
                Assert.AreEqual(strings.Get(i), q.Poll());
            }
        }
 public void TestPutNull()
 {
     try
     {
         LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>(SIZE);
         q.Put(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception)
     {
         UnexpectedException();
     }
 }
 public void TestAddAll3()
 {
     try
     {
         LinkedBlockingQueue <String> q       = new LinkedBlockingQueue <String>(SIZE);
         ArrayList <String>           strings = new ArrayList <String>();
         for (int i = 0; i < SIZE - 1; ++i)
         {
             strings.Add(i.ToString());
         }
         strings.Add(null);
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestAdd()
 {
     try
     {
         LinkedBlockingQueue <String> q = new LinkedBlockingQueue <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)
     {
     }
 }
Esempio n. 13
0
            public LBQIterator(LinkedBlockingQueue <E> parent)
            {
                this.parent = parent;

                parent.FullyLock();
                try {
                    current = parent.head.next;
                    if (current != null)
                    {
                        currentElement = current.item;
                    }
                }
                finally
                {
                    parent.FullyUnlock();
                }
            }
 public void TestPut()
 {
     try
     {
         LinkedBlockingQueue <String> q = new LinkedBlockingQueue <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();
     }
 }
        public void TestRemainingCapacity()
        {
            LinkedBlockingQueue <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());
            }
        }
        public void TestAddAll5()
        {
            ArrayList <String> empty   = new ArrayList <String>();
            ArrayList <String> strings = new ArrayList <String>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                strings.Add(i.ToString());
            }
            LinkedBlockingQueue <String> q = new LinkedBlockingQueue <String>(SIZE);

            Assert.IsFalse(q.AddAll(empty));
            Assert.IsTrue(q.AddAll(strings));
            for (int i = 0; i < SIZE; ++i)
            {
                Assert.AreEqual(strings.Get(i), q.Poll());
            }
        }