Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Do you consider these different or the same?

by tmoertel (Chaplain)
on Jul 01, 2005 at 16:50 UTC ( #471772=note: print w/replies, xml ) Need Help??


in reply to Do you consider these different or the same?

You are asking the wrong questions. Instead, ask –
  1. What is the purpose of Test::More::is_deeply?
  2. What, then, should its semantics be?

My answer to the first is that is_deeply's purpose is to make it easy to test complex observed values by comparing them with given expected values.

My answer to the second, then, is that is_deeply should consider the observed and expected values to be equivalent if both have the same structure and subvalues, ignoring sharing. (Remember, I am talking semantics here, not implementation.)

Why ignore sharing? Because it rarely matters in tests. By ignoring it we make the common case easier for testers, who frequently hand-roll expected values. This goes back to the purpose of is_deeply; convenience matters.

As to your questions, then, here is how I answer. In the first case, $ar1 and $ar2 are equivalent. Both have the same structure and subvalues – [{},{}]. In the second case, they are not equivalent; [{a=>'foo'},{a=>'foo'}] differs from [{a=>'foo'},{}].

Cheers,
Tom

  • Comment on Re: Do you consider these different or the same?

Replies are listed 'Best First'.
Re^2: Do you consider these different or the same? (eq)
by tye (Sage) on Jul 02, 2005 at 02:44 UTC

    Exactly.

    Also note that the name "is_deeply" comes from the is() function that only cares about eq. So "is_deeply" is meant to convey applying eq deeply between two structures. Something that does more than that needs a different name if it is part of Test::More.

    The "deeply" part means that $a vs. "$a" fail the test if $a is a reference because only leaves are compared.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://471772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2022-12-10 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?