Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tests cases for merge in merge sort

Are there any edge cases or just cases in general that I need to test for this function. The only thing I can think of is if one of the arrays being merged is empty. Are there other test cases I need to consider?

like image 861
user1136342 Avatar asked Dec 15 '22 13:12

user1136342


2 Answers

For any sort, I consider these cases:

  • The empty list
  • An already sorted list
  • A reverse sorted list
  • A list consisting of the same element throughout
  • A list containing dupes

This is not just to prove the algorithm but also for performance.

like image 137
Robbie Dee Avatar answered Jan 02 '23 16:01

Robbie Dee


Some more:

  • Think about the number of elements in each array: Both array have even number of elements One array has even while the other has odd number of elements Number of elements in one array is more than the number of elements in another

  • Also consider the range of elements in the array The largest element in one array is smaller than the smallest element in the second array One array has duplicates Both the arrays have the same set of elements e.g.(A1: 2,4,6,8 and A2: 2,4,6,8)

Basically these ones are good at catching one off errors in the for loop while merging

like image 37
jsshah Avatar answered Jan 02 '23 16:01

jsshah