mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Add (failing) test for keysSortedByValueUsingComparator:
This commit is contained in:
parent
8f0087b73d
commit
155bec0aca
1 changed files with 41 additions and 0 deletions
41
Tests/base/NSDictionary/sort.m
Normal file
41
Tests/base/NSDictionary/sort.m
Normal file
|
@ -0,0 +1,41 @@
|
|||
#import "Testing.h"
|
||||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
NSArray* values = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithFloat:2.0],
|
||||
[NSNumber numberWithFloat:1.0],
|
||||
[NSNumber numberWithFloat:3.0],
|
||||
[NSNumber numberWithFloat:4.0],
|
||||
nil];
|
||||
|
||||
NSArray* keys = [NSArray arrayWithObjects:
|
||||
@"shouldSortToSecond",
|
||||
@"shouldSortToFirst",
|
||||
@"shouldSortToThird",
|
||||
@"shouldSortToFourth",
|
||||
nil];
|
||||
|
||||
NSDictionary *d = [NSDictionary dictionaryWithObjects:values forKeys:keys];
|
||||
NSArray* keysOrderedByKeyedValue = [d keysSortedByValueUsingComparator:
|
||||
^NSComparisonResult(id obj1, id obj2) {
|
||||
return [(NSNumber*)obj1 compare:(NSNumber*)obj2];
|
||||
}];
|
||||
|
||||
NSArray* expected = [NSArray arrayWithObjects:
|
||||
@"shouldSortToFirst",
|
||||
@"shouldSortToSecond",
|
||||
@"shouldSortToThird",
|
||||
@"shouldSortToFourth",
|
||||
nil];
|
||||
|
||||
PASS([keysOrderedByKeyedValue isEqual:expected], "Can sort a dictionary's keys by its values");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue