Home | History | Annotate | Download | only in test
      1 
      2 #include "cs_config.h"
      3 #include <unistd.h>
      4 #include <string.h>
      5 #include "util/neo_misc.h"
      6 #include "util/neo_hdf.h"
      7 #include "util/neo_rand.h"
      8 
      9 int TestCompare(const void* pa, const void* pb)
     10 {
     11   HDF **a = (HDF **)pa;
     12   HDF **b = (HDF **)pb;
     13   float aVal,bVal;
     14 
     15   aVal = atof(hdf_get_value(*a,"val","0"));
     16   bVal = atof(hdf_get_value(*b,"val","0"));
     17 
     18   printf("TestCompare aVal=%f [%s]  bVal=%f [%s]\n",aVal,hdf_get_value(*a,"name","?"),bVal,hdf_get_value(*b,"name","?"));
     19 
     20   if (aVal<bVal) return -1;
     21   if (aVal==bVal) return 0;
     22   return 1;
     23 }
     24 
     25 void TestSort(HDF* hdf)
     26 {
     27   int i;
     28   float value;
     29 
     30   for (i=0;i<15;i++)
     31   {
     32     value = rand()/(RAND_MAX+1.0);
     33 
     34     hdf_set_valuef(hdf, "test.%d", "%d", i, i);
     35     hdf_set_valuef(hdf, "test.%d.name", "item #%d", i, i);
     36     hdf_set_valuef(hdf, "test.%d.val", "%f", i, value );
     37   }
     38 
     39   hdf_dump(hdf,NULL);
     40 
     41   hdf_sort_obj(hdf_get_obj(hdf, "test"), TestCompare);
     42 
     43   hdf_dump(hdf,NULL);
     44 
     45 }
     46 
     47 
     48 int main(int argc, char *argv[])
     49 {
     50   NEOERR *err;
     51   HDF *hdf;
     52   double tstart = 0;
     53 
     54   err = hdf_init(&hdf);
     55   if (err != STATUS_OK)
     56   {
     57     nerr_log_error(err);
     58     return -1;
     59   }
     60 
     61   tstart = ne_timef();
     62   TestSort(hdf);
     63   ne_warn("sort took %5.5fs", ne_timef() - tstart);
     64 
     65   hdf_dump(hdf, NULL);
     66 
     67   hdf_destroy(&hdf);
     68 
     69   return 0;
     70 }
     71