예제 #1
0
        public void TestSize()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Count);
                list.Add(j);
                Assert.AreEqual(j + 1, list.Count);
            }
            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(1000 - j, list.Count);
                list.RemoveValue(j);
                Assert.AreEqual(999 - j, list.Count);
            }
        }
예제 #2
0
        public void TestIsEmpty()
        {
            IntList list1 = new IntList();
            IntList list2 = new IntList(1000);
            IntList list3 = new IntList(list1);

            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
            list1.Add(1);
            list2.Add(2);
            list3 = new IntList(list2);
            Assert.IsTrue(!list1.IsEmpty());
            Assert.IsTrue(!list2.IsEmpty());
            Assert.IsTrue(!list3.IsEmpty());
            list1.Clear();
            list2.Remove(0);
            list3.RemoveValue(2);
            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
        }
예제 #3
0
        public void TestRemoveValue()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j / 2);
            }
            for (int j = 0; j < 1000; j++)
            {
                if (j < 500)
                {
                    Assert.IsTrue(list.RemoveValue(j));
                    Assert.IsTrue(list.RemoveValue(j));
                }
                Assert.IsTrue(!list.RemoveValue(j));
            }
        }
예제 #4
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));
        }