// tests that a list with nodes were created by finding nodes in a created list public void ShouldCreateListAndNodes(int arrIdx, string cerVal) { CerealList testList = Program.CreateInitialList(); string[] testArr = testList.ListToArr(5); Assert.Equal(cerVal, testArr[arrIdx]); }
public void ShouldThrowExceptionForImproperInput() { CerealList testList = Program.CreateInitialList(); var exception = Record.Exception(() => Program.CerealKthFromEnd(testList, 8)); Assert.IsType <ArgumentException>(exception); }
// tests that an LL with only one node just gets returned public void ShouldReturnSingleEntryList() { CerealList testList = new CerealList(new Cereal("Raisin Bran")); Program.ReverseLL(testList); string[] testArr = testList.ListToArr(1); Assert.Equal("Raisin Bran", testArr[0]); }
// tests that the test LL is being reversed public void ShouldReverseTheLL(string cereal, int index) { CerealList testList = Program.generateListForTesting(); Program.ReverseLL(testList); string[] testArr = testList.ListToArr(4); Assert.Equal(cereal, testArr[index]); }
public void ShouldMergeWhenListAIsLonger(int index, string expectedOutput) { CerealList GeneralMills = Program.genListOne(); CerealList Post = Program.genListThree(); CerealList CombinedList = Program.Merge(GeneralMills, Post); string[] CombinedArr = CombinedList.ListToArr(6); Assert.Equal(expectedOutput, CombinedArr[index]); }
static void UserLoop(CerealList MyCereal) { char userPick = UserOptions(); if (userPick != '6') { PerformAction(userPick, MyCereal); } }
public void ShouldMergeWhenListBIsLonger(int index, string expectedOutput) { CerealList Post = Program.genListThree(); CerealList Kellogs = Program.genListTwo(); CerealList CombinedList = Program.Merge(Post, Kellogs); string[] CombinedArr = CombinedList.ListToArr(6); Assert.Equal(expectedOutput, CombinedArr[index]); }
public void ShouldAddCerealToListEnd() { CerealList testList = Program.CreateInitialList(); Cereal frostedFlakes = new Cereal("Frosted Flakes"); testList.AppendCereal(frostedFlakes); string[] testArr = testList.ListToArr(6); Assert.Equal("Frosted Flakes", testArr[5]); }
public void ShouldMergeEqualLengthLists(int index, string expectedOutput) { CerealList GeneralMills = Program.genListOne(); CerealList Kellogs = Program.genListTwo(); CerealList CombinedList = Program.Merge(GeneralMills, Kellogs); string[] CombinedArr = CombinedList.ListToArr(8); Assert.Equal(expectedOutput, CombinedArr[index]); }
/// <summary> /// A method for generating a CerealList to use for testing /// </summary> /// <returns>The Cereal list we will use to test</returns> public static CerealList generateListForTesting() { CerealList testList = new CerealList(new Cereal("Lucky Charms")); testList.AppendCereal(new Cereal("Fruit Loops")); testList.AppendCereal(new Cereal("Frosted Flakes")); testList.AppendCereal(new Cereal("Cocoa Puffs")); return(testList); }
public void ShouldAddCerealAfterFruitLoops() { CerealList testList = Program.CreateInitialList(); Cereal frostedFlakes = new Cereal("Frosted Flakes"); testList.AddAfter(frostedFlakes, "Fruit Loops"); string[] testArr = testList.ListToArr(6); Assert.Equal("Frosted Flakes", testArr[2]); Assert.Equal("Fruit Loops", testArr[1]); }
/// <summary> /// This is a method to quickly generate Cereal lists, mostly for testing purposes /// </summary> /// <param name="cerealList">An array of strings to be turned into cereals</param> /// <returns>A CerealList full of Cereals generated from input array</returns> public static CerealList generateList(string[] cerealList) { CerealList temp = new CerealList(new Cereal(cerealList[0])); for (int i = 1; i < cerealList.Length; i++) { temp.AddCereal(new Cereal(cerealList[i])); } return(temp); }
// tests that the method can reverse a longer LL with an odd number of nodes public void ShouldReverseOddNumberLL(string cereal, int index) { CerealList testList = Program.generateListForTesting(); testList.AddCereal(new Cereal("Fruity Yummy Mummy")); testList.AddCereal(new Cereal("Cap'n Crunch")); testList.AddCereal(new Cereal("Golden Grahams")); Program.ReverseLL(testList); string[] testArr = testList.ListToArr(7); Assert.Equal(cereal, testArr[index]); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); CerealList MyCereal = CreateInitialList(); Console.WriteLine("Here's a list of cereals!"); MyCereal.PrintList(); UserLoop(MyCereal); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); CerealList testList = generateListForTesting(); // Print the list testList.PrintList(); // Reverse the list ReverseLL(testList); // Print the list again, showing that it has been reversed testList.PrintList(); Console.ReadKey(); }
public static void Main(string[] args) { Console.WriteLine("Hello World!"); CerealList GeneralMills = genListOne(); CerealList Kellogs = genListTwo(); Console.WriteLine("General Mills"); GeneralMills.PrintList(); Console.WriteLine("Kellogs"); Kellogs.PrintList(); Merge(GeneralMills, Kellogs); Console.WriteLine("Combined"); GeneralMills.PrintList(); Console.ReadKey(); }
/// <summary> /// Creates a list of cereals to start the user off /// Also useful for testing /// </summary> /// <returns>A CerealList with a set of Cereal nodes already in it</returns> public static CerealList CreateInitialList() { Cereal LuckyCharms = new Cereal("Lucky Charms"); CerealList StarterList = new CerealList(LuckyCharms); Cereal AppleJacks = new Cereal("Apple Jacks"); Cereal Trix = new Cereal("Trix"); Cereal FruitLoops = new Cereal("Fruit Loops"); Cereal CocoaPebbles = new Cereal("Cocoa Pebbles"); StarterList.AddCereal(AppleJacks); StarterList.AppendCereal(Trix); StarterList.AddBefore(FruitLoops, "Lucky Charms"); StarterList.AddAfter(CocoaPebbles, "Lucky Charms"); return(StarterList); }
/// <summary> /// Reverses a CerealList in place /// </summary> /// <param name="LL">The Linked List (CerealList in this case) to be reversed</param> /// <returns>The list that was input, which will be reversed</returns> public static CerealList ReverseLL(CerealList LL) { LL.Current = LL.Head; Cereal tempPrev = null; while (LL.Current.Next != null) { Cereal tempNext = LL.Current.Next; LL.Current.Next = tempPrev; tempPrev = LL.Current; LL.Current = tempNext; } LL.Current.Next = tempPrev; LL.Head = LL.Current; return(LL); }
static void PerformAction(char pick, CerealList MyCereal) { Cereal newCer = null; string oldCer = null; Console.WriteLine("\n"); switch (pick) { case '1': newCer = new Cereal(GetNewCereal()); MyCereal.AddCereal(newCer); break; case '2': newCer = new Cereal(GetNewCereal()); MyCereal.AppendCereal(newCer); break; case '3': newCer = new Cereal(GetNewCereal()); Console.WriteLine("Which cereal should come after this new one?"); oldCer = Console.ReadLine(); MyCereal.AddBefore(newCer, oldCer); break; case '4': newCer = new Cereal(GetNewCereal()); Console.WriteLine("Which cereal should come before this new one?"); oldCer = Console.ReadLine(); MyCereal.AddAfter(newCer, oldCer); break; case '5': MyCereal.PrintList(); break; default: Console.WriteLine("Sorry, that wan't an option."); break; } UserLoop(MyCereal); }
/// <summary> /// Merges two Linked Lists by zippering the second cereal list into the first /// </summary> /// <param name="listA">A list of Cereals</param> /// <param name="listB">A second list of Cereals</param> /// <returns>The first list which is now combined with the second</returns> public static CerealList Merge(CerealList listA, CerealList listB) { listA.Current = listA.Head; listB.Current = listB.Head; while (listA.Current.Next != null && listB.Current.Next != null) { Cereal tempA = listA.Current.Next; Cereal tempB = listB.Current.Next; listA.Current.Next = listB.Current; listB.Current.Next = tempA; listA.Current = tempA; listB.Current = tempB; } if (listA.Current.Next == null) { listA.Current.Next = listB.Current; } else { listB.Current.Next = listA.Current.Next; listA.Current.Next = listB.Current; } return(listA); }
public void ShouldReturnValueAtProperIndex(int input, string expectedOutput) { CerealList testList = Program.CreateInitialList(); Assert.Equal(expectedOutput, Program.CerealKthFromEnd(testList, input)); }