// 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]); }
public void ShouldAddCerealToListHead() { CerealList testList = Program.CreateInitialList(); Cereal frostedFlakes = new Cereal("Frosted Flakes"); testList.AddCereal(frostedFlakes); string[] testArr = testList.ListToArr(1); Assert.Equal("Frosted Flakes", testArr[0]); }
/// <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); }
/// <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); }
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); }