| #include <stdlib.h> // size_t |
| #include <assert.h> // assert |
| #include "median.h" |
| #include "hex.h" |
| |
| // A sinple main routine meant as an example, |
| // and also to unit test most of the intersting |
| // functions of the median module. |
| int main(int argc, char * argv[]) { |
| // Call suggest buffer size to determine the size of the buffer |
| // we need to build the data structure. |
| size_t n = 0; |
| assert(median_suggest_buffer_size(.001, 1000, &n) == MEDIAN_OK); |
| |
| // Allocate the buffer of the required size. And then |
| // initialize it (median_init_buffer). |
| void * b = malloc(n); |
| median_buffer_t buf; |
| assert(median_init_buffer(b, n, .001, 1000, &buf) == MEDIAN_OK); |
| |
| // Insert some data. |
| for(median_data_t i = 1; i < 3010; i++) { |
| assert(median_insert_data(buf,i) == MEDIAN_OK); |
| } |
| |
| // Dump it. |
| assert(median_dump_stderr(buf) == MEDIAN_OK); |
| |
| // All done, return 0 |
| return 0; |
| } |