public void Print_All_Elts_Empty() { Console.WriteLine("CHECK THIS: SmartArray starts with all zeros"); TestHelpers th = new TestHelpers(); th.StartOutputCapturing(); sa.PrintAllElements(); String sResult = th.StopOutputCapturing(); StringWriter sw = new StringWriter(); for (int i = 0; i < SMART_ARRAY_SIZE; i++) sw.WriteLine(0); string sCorrect = sw.ToString(); Console.WriteLine("Expected the output\n" + sCorrect + "\nActually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); bool theSame = TestHelpers.EqualsFuzzyString(sCorrect, sResult); Assert.That(theSame == true, "Expected the output\n" + sCorrect + "\nBut actually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); }
public void Print_All_Elts_Set() { int[] nums = new int[] { 10, 20, 30, 40, 50 }; for (int i = 0; i < nums.Length; i++) { sa.SetAtIndex(i, nums[i]); } TestHelpers th = new TestHelpers(); th.StartOutputCapturing(); sa.PrintAllElements(); String sResult = th.StopOutputCapturing(); StringWriter sw = new StringWriter(); for (int i = 0; i < nums.Length; i++) sw.WriteLine(nums[i]); string sCorrect = sw.ToString(); Console.WriteLine("Expected the output\n" + sCorrect + "\nActually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); bool theSame = TestHelpers.EqualsFuzzyString(sCorrect, sResult); Assert.That(theSame == true, "Expected the output\n" + sCorrect + "\nBut actually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); }
public void Print_All_Elts_Resized_Then_Set() { int[] nums = new int[] { 10, 20, 30, 40, 50 }; int[] extra = new int[] { 100, 90, 80, 70, 60 }; // first, fill up the starting array for (int i = 0; i < nums.Length; i++) { sar.SetAtIndex(i, nums[i]); } Console.WriteLine("Finished initial fill!"); // second, resize the array. This should preserve the values we put into it, above sar.Resize(sar.getSize() + extra.Length); Console.WriteLine("Resized the array"); // third, add some more values to the new space in the array for ( int i = sar.getSize() - extra.Length, j = 0; i < sar.getSize(); i++, j++) { Console.WriteLine("rgNums[" + i + "] = "+extra[j] +" ( which is extra[" + j + "] )"); sar.SetAtIndex(i, extra[j]); } TestHelpers th = new TestHelpers(); th.StartOutputCapturing(); sar.PrintAllElements(); String sResult = th.StopOutputCapturing(); StringWriter sw = new StringWriter(); for (int i = 0; i < nums.Length; i++) sw.WriteLine(nums[i]); for (int i = 0; i < extra.Length; i++) sw.WriteLine(extra[i]); string sCorrect = sw.ToString(); Console.WriteLine("Expected the output\n" + sCorrect + "\nActually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); bool theSame = TestHelpers.EqualsFuzzyString(sCorrect, sResult); Assert.That(theSame == true, "Expected the output\n" + sCorrect + "\nBut actually got:\n" + sResult + "END OF YOUR OUTPUT\n(END OF YOUR OUTPUT was added so it's clear what your output ends"); }