in reply to Re: 0==undef, that's annoying. Is it?
in thread 0==undef, that's annoying. Is it?

These work, but I don't like either of them (i'm being a bit too perfectionist there).

The first one is not clear, it's a lot too complex to read, for such a simple assertion. The second one is exactly equivalent to my

is($score, 0)
assertion, but just harder to read.
And i still prefer using cmp_ok() for numbers, as '==' indicates clearly that it's numbers. And
is('1','1.0')
returns 0, while
cmp(1, '==', 1.0)
is true.
So... I'd like to use cmp_ok() for numbers, but i'll have to be careful to not compare zeros in there.

Replies are listed 'Best First'.
Re^3: 0==undef, that's annoying. Is it?
by AnomalousMonk (Archbishop) on Jul 15, 2012 at 23:11 UTC

    Perhaps another alternative to consider is Test::NoWarnings.

    >perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; cmp_ok(0, '==', undef, 'is 0 really undefined?'); " ok 1 - is 0 really undefined? not ok 2 - no warnings # Failed test 'no warnings' # at C:/strawberry/5.14/perl/vendor/lib/Test/NoWarnings.pm line 38. # There were 1 warning(s) # (lots and lots of discussion about the warning elided) # 1..2 # Looks like you failed 1 test of 2.
Re^3: 0==undef, that's annoying. Is it?
by Anonymous Monk on Jul 15, 2012 at 23:33 UTC

    These work, but I don't like either of them (i'm being a bit too perfectionist there).

    :) No, not perfectionist, merely neurotic (overanxious) :) See, the language is what it is, learn its ways and go with the flow :) don't get annoyed at things outside of your control, control yourself :) serenity now