mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
numeric sort test
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39667 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0ce5d9d2db
commit
c727a19c46
1 changed files with 65 additions and 0 deletions
65
Tests/base/NSString/test08.m
Normal file
65
Tests/base/NSString/test08.m
Normal file
|
@ -0,0 +1,65 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
|
||||
@interface NSString (NumericSort)
|
||||
- (NSComparisonResult)numericCompare: (NSString *)s;
|
||||
@end
|
||||
|
||||
@implementation NSString (NumericSort)
|
||||
- (NSComparisonResult)numericCompare: (NSString *)s
|
||||
{
|
||||
return [self compare: s options: NSNumericSearch];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *a1, *a2;
|
||||
NSArray *a;
|
||||
NSString *s1, *s2;
|
||||
|
||||
s1 = @"1";
|
||||
s2 = @"2";
|
||||
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedAscending,
|
||||
"1 is less than 2");
|
||||
|
||||
s1 = @"1";
|
||||
s2 = @"10";
|
||||
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedAscending,
|
||||
"1 is less than 10");
|
||||
|
||||
s1 = @"1";
|
||||
s2 = @"11";
|
||||
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedAscending,
|
||||
"1 is less than 11");
|
||||
|
||||
s1 = @"11";
|
||||
s2 = @"1";
|
||||
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedDescending,
|
||||
"11 is greater than 1");
|
||||
|
||||
s1 = @"11";
|
||||
s2 = @"2";
|
||||
PASS([s1 compare: s2 options: NSNumericSearch] == NSOrderedDescending,
|
||||
"11 is greater than 2");
|
||||
|
||||
a1 = [[NSArray alloc] initWithObjects:
|
||||
@"2", @"1", @"10", @"11", @"20", @"3", nil];
|
||||
|
||||
a = [[NSArray alloc] initWithObjects:
|
||||
@"1", @"10", @"11", @"2", @"20", @"3", nil];
|
||||
a2 = [a1 sortedArrayUsingSelector: @selector(compare:)];
|
||||
PASS_EQUAL(a2, a, "text sort");
|
||||
|
||||
a = [[NSArray alloc] initWithObjects:
|
||||
@"1", @"2", @"3", @"10", @"11", @"20", nil];
|
||||
a2 = [a1 sortedArrayUsingSelector: @selector(numericCompare:)];
|
||||
PASS_EQUAL(a2, a, "numeric sort");
|
||||
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue