ftp.nice.ch/pub/next/developer/resources/libraries/libcoll.930521.s.tar.gz#/libcoll-930521/tests/test1.m

This is test1.m in view mode; [Download] [Up]

#include <objc/Object.h>
#include <coll/coll.h>

int compareInts(elt e1, elt e2)
{
  return (e1.int_t - e2.int_t);
}

@interface Collection (TestingExtras)
- printCount;
@end
@implementation Collection (TestingExtras)
- printCount
{
  printf("%s: count=%d\n", [self name], [self count]);
  return self;
}
@end

void checkSameContents(id colllist)
{
  unsigned i, c = [colllist count];
  
  for (i = 1; i < c; i++)
    if (![[colllist objectAtIndex:0] 
	  includesSameContents:[colllist objectAtIndex:i]])
      printf("collection 0 does not have same contents as collection %d\n", i);
}


BOOL nonNullTest(elt e)
{
  if (e.void_ptr_t == 0) return NO;
  else return YES;
}


main()
{
  int i, j, e;
  char *s;

  id array = [[Array alloc] initDescription:"i"];
  id sarray = [[SortedArray alloc] initDescription:"i" 
	       comparisonFunc:compareInts];
  id llist = [[LinkedList alloc] initDescription:"i"];
  id bag = [[Bag alloc] initDescription:"i"];
  id stack = [[Stack alloc] initDescription:"i"];
  id queue = [[Queue alloc] initDescription:"i"];
  id gaparray = [[GapArray alloc] initDescription:"i"];

  id collections = [DelegateList new];

  [collections delegateListAddObject:array];
  [collections delegateListAddObject:sarray];
  [collections delegateListAddObject:llist];
  [collections delegateListAddObject:bag];
  [collections delegateListAddObject:stack];
  [collections delegateListAddObject:queue];
  [collections delegateListAddObject:gaparray];
  printf("delegateList filled, count=%d\n",
	 [[collections delegateListList] count]);

  [collections addElement:99];
  [collections printCount];

  printf("Adding numbers...\n");
  for (i = 0; i < 17; i++)
    {
      e = random() % 99;
      printf("%2d ", e);
      [collections addElement:e];
    }
  printf("\ncollections filled\n\n");
  [collections printForDebugger];

  if ([array trueForAllByCalling:nonNullTest])
    printf("Array contains no zero's\n");

  checkSameContents([collections delegateListList]);

  printf("\nremoving 99\n\n");
  [collections removeElement:99];
  [collections printForDebugger];
  checkSameContents([collections delegateListList]);

  exit(0);

/*
  if (![collections trueForAllByPerforming:@selector(includesSameContents:)
	      with:array])
    printf("error: collections not all the same\n");
*/
}


These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.