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