Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created August 18, 2014 13:50
Show Gist options
  • Save zwaldowski/1d2ce7e9f5c66a4a4e48 to your computer and use it in GitHub Desktop.
Save zwaldowski/1d2ce7e9f5c66a4a4e48 to your computer and use it in GitHub Desktop.
@import QuartzCore.CABase;
#import <Kiwi/Kiwi.h>
#ifndef CGFLOAT_EPSILON
#if CGFLOAT_IS_DOUBLE
#define CGFLOAT_EPSILON DBL_EPSILON
#else
#define CGFLOAT_EPSILON FLT_EPSILON
#endif
#endif
SPEC_BEGIN(FloatingPointInvolved)
describe(@"shows how gross C floats are", ^{
it(@"compares incorrectly", ^{
CGFloat fail = 13.37;
#if __LP64__
[[theValue(fail) should] equal:theValue(13.37)];
#else
[[theValue(fail) shouldNot] equal:theValue(13.37)];
#endif
double works = 13.37;
[[theValue(works) should] equal:theValue(13.37)];
});
it(@"compares correctly", ^{
CGFloat fail = 13.37;
[[theValue(fail) should] equal:13.37 withDelta:CGFLOAT_EPSILON];
double works = 13.37;
[[theValue(works) should] equal:13.37 withDelta:CGFLOAT_EPSILON];
});
it(@"compares incorrectly (objects)", ^{
CGFloat fail = 13.37;
[[@(fail) should] equal:@(13.37)];
});
});
SPEC_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment