Ejemplo n.º 1
0
        public void TestConstructors()
        {
            IntList list = new IntList();

            Assert.IsTrue(list.IsEmpty());
            list.Add(0);
            list.Add(1);
            IntList list2 = new IntList(list);

            //Assert.AreEqual(list, list2);
            Assert.IsTrue(list.Equals(list2));
            IntList list3 = new IntList(2);

            Assert.IsTrue(list3.IsEmpty());
        }
Ejemplo n.º 2
0
        public void TestRetainAll()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            IntList listCopy = new IntList(list);
            IntList listOdd = new IntList();
            IntList listEven = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                if (j % 2 == 0)
                {
                    listEven.Add(j);
                }
                else
                {
                    listOdd.Add(j);
                }
            }
            list.RetainAll(listOdd);
            //Assert.AreEqual(list, listOdd);
            Assert.IsTrue(list.Equals(listOdd));
            list.RetainAll(listEven);
            Assert.IsTrue(list.IsEmpty());
            listCopy.RetainAll(listEven);
            //Assert.AreEqual(listCopy, listEven);
            Assert.IsTrue(listCopy.Equals(listEven));
            listCopy.RetainAll(listOdd);
            Assert.IsTrue(listCopy.IsEmpty());
        }
Ejemplo n.º 3
0
        public void TestEquals()
        {
            IntList list = new IntList();

            Assert.AreEqual(list, list);
            Assert.IsTrue(!list.Equals(null));
            IntList list2 = new IntList(200);

            Assert.IsTrue(list.Equals(list2));//Assert.AreEqual(list, list2);
            Assert.IsTrue(list2.Equals(list));//Assert.AreEqual(list2, list);
            Assert.AreEqual(list.GetHashCode(), list2.GetHashCode());
            list.Add(0);
            list.Add(1);
            list2.Add(1);
            list2.Add(0);
            Assert.IsTrue(!list.Equals(list2));
            list2.RemoveValue(1);
            list2.Add(1);
            Assert.IsTrue(list.Equals(list2));//Assert.AreEqual(list, list2);
            Assert.IsTrue(list2.Equals(list));//Assert.AreEqual(list2, list);
            list2.Add(2);
            Assert.IsTrue(!list.Equals(list2));
            Assert.IsTrue(!list2.Equals(list));
        }
Ejemplo n.º 4
0
        public void TestAddAll()
        {
            IntList list = new IntList();

            for (int j = 0; j < 5; j++)
            {
                list.Add(j);
            }
            IntList list2 = new IntList(0);

            list2.AddAll(list);
            list2.AddAll(list);
            Assert.AreEqual(2 * list.Count, list2.Count);
            for (int j = 0; j < 5; j++)
            {
                Assert.AreEqual(list2.Get(j), j);
                Assert.AreEqual(list2.Get(j + list.Count), j);
            }
            IntList empty = new IntList();
            int limit = list.Count;

            for (int j = 0; j < limit; j++)
            {
                Assert.IsTrue(list.AddAll(j, empty));
                Assert.AreEqual(limit, list.Count);
            }
            try
            {
                list.AddAll(limit + 1, empty);
                Assert.Fail("should have thrown an exception");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }

            // try add at beginning
            empty.AddAll(0, list);
            //Assert.AreEqual(empty, list);
            Assert.IsTrue(empty.Equals(list));

            // try in the middle
            empty.AddAll(1, list);
            Assert.AreEqual(2 * list.Count, empty.Count);
            Assert.AreEqual(list.Get(0), empty.Get(0));
            Assert.AreEqual(list.Get(0), empty.Get(1));
            Assert.AreEqual(list.Get(1), empty.Get(2));
            Assert.AreEqual(list.Get(1), empty.Get(6));
            Assert.AreEqual(list.Get(2), empty.Get(3));
            Assert.AreEqual(list.Get(2), empty.Get(7));
            Assert.AreEqual(list.Get(3), empty.Get(4));
            Assert.AreEqual(list.Get(3), empty.Get(8));
            Assert.AreEqual(list.Get(4), empty.Get(5));
            Assert.AreEqual(list.Get(4), empty.Get(9));

            // try at the end
            empty.AddAll(empty.Count, list);
            Assert.AreEqual(3 * list.Count, empty.Count);
            Assert.AreEqual(list.Get(0), empty.Get(0));
            Assert.AreEqual(list.Get(0), empty.Get(1));
            Assert.AreEqual(list.Get(0), empty.Get(10));
            Assert.AreEqual(list.Get(1), empty.Get(2));
            Assert.AreEqual(list.Get(1), empty.Get(6));
            Assert.AreEqual(list.Get(1), empty.Get(11));
            Assert.AreEqual(list.Get(2), empty.Get(3));
            Assert.AreEqual(list.Get(2), empty.Get(7));
            Assert.AreEqual(list.Get(2), empty.Get(12));
            Assert.AreEqual(list.Get(3), empty.Get(4));
            Assert.AreEqual(list.Get(3), empty.Get(8));
            Assert.AreEqual(list.Get(3), empty.Get(13));
            Assert.AreEqual(list.Get(4), empty.Get(5));
            Assert.AreEqual(list.Get(4), empty.Get(9));
            Assert.AreEqual(list.Get(4), empty.Get(14));
        }