예제 #1
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]);
            }
        }
예제 #2
0
 public void CanIterateOverEmptyList()
 {
     LinkedIntList list = new LinkedIntList();
     Assert.Empty(list);
     foreach (var value in list) {
         throw new Exception("There should be no values in an empty list");
     }
 }
예제 #3
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);
 }
예제 #4
0
        public void CanIterateOverEmptyList()
        {
            LinkedIntList list = new LinkedIntList();

            Assert.Empty(list);
            foreach (var value in list)
            {
                throw new Exception("There should be no values in an empty list");
            }
        }
예제 #5
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);
        }
예제 #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 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());
        }
예제 #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 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);
        }
예제 #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);
            }
        }
예제 #11
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]);
            }
        }
예제 #12
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);
            }
        }