Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public static void RunFunctionalityTest(int[] array, int expected)
  2. {
  3. int median = BruteForceMedian(array);
  4.  
  5. Console.Write("Array: ");
  6. PrintArray(array);
  7.  
  8. Console.WriteLine("{0} == {1}? {2}", expected, median, median == expected);
  9. Console.WriteLine("Operations: {0}", operations);
  10. Console.WriteLine("----------");
  11. }
  12.  
  13. public static void VerifyFunctionality()
  14. {
  15. int[] test1 = new int[] { 1 }; // n = 1 test
  16. int[] test2 = new int[] { 1, 2, 3 }; // Pre-sorted, short, simple
  17. int[] test3 = new int[] { 3, 1, 2 }; // Unsorted, short, simple
  18. int[] test4 = new int[] { 1, 1, 2, 2, 3, 3 }; // Sorted, with duplicates
  19. int[] test5 = new int[] { 9, 8, 7, 6, 5, 6, 7, 5, 9, 8 }; // Unsorted, with duplicates
  20. int[] test6 = new int[] { 5, 4, 1, 5, 2, 6, 8, 1, 5, 9 }; // Unsorted, with duplicates (but not all) 5 is median
  21. int[] test7 = GenerateArray(10, 15, true); // As before, but randomly generated (median is unpredictable here)
  22.  
  23. RunFunctionalityTest(test1, 1);
  24. RunFunctionalityTest(test2, 2);
  25. RunFunctionalityTest(test3, 2);
  26. RunFunctionalityTest(test4, 2);
  27. RunFunctionalityTest(test5, 7);
  28. RunFunctionalityTest(test6, 5);
  29. RunFunctionalityTest(test7, 0);
  30.  
  31. Array.Sort(test7); // To manually verify
  32. PrintArray(test7);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement