Re: Getting a handle on inf
Re: Getting a handle on inf
- Subject: Re: Getting a handle on inf
- From: Ian Piper <email@hidden>
- Date: Mon, 26 Oct 2009 19:11:42 +0000
On 26 Oct 2009, at 18:45, Greg Parker wrote:
On Oct 26, 2009, at 11:26 AM, Ian Piper wrote:
So I am guessing that when I get a float displayed as "inf" this is
not the string it seems to be. Also, it looks like the string value
of whatever is coming back is not something that I can use. Can
anyone suggest how I might handle a test case like this?
As Kyle noted, -stringValue returns an NSString, not a char*. You'd
need to compare to @"inf" and print with %@.
Kyle, Greg,
Thanks for that. I tried it out:
- (void)testVeryLargeNumberShouldReturnInf {
testConverter = Converter.new;
[testConverter setValue:[NSNumber numberWithFloat:
1000000000000000000000000000000000000000.0] forKey:@"originalTemp"];
NSNumber *newTemperatureInF = [NSNumber numberWithFloat:(float)
[testConverter convertCToF]];
STAssertEquals(@"inf", [newTemperatureInF stringValue], @"Expecting
inf; we got %@", [newTemperatureInF stringValue]);
[testConverter release];
}
...and I still get a failed build with this message:
Expecting inf; we got inf
Which seems odd. When I look at the transcript for the test result it
looks like this:
TCTests.m:58: error: -[TCTests testVeryLargeNumberShouldReturnInf] :
'<28810c00 01000000>' should be equal to '<c08a1800 01000000>':
Expecting inf; we got inf
So I am still not comparing apples with apples...
A better way to check for floating-point +infinity and -infinity is
to use the isinf() macro.
if (isinf([number floatValue])) {
NSLog(@"number is +inf or -inf");
}
That macro isn't part of OCUnit is it? I don't see it in the
Documentation.
Ian.
--
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden