2011-02-16 08:21:17 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2011-10-12 14:28:44 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
unichar u = 0x00a3; // Pound sign
|
|
|
|
NSString *s;
|
|
|
|
double d;
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
|
|
PASS([@"12" intValue] == 12, "simple intValue works");
|
|
|
|
PASS([@"-12" intValue] == -12, "negative intValue works");
|
|
|
|
PASS([@"+12" intValue] == 12, "positive intValue works");
|
|
|
|
PASS([@"1.6" intValue] == 1, "intValue ignores trailing data");
|
|
|
|
PASS([@" 12" intValue] == 12,
|
|
|
|
"intValue with leading space works");
|
|
|
|
|
|
|
|
d = [@"1.2" doubleValue];
|
2011-03-16 15:12:49 +00:00
|
|
|
PASS(d > 1.199999 && d < 1.200001, "simple doubleValue works");
|
2013-04-10 22:03:52 +00:00
|
|
|
PASS([@"1.9" doubleValue] == 90 / 100.0 + 1.0, "precise doubleValue works");
|
2011-02-16 08:21:17 +00:00
|
|
|
d = [@"-1.2" doubleValue];
|
2011-03-16 15:12:49 +00:00
|
|
|
PASS(d < -1.199999 && d > -1.200001, "negative doubleValue works");
|
2011-02-16 08:21:17 +00:00
|
|
|
d = [@"+1.2" doubleValue];
|
2011-03-16 15:12:49 +00:00
|
|
|
PASS(d > 1.199999 && d < 1.200001, "positive doubleValue works");
|
2011-02-16 08:21:17 +00:00
|
|
|
d = [@"+1.2 x" doubleValue];
|
2011-03-16 15:12:49 +00:00
|
|
|
PASS(d > 1.199999 && d < 1.200001, "doubleValue ignores trailing data");
|
2011-02-16 08:21:17 +00:00
|
|
|
d = [@" 1.2" doubleValue];
|
2011-03-16 15:12:49 +00:00
|
|
|
PASS(d > 1.199999 && d < 1.200001, "doubleValue with leading space works");
|
2011-02-16 08:21:17 +00:00
|
|
|
|
2014-11-29 11:02:23 +00:00
|
|
|
s = @"50.6468746467461646";
|
|
|
|
sscanf([s UTF8String], "%lg", &d);
|
|
|
|
PASS(EQ([s doubleValue], d), "50.6468746467461646 -doubleValue OK");
|
|
|
|
|
|
|
|
s = @"50.64687464674616461";
|
|
|
|
sscanf([s UTF8String], "%lg", &d);
|
|
|
|
PASS(EQ([s doubleValue], d), "50.64687464674616461 -doubleValue OK");
|
|
|
|
|
|
|
|
s = @"0.646874646746164616898211";
|
|
|
|
sscanf([s UTF8String], "%lg", &d);
|
|
|
|
PASS(EQ([s doubleValue], d), "0.646874646746164616898211 -doubleValue OK");
|
|
|
|
|
|
|
|
s = @"502.646874646746164";
|
|
|
|
sscanf([s UTF8String], "%lg", &d);
|
|
|
|
PASS(EQ([s doubleValue], d), "502.646874646746164 -doubleValue OK");
|
|
|
|
|
|
|
|
s = @"502.6468746467461646";
|
|
|
|
sscanf([s UTF8String], "%lg", &d);
|
|
|
|
PASS(EQ([s doubleValue], d), "502.6468746467461646 -doubleValue OK");
|
|
|
|
|
2011-10-12 14:28:44 +00:00
|
|
|
s = [NSString stringWithCharacters: &u length: 1];
|
|
|
|
PASS_EQUAL(s, @"£", "UTF-8 string literal matches 16bit unicode string");
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|