コード例 #1
0
        public void TestSet()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            Assert.AreEqual(two, full.Set(2, four).ToString());
            Assert.AreEqual(4.ToString(), full.Get(2));
        }
コード例 #2
0
        public void TestSubList()
        {
            CopyOnWriteArrayList <Object> a = PopulatedArray(10);

            Assert.IsTrue(a.SubList(1, 1).IsEmpty());

            for (int j = 0; j < 9; ++j)
            {
                for (int i = j; i < 10; ++i)
                {
                    List <Object> b = a.SubList(j, i);
                    for (int k = j; k < i; ++k)
                    {
                        Assert.AreEqual(k, b.Get(k - j));
                    }
                }
            }

            List <Object> s = a.SubList(2, 5);

            Assert.AreEqual(s.Size(), 3);
            s.Set(2, m1);
            Assert.AreEqual(a.Get(4), m1);
            s.Clear();
            Assert.AreEqual(a.Size(), 7);
        }
コード例 #3
0
        public void TestAddIfAbsent2()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(SIZE);

            full.AddIfAbsent(three);
            Assert.IsTrue(full.Contains(three));
        }
コード例 #4
0
        public void TestIndexOf2()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            Assert.AreEqual(1, full.IndexOf(1, 0));
            Assert.AreEqual(-1, full.IndexOf(1, 2));
        }
コード例 #5
0
        public void TestContains()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            Assert.IsTrue(full.Contains(1));
            Assert.IsFalse(full.Contains(5));
        }
コード例 #6
0
            public int LastIndexOf(E o)
            {
                SubListReadData b   = read;
                int             ind = CopyOnWriteArrayList <E> .LastIndexOf(o, b.Data, start, b.Size) - start;

                return(ind < 0 ? -1 : ind);
            }
コード例 #7
0
        public void TestClear()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(SIZE);

            full.Clear();
            Assert.AreEqual(0, full.Size());
        }
コード例 #8
0
        public void TestRemove()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            Assert.AreEqual(two, full.Remove(2).ToString());
            Assert.AreEqual(2, full.Size());
        }
コード例 #9
0
        public void TestAddIfAbsent()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(SIZE);

            full.AddIfAbsent(1);
            Assert.AreEqual(SIZE, full.Size());
        }
コード例 #10
0
        public void TestIsEmpty()
        {
            CopyOnWriteArrayList <Object> empty = new CopyOnWriteArrayList <Object>();
            CopyOnWriteArrayList <Object> full  = PopulatedArray(SIZE);

            Assert.IsTrue(empty.IsEmpty());
            Assert.IsFalse(full.IsEmpty());
        }
コード例 #11
0
        public void TestSize()
        {
            CopyOnWriteArrayList <Object> empty = new CopyOnWriteArrayList <Object>();
            CopyOnWriteArrayList <Object> full  = PopulatedArray(SIZE);

            Assert.AreEqual(SIZE, full.Size());
            Assert.AreEqual(0, empty.Size());
        }
コード例 #12
0
        public void TestLastIndexOf2()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            full.Add(one);
            full.Add(three);
            Assert.AreEqual(3, full.LastIndexOf(one, 4));
            Assert.AreEqual(-1, full.LastIndexOf(three, 3));
        }
コード例 #13
0
        public void TestClone()
        {
            CopyOnWriteArrayList <Object> l1 = PopulatedArray(SIZE);
            CopyOnWriteArrayList <Object> l2 = (CopyOnWriteArrayList <Object>)(l1.Clone());

            Assert.AreEqual(l1, l2);
            l1.Clear();
            Assert.IsFalse(l1.Equals(l2));
        }
コード例 #14
0
 public void TestGet2IndexOutOfBoundsException()
 {
     try {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.Add("asdasd");
         c.Add("asdad");
         c.Get(100);
         ShouldThrow();
     } catch (IndexOutOfRangeException) {}
 }
