1

I'm just wondering the best way to test out sort and search in helpers.c. Since the file won't compile/run on its own, how can I test the code that I'm writing?

1 Answer 1

2

Well, helper.c is part of the program named find, you may run

make find

which, per the Makefile, will compile both, find.c and helpers.c. You may then run

./find <some value>

and provide it with your values to test the searching/sorting functionality.

7
  • Kareen, how would you test sort in this way? Nothing prints out except that you found the needle or not.
    – Azurespot
    Commented Aug 22, 2014 at 8:56
  • @NoniA. you could write some code for printing the sorted array in helpers.c!
    – kzidane
    Commented Aug 22, 2014 at 9:09
  • That's what I don't know how to do though :( I tried to print my minimum variable at the end of my inner loop, each time it loops, but it gives values that don't make sense.
    – Azurespot
    Commented Aug 23, 2014 at 23:27
  • 1
    @NoniA.well, the writer of this program assumed that the user can input a maximum of MAX integers (i.e., 65536) and this definitely has some reasons one of which is that we can't let the user input an infinite number of integers since we have a finite memory. If the user inputs, say 10 integers, definitely we don't want to care about the latter 65526 elements in haystack. Here comes the role of n which is the number of integers that were inputted by the user or, in other words, the number of integers we care about.
    – kzidane
    Commented Aug 24, 2014 at 22:20
  • 1
    @NoniA. when size is passed in to search(), it matches the place of n (i.e., the parameter of search()), a copy of the value that's stored in size is stored in n. Recall that size represents the number of integers that were inputted by the user (and so does n). Given these information, we can print the first n elements of values[] using a simple for loop.
    – kzidane
    Commented Aug 24, 2014 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .