mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
New file.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1372 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
313ef47ba4
commit
9e2c0d5bd4
1 changed files with 59 additions and 0 deletions
59
Testing/heap.m
Normal file
59
Testing/heap.m
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* Test Heap class. */
|
||||
|
||||
#include <objects/objects.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
#define N 20
|
||||
|
||||
#if (sun && __svr4__) || defined(__hpux) || defined(_SEQUENT_)
|
||||
long lrand48();
|
||||
#define random lrand48
|
||||
#else
|
||||
#if WIN32
|
||||
#define random rand
|
||||
#else
|
||||
long random();
|
||||
#endif
|
||||
#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");
|
||||
|
||||
[heap release];
|
||||
[array release];
|
||||
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in a new issue