コード例 #15
0
        public void TestToArray()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);

            Object[] o = full.ToArray();
            Assert.AreEqual(3, o.Length);
            Assert.AreEqual(0, o[0]);
            Assert.AreEqual(1, o[1]);
            Assert.AreEqual(2, o[2]);
        }
コード例 #16
0
        public void TestToString()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            String s = full.ToString();

            for (int i = 0; i < 3; ++i)
            {
                Assert.IsTrue(s.IndexOf(i.ToString()) >= 0);
            }
        }
コード例 #17
0
        public void TestRemoveAll()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            ArrayList <Object>            v    = new ArrayList <Object>();

            v.Add(1);
            v.Add(2);
            full.RemoveAll(v);
            Assert.AreEqual(1, full.Size());
        }
コード例 #18
0
        public void TestAddAllAbsent()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            ArrayList <Object>            v    = new ArrayList <Object>();

            v.Add(3);
            v.Add(4);
            v.Add(1); // will not Add this element
            full.AddAllAbsent(v);
            Assert.AreEqual(5, full.Size());
        }
コード例 #19
0
        public void TestAddAll()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            ArrayList <Object>            v    = new ArrayList <Object>();

            v.Add(three);
            v.Add(four);
            v.Add(five);
            full.AddAll(v);
            Assert.AreEqual(6, full.Size());
        }
コード例 #20
0
 public void TestSubList3IndexOutOfBoundsException()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.SubList(3, 1);
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #21
0
 public void TestListIterator1IndexOutOfBoundsException()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.ListIterator(-1);
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #22
0
 public void TestAddAll1IndexOutOfBoundsException()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.AddAll(-1, new ArrayList <Object>());
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #23
0
 public void TestRemove1IndexOutOfBounds()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.Remove(-1);
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #24
0
 public void TestSet1IndexOutOfBoundsException()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.Set(-1, "qwerty");
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #25
0
        public void TestContainsAll()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            ArrayList <Object>            v    = new ArrayList <Object>();

            v.Add(1);
            v.Add(2);
            Assert.IsTrue(full.ContainsAll(v));
            v.Add(6);
            Assert.IsFalse(full.ContainsAll(v));
        }
コード例 #26
0
            public SubListImpl(CopyOnWriteArrayList <E> list, int fromIdx, int toIdx)
            {
                this.list = list;
                Object[] data = list.Data;
                int      size = toIdx - fromIdx;

                CheckIndexExlusive(fromIdx, data.Length);
                CheckIndexInclusive(toIdx, data.Length);
                read  = new SubListReadData(size, list.Data);
                start = fromIdx;
            }
コード例 #27
0
        public void TestIterator()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(SIZE);
            Iterator <Object>             i    = full.Iterator();
            int j;

            for (j = 0; i.HasNext; j++)
            {
                Assert.AreEqual(j, i.Next());
            }
            Assert.AreEqual(SIZE, j);
        }
コード例 #28
0
        public void TestListIterator2()
        {
            CopyOnWriteArrayList <Object> full = PopulatedArray(3);
            ListIterator <Object>         i    = full.ListIterator(1);
            int j;

            for (j = 0; i.HasNext; j++)
            {
                Assert.AreEqual(j + 1, i.Next());
            }
            Assert.AreEqual(2, j);
        }
コード例 #29
0
 public void TestSet2()
 {
     try
     {
         CopyOnWriteArrayList <Object> c = new CopyOnWriteArrayList <Object>();
         c.Add("asdasd");
         c.Add("asdad");
         c.Set(100, "qwerty");
         ShouldThrow();
     }
     catch (IndexOutOfRangeException)
     {}
 }
コード例 #30
0
 public virtual Object Clone()
 {
     try
     {
         CopyOnWriteArrayList <E> thisClone = (CopyOnWriteArrayList <E>)base.MemberwiseClone();
         thisClone.Data = this.Data;
         return(thisClone);
     }
     catch (NotSupportedException)
     {
         throw new ApplicationException("NotSupportedException is not expected here");
     }
 }