mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Completely overhaul how we do sorting in -base. GSSorting.h now defines an
interface that can be used for all sorting tasks in the library. The actual sort algorithms to use are now plugable. Timsort is the new default sorting algorithm, the existing algorithms, shellsort and quicksort, can still be selected using a configure switch. Also implement the new NSComparator (blocks) based sorting and insertion index searching methods for NSMutableArray and NSArray. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35573 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9407f87dea
commit
b9b63476ef
18 changed files with 2024 additions and 188 deletions
|
@ -13,7 +13,7 @@ int main()
|
|||
vals1 = [[[NSArray arrayWithObject:val1] arrayByAddingObject:val2] retain];
|
||||
vals2 = [[vals1 arrayByAddingObject:val2] retain];
|
||||
vals3 = [[vals1 arrayByAddingObject:val3] retain];
|
||||
|
||||
|
||||
obj = [NSArray new];
|
||||
arr = obj;
|
||||
PASS(obj != nil && [obj isKindOfClass:[NSArray class]] && [obj count] == 0,
|
||||
|
@ -30,16 +30,16 @@ int main()
|
|||
e = [arr objectEnumerator];
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
PASS(e != nil && v1 == nil && v2 == nil,
|
||||
PASS(e != nil && v1 == nil && v2 == nil,
|
||||
"-objectEnumerator: is ok for empty array");
|
||||
e = [vals1 objectEnumerator];
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
v3 = [e nextObject];
|
||||
PASS(v1 != nil && v2 != nil && v3 == nil && [vals1 containsObject:v1] &&
|
||||
PASS(v1 != nil && v2 != nil && v3 == nil && [vals1 containsObject:v1] &&
|
||||
[vals1 containsObject:v2] && [v1 isEqual:val1] && [v2 isEqual: val2],
|
||||
"-objectEnumerator: enumerates the array");
|
||||
}
|
||||
}
|
||||
{
|
||||
obj = [arr description];
|
||||
obj = [obj propertyList];
|
||||
|
@ -53,14 +53,14 @@ int main()
|
|||
PASS(vals1 != nil && [vals1 isKindOfClass: [NSArray class]] &&
|
||||
[vals1 count] == 2, "-count returns two for an array with two objects");
|
||||
PASS([vals1 hash] == 2, "-hash returns two for an array with two objects");
|
||||
PASS([vals1 indexOfObject:nil] == NSNotFound,
|
||||
PASS([vals1 indexOfObject:nil] == NSNotFound,
|
||||
"-indexOfObject: gives NSNotFound for a nil object");
|
||||
PASS([vals1 indexOfObject:val3] == NSNotFound,
|
||||
"-indexOfObject: gives NSNotFound for a object not in the array");
|
||||
PASS([vals1 isEqualToArray:vals1],
|
||||
"Array is equal to itself using -isEqualToArray:");
|
||||
PASS(![vals1 isEqualToArray:vals2],"Similar arrays are not equal using -isEqualToArray:");
|
||||
|
||||
|
||||
{
|
||||
NSArray *a;
|
||||
NSRange r = NSMakeRange(0,2);
|
||||
|
@ -71,7 +71,7 @@ int main()
|
|||
r = NSMakeRange(1,2);
|
||||
PASS_EXCEPTION([arr subarrayWithRange:r];,@"NSRangeException","-subarrayWithRange with invalid range");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSString *c = @"/";
|
||||
NSString *s = @"Hello/A Goodbye";
|
||||
|
@ -86,6 +86,15 @@ int main()
|
|||
"-sortedArrayUsingSelector: seems ok");
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
NSMutableArray *unsorted = [NSMutableArray arrayWithContentsOfFile: @"random.plist"];
|
||||
NSArray *expected = [NSArray arrayWithContentsOfFile: @"sorted.plist"];
|
||||
[unsorted sortUsingSelector: @selector(compare:)];
|
||||
PASS_EQUAL(unsorted, expected, "Sorting larger arrays works.");
|
||||
|
||||
}
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue