File: selftest.c

package info (click to toggle)
libwn6 6.0-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,996 kB
  • ctags: 3,938
  • sloc: ansic: 45,083; makefile: 926; csh: 274; sh: 12
file content (142 lines) | stat: -rw-r--r-- 2,222 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/****************************************************************************

COPYRIGHT NOTICE:

  The source code in this file is provided free of charge
  to the author's consulting clients.  It is in the
  public domain and therefore may be used by anybody for
  any purpose.

AUTHOR:

  Will Naylor

****************************************************************************/
#include <stdio.h>

#include "wnlib.h"
#include "wnasrt.h"

#include "wnhtbl.h"



#if 1
main()
{
  wn_htab table;
  int i,j,num;
  bool success;

  printf("testing hash...\n");

  /*
  for(i=0;i<2000000;++i)
  {
    num = wn_inthash(i);
  }

  return;
  */

  wn_gpmake("no_free");

  wn_mkinthtab(&table);

  for(i=0;i<10000;++i)
  {
    success = wn_hins((ptr)(i+1),table,(ptr)i);
    wn_assert(success);
  }

  wn_hverify(table);

  /*
  for(j=0;j<50;++j)
  */
  for(i=0;i<10000;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(success);
  }

  wn_hverify(table);

  for(i=0;i<5000;++i)
  {
    success = wn_hdel(table,(ptr)i);
    wn_assert(success);
  }

  wn_hverify(table);

  for(i=0;i<5000;++i)
  {
    success = wn_hdel(table,(ptr)i);
    wn_assert(!(success));
  }

  wn_hverify(table);

  for(i=0;i<5000;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(!(success));
  }

  for(i=5000;i<10000;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(success);
    wn_assert(num == i+1);
  }

  for(i=2500;i<7500;++i)
  {
    success = wn_hfins((ptr)i,table,(ptr)i);
    wn_assert(success);
  }

  for(i=2500;i<7500;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(success);
    wn_assert(num == i);
  }

  for(i=0;i<2500;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(!(success));
  }

  for(i=7500;i<10000;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(success);
    wn_assert(num == i+1);
  }

  wn_hverify(table);

  for(i=2500;i<10000;++i)
  {
    success = wn_hdel(table,(ptr)i);
    wn_assert(success);
  }

  wn_hverify(table);

  for(i=0;i<10000;++i)
  {
    success = wn_hget((ptr *)&num,table,(ptr)i);
    wn_assert(!(success));
  }

  printf("  ok!!!!!!\n");

  exit(0);
}
#endif