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()); }
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); } }
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); }