示例#1
0
 public void CanAddIntAndMaintainCount()
 {
     LinkedIntList intList = new LinkedIntList();
     Assert.Equal(0, intList.Count);
     intList.Add(1);
     Assert.Equal(1, intList.Count);
     intList.Add(2);
     Assert.Equal(2, intList.Count);
 }
示例#2
0
        public void CanAddIntAndMaintainCount()
        {
            LinkedIntList intList = new LinkedIntList();

            Assert.Equal(0, intList.Count);
            intList.Add(1);
            Assert.Equal(1, intList.Count);
            intList.Add(2);
            Assert.Equal(2, intList.Count);
        }
示例#3
0
        public void FifthLastReturnsAKnownValue()
        {
            // this is just a final sanity test

            LinkedIntList list = new LinkedIntList();
            list.Add(134);
            list.Add(5823);
            list.Add(-12);
            list.Add(0);
            list.Add(132);
            list.Add(5209);

            Assert.Equal(5823, list.GetFifthLast());
            list.Add(1305);
            Assert.Equal(-12, list.GetFifthLast());
        }
示例#4
0
        public void CanIterate()
        {
            int[]         testInts = new int[] { 0, 2, 3, 1243, -13 };
            LinkedIntList intList  = new LinkedIntList();

            for (int i = 0; i < testInts.Length; i++)
            {
                Assert.Equal(i, intList.Count);
                intList.Add(testInts[i]);
            }

            int[] resultInts = new int[intList.Count];
            int   index      = 0;

            // iterate and save values
            foreach (int intValue in intList)
            {
                resultInts[index++] = intValue;
            }

            // Compare the two results
            Assert.Equal(testInts.Length, resultInts.Length);
            for (int i = 0; i < testInts.Length; i++)
            {
                Assert.Equal(testInts[i], resultInts[i]);
            }
        }
示例#5
0
        public void FifthLastReturnsAppropriateValues()
        {
            LinkedIntList list = new LinkedIntList();

            int initialListCount = 5;

            // seed the list with values 1 - 5
            for (int i = 1; i <= initialListCount; i++)
            {
                Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
                list.Add(i);
            }

            // Check values as we add more
            for (int i = 1; i <= 5; i++)
            {
                Assert.Equal(i, list.GetFifthLast());
                list.Add(i + initialListCount);
            }
        }
示例#6
0
        public void FifthLastReturnsAKnownValue()
        {
            // this is just a final sanity test

            LinkedIntList list = new LinkedIntList();

            list.Add(134);
            list.Add(5823);
            list.Add(-12);
            list.Add(0);
            list.Add(132);
            list.Add(5209);

            Assert.Equal(5823, list.GetFifthLast());
            list.Add(1305);
            Assert.Equal(-12, list.GetFifthLast());
        }
示例#7
0
 public void FifthLastErrorsWithLessThanFiveElements()
 {
     LinkedIntList list = new LinkedIntList();
     Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
     list.Add(1);
     Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
     list.Add(2);
     Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
     list.Add(3);
     Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
     list.Add(4);
     Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
     list.Add(5);
     Assert.DoesNotThrow((() => { list.GetFifthLast(); }));
     list.Add(6);
     Assert.DoesNotThrow((() => { list.GetFifthLast(); }));
     list.Add(7);
 }
示例#8
0
        public void FifthLastErrorsWithLessThanFiveElements()
        {
            LinkedIntList list = new LinkedIntList();

            Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
            list.Add(1);
            Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
            list.Add(2);
            Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
            list.Add(3);
            Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
            list.Add(4);
            Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
            list.Add(5);
            Assert.DoesNotThrow((() => { list.GetFifthLast(); }));
            list.Add(6);
            Assert.DoesNotThrow((() => { list.GetFifthLast(); }));
            list.Add(7);
        }
示例#9
0
        public void CanIterate()
        {
            int[] testInts = new int[] { 0, 2, 3, 1243, -13 };
            LinkedIntList intList = new LinkedIntList();

            for (int i = 0; i < testInts.Length; i++) {
                Assert.Equal(i, intList.Count);
                intList.Add(testInts[i]);
            }

            int[] resultInts = new int[intList.Count];
            int index = 0;
            // iterate and save values
            foreach (int intValue in intList) {
                resultInts[index++] = intValue;
            }

            // Compare the two results
            Assert.Equal(testInts.Length, resultInts.Length);
            for (int i = 0; i < testInts.Length; i++) {
                Assert.Equal(testInts[i], resultInts[i]);
            }
        }
示例#10
0
        public void FifthLastReturnsAppropriateValues()
        {
            LinkedIntList list = new LinkedIntList();

            int initialListCount = 5;
            // seed the list with values 1 - 5
            for (int i = 1; i <= initialListCount; i++) {
                Assert.Throws(typeof(IndexOutOfRangeException), (() => { list.GetFifthLast(); }));
                list.Add(i);
            }

            // Check values as we add more
            for (int i = 1; i <= 5; i++) {
                Assert.Equal(i, list.GetFifthLast());
                list.Add(i + initialListCount);
            }
        }