# How to test implementation details when there are multiple ways of implementing the algorithm, without reading the code?

I want to make sure that the code that the written code is precisely doing what it is expected to do.

For example, if I want to search in an array particularly using linear search, I don't want binary search to pass the test. Unit test to test the method "search" would pass irrespective of the implementation which is not what I want. (I understand that binary search won't work if the data is unsorted, but lets say the data is sorted and I still want to make sure that it is a linear search and not the binary. In this case, I know that for sufficiently large input, BS would be way quicker than LS, but I want a generic answer where there might not be considerable difference in performance.)

Is there a way to achieve this?

An idea comes to my mind - Divide the method in extremely small submethods and make sure that all the submethods are implemented correctly and are used in main method. However this is not desirable, this might not be feasible always.

• What do you want to do? Check if the code is well-written requires reading the code. I just don't see any way around it. – vonbrand Sep 13 '19 at 13:40

• Best you can do is to request some "efficiency" measure, i.e., the algorithm has to sort with $O(n \log n)$ assignments/comparisons, instrument the data sorted, and run it on some (selected) examples. But that won't let you distinguish e.g. mergesort and quicksort. And they could cheat by sorting off-line by bubblesort and permuting into the result. – vonbrand Sep 13 '19 at 13:39