unittest: compare properly decimal numbers
This commit is contained in:
parent
2e1ed274c8
commit
1529e7ec4e
|
@ -21,6 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Foundation/NSException.h>
|
#import <Foundation/NSException.h>
|
||||||
|
#import <Foundation/NSLocale.h>
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
#import <Foundation/NSValue.h>
|
#import <Foundation/NSValue.h>
|
||||||
|
|
||||||
|
@ -71,6 +72,8 @@
|
||||||
{
|
{
|
||||||
SBJsonParser *parser;
|
SBJsonParser *parser;
|
||||||
id result;
|
id result;
|
||||||
|
NSDecimalNumber *obtained, *expected;
|
||||||
|
NSDictionary *locale;
|
||||||
|
|
||||||
parser = [SBJsonParser new];
|
parser = [SBJsonParser new];
|
||||||
[parser autorelease];
|
[parser autorelease];
|
||||||
|
@ -80,17 +83,20 @@
|
||||||
|
|
||||||
result = [parser objectWithString: @"[ 0 ]"];
|
result = [parser objectWithString: @"[ 0 ]"];
|
||||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: 0]]);
|
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: 0]]);
|
||||||
|
|
||||||
result = [parser objectWithString: @"[ -1 ]"];
|
result = [parser objectWithString: @"[ -1 ]"];
|
||||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: -1]]);
|
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: -1]]);
|
||||||
|
|
||||||
|
locale = [NSDictionary dictionaryWithObject: @"." forKey: NSLocaleDecimalSeparator];
|
||||||
result = [parser objectWithString: @"[ 12.3456 ]"];
|
result = [parser objectWithString: @"[ 12.3456 ]"];
|
||||||
testEquals ([result objectAtIndex: 0],
|
obtained = [result objectAtIndex: 0];
|
||||||
[NSDecimalNumber decimalNumberWithString: @"12.3456"]);
|
expected = [NSDecimalNumber decimalNumberWithString: @"12.3456" locale: locale];
|
||||||
|
test ([obtained compare: expected] == NSOrderedSame);
|
||||||
|
|
||||||
result = [parser objectWithString: @"[ -312.3456 ]"];
|
result = [parser objectWithString: @"[ -312.3456 ]"];
|
||||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithDouble: -312.3456]]);
|
obtained = [result objectAtIndex: 0];
|
||||||
|
expected = [NSDecimalNumber decimalNumberWithString: @"-312.3456" locale: locale];
|
||||||
|
test ([obtained compare: expected] == NSOrderedSame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue