1996-04-16 21:29:40 +00:00
|
|
|
/* Test Heap class. */
|
|
|
|
|
2003-07-31 23:49:32 +00:00
|
|
|
#include <GNUstepBase/all.h>
|
1996-04-16 21:29:40 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
|
|
|
|
#define N 20
|
|
|
|
|
1998-05-29 15:25:41 +00:00
|
|
|
#if defined(__svr4__) || defined(__hpux) || defined(_SEQUENT_)
|
1996-04-16 21:29:40 +00:00
|
|
|
long lrand48();
|
|
|
|
#define random lrand48
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
id s1, s2;
|
|
|
|
id arp;
|
|
|
|
|
|
|
|
Heap* heap = [Heap new];
|
|
|
|
Array* array = [Array new];
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
for (i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
s = random () % 100;
|
|
|
|
[heap addObject: [NSNumber numberWithInt: s]];
|
|
|
|
[array addObject: [NSNumber numberWithInt: s]];
|
|
|
|
}
|
|
|
|
[array sortContents];
|
|
|
|
|
|
|
|
[heap printForDebugger];
|
|
|
|
[array printForDebugger];
|
|
|
|
|
|
|
|
for (i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
s1 = [heap firstObject];
|
|
|
|
s2 = [array firstObject];
|
|
|
|
[heap removeFirstObject];
|
|
|
|
[array removeFirstObject];
|
|
|
|
printf("(%d,%d) ", [s1 intValue], [s2 intValue]);
|
|
|
|
assert ([s1 intValue] == [s2 intValue]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1996-04-16 21:29:40 +00:00
|
|
|
[heap release];
|
|
|
|
[array release];
|
|
|
|
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|