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
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.
-
Kareen, how would you test sort in this way? Nothing prints out except that you found the needle or not. Commented Aug 22, 2014 at 8:56
-
@NoniA. you could write some code for printing the sorted array in helpers.c!– kzidaneCommented 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. 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 inhaystack
. Here comes the role ofn
which is the number of integers that were inputted by the user or, in other words, the number of integers we care about.– kzidaneCommented Aug 24, 2014 at 22:20 -
1@NoniA. when
size
is passed in tosearch()
, it matches the place ofn
(i.e., the parameter ofsearch()
), a copy of the value that's stored insize
is stored inn
. Recall thatsize
represents the number of integers that were inputted by the user (and so doesn
). Given these information, we can print the firstn
elements ofvalues[]
using a simple for loop.– kzidaneCommented Aug 24, 2014 at 22:21