Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void RunFunctionalityTest(int[] array, int expected)
- {
- int median = BruteForceMedian(array);
- Console.Write("Array: ");
- PrintArray(array);
- Console.WriteLine("{0} == {1}? {2}", expected, median, median == expected);
- Console.WriteLine("Operations: {0}", operations);
- Console.WriteLine("----------");
- }
- public static void VerifyFunctionality()
- {
- int[] test1 = new int[] { 1 }; // n = 1 test
- int[] test2 = new int[] { 1, 2, 3 }; // Pre-sorted, short, simple
- int[] test3 = new int[] { 3, 1, 2 }; // Unsorted, short, simple
- int[] test4 = new int[] { 1, 1, 2, 2, 3, 3 }; // Sorted, with duplicates
- int[] test5 = new int[] { 9, 8, 7, 6, 5, 6, 7, 5, 9, 8 }; // Unsorted, with duplicates
- int[] test6 = new int[] { 5, 4, 1, 5, 2, 6, 8, 1, 5, 9 }; // Unsorted, with duplicates (but not all) 5 is median
- int[] test7 = GenerateArray(10, 15, true); // As before, but randomly generated (median is unpredictable here)
- RunFunctionalityTest(test1, 1);
- RunFunctionalityTest(test2, 2);
- RunFunctionalityTest(test3, 2);
- RunFunctionalityTest(test4, 2);
- RunFunctionalityTest(test5, 7);
- RunFunctionalityTest(test6, 5);
- RunFunctionalityTest(test7, 0);
- Array.Sort(test7); // To manually verify
- PrintArray(test7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement