get() public method

public get ( int i ) : int
i int index to Read, must be in the range [0, ).
return int
示例#1
0
        public void testAdd_LargeGroup()
        {
            IntList i = new IntList();
            int n = 500;
            for (int v = 0; v < n; v++)
                i.add(10 + v);

            Assert.AreEqual(n, i.size());

            for (int v = 0; v < n; v++)
                Assert.AreEqual(10 + v, i.get(v));

            try
            {
                i.get(n);
                Assert.Fail("Accepted out of bound index on list");
            }
            catch (IndexOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }
示例#2
0
 public void testEmpty_SpecificCapacity()
 {
     IntList i = new IntList(5);
     Assert.AreEqual(0, i.size());
     try
     {
         i.get(0);
         Assert.Fail("Accepted 0 index on empty list");
     }
     catch (IndexOutOfRangeException)
     {
         Assert.IsTrue(true);
     }
 }
示例#3
0
        public void testSet()
        {
            IntList i = new IntList();
            i.add(1);
            Assert.AreEqual(1, i.size());
            Assert.AreEqual(1, i.get(0));

            i.set(0, 5);
            Assert.AreEqual(5, i.get(0));

            AssertHelper.Throws<ArgumentException>(() => i.set(5, 5), "accepted set of 5 beyond end of list");

            i.set(1, 2);
            Assert.AreEqual(2, i.size());
            Assert.AreEqual(2, i.get(1));
        }
示例#4
0
        public void testClear()
        {
            IntList i = new IntList();
            int n = 5;
            for (int v = 0; v < n; v++)
                i.add(10 + v);
            Assert.AreEqual(n, i.size());

            i.clear();
            Assert.AreEqual(0, i.size());

            try
            {
                i.get(0);
                Assert.Fail("Accepted 0 index on empty list");
            }
            catch (IndexOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }
示例#5
0
 public void testFillTo100()
 {
     IntList i = new IntList();
     i.fillTo(100, int.MinValue);
     Assert.AreEqual(100, i.size());
     i.add(3);
     Assert.AreEqual(int.MinValue, i.get(99));
     Assert.AreEqual(3, i.get(100));
 }
示例#6
0
 public void testFillTo1()
 {
     IntList i = new IntList();
     i.fillTo(1, int.MinValue);
     Assert.AreEqual(1, i.size());
     i.add(0);
     Assert.AreEqual(int.MinValue, i.get(0));
     Assert.AreEqual(0, i.get(1));
 }
示例#7
0
 public void testAdd_ZeroCapacity()
 {
     IntList i = new IntList(0);
     Assert.AreEqual(0, i.size());
     i.add(1);
     Assert.AreEqual(1, i.get(0));
 }