objective c - NSDecimalNumber unit test struggle -


this question has answer here:

i trying write unit test method doing operations on nsdecimalnumber. simplicity prepared simple unit test snippet:

- (void) testtmp {     nsdecimalnumber* val = [nsdecimalnumber decimalnumberwithstring:@"0"];     xctassertequal([val stringvalue], @"0"); } 

unfortunately fails , can't work. doing wrong? how test if nsdecimalnumber's value equals other value?

xctassertequal() compares object references. should use xctassertequalobjects().

- (void) testtmp {   nsdecimalnumber* val = [nsdecimalnumber decimalnumberwithstring:@"0"];   xctassertequalobjects([val stringvalue], @"0"); } 

btw: should not compare string representation of number, number …:

- (void) testtmp {   nsdecimalnumber* val = [nsdecimalnumber decimalnumberwithstring:@"0"];   xctassertequalobjects(val, [nsdecimalnumber decimalnumberwithstring:@"0"]); } 

… or (did not check it, whether nsnumber , nsdecimalnumber can equal, should way) …

- (void) testtmp {   nsdecimalnumber* val = [nsdecimalnumber decimalnumberwithstring:@"0"];   xctassertequalobjects(val, @0); } 

however, instances of nsdecimalnumber floating point values. comparing them equity voodoo.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -