Author: rfm
Date: Thu Apr 14 16:59:29 2016
New Revision: 39667
URL: http://svn.gna.org/viewcvs/gnustep?rev=39667&view=rev
Log:
numeric sort test
Added:
libs/base/trunk/Tests/base/NSString/test08.m
Added: libs/base/trunk/Tests/base/NSString/test08.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/NSString/test08.m?rev=39667&view=auto
==============================================================================
--- libs/base/trunk/Tests/base/NSString/test08.m (added)
+++ libs/base/trunk/Tests/base/NSString/test08.m Thu Apr 14 16:59:29 2016
@@ -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;
+}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs