(root)/
libredwg-0.13/
test/
unit-testing/
hash_test.c
       1  #define HASH_TEST_C
       2  #include "hash.h"
       3  #include "common.h"
       4  #include <string.h>
       5  #include <stdlib.h>
       6  #include "tests_common.h"
       7  
       8  #define MAX_SIZE 2453916
       9  // 1 for full pressure, 5 for light pressure
      10  #define PRESSURE_FACTOR 1
      11  
      12  static inline uint32_t
      13  maxrand (int max)
      14  {
      15    uint32_t rnd = (uint32_t)rand ();
      16    return rnd % (uint32_t)max;
      17  }
      18  
      19  int
      20  main (int argc, char const *argv[])
      21  {
      22    const int max = MAX_SIZE;
      23    int i;
      24    dwg_inthash *hash;
      25  
      26    hash = hash_new (max);
      27    for (i = 1; i < max / PRESSURE_FACTOR; i++)
      28      {
      29        int32_t rnd = i; // we need to ensure full coverage.
      30        // i = maxrand(i)+1; for a more realistic workload
      31        hash_set (hash, rnd, rnd + 1);
      32      }
      33    ok ("hash size(%d) => %" PRIu64, max, hash->size);
      34  
      35    for (i = 1; i < max / PRESSURE_FACTOR; i++)
      36      {
      37        uint64_t v;
      38        uint32_t rnd = maxrand (i) + 1;
      39        if ((v = hash_get (hash, rnd)) != rnd + 1)
      40          fail ("hash_get(%d) => %" PRIu64, rnd, v);
      41      }
      42  
      43    hash_free (hash);
      44    return 0;
      45  }