On 7/1/05, Ovid <[EMAIL PROTECTED]> wrote:
> --- Piers Cawley <[EMAIL PROTECTED]> wrote:
> > I've always thought of C<is_deeply> as being about the 'shape' of a
> > data
> > structure. When you think of things in this way, then it seems
> > obvious that given
> >
> > $a = [], $b = [], $c = []
> >
> > then [$a, $a] and [$b, $c] have substantially different shapes.
>
> That's not obvious to me. When I look at that, I ultimately see this
> *shape* for each: "[[],[]]". In other words, I'm just looking for what
> data is arranged in what type of data structure. I'm not really
> considering how that structure might mutate given that someone comes
> along later and changes one of the values. I'd write a test for that.
Me, Id hope that Test::More::is_deeply() did test for that... (but
then that the whole point of this debate)
>
> Heck, if we're going to consider that, why would this pass?
>
> my $a = [1,2,3];
> my $b = [1,2,3];
> is_deeply $a, $b, '...';
> is_deeply $a, $a, '...';
>
> That should pass nicely, but start shoving those array refs in other
> array refs and things fail? I don't see why.
Acutally i dont understand the example. Im not arguing either of those
should fail.
>
> The argument seems to be that when we have [$a, $a] and [$b, $c],
> changing the value of $a in the first changes the value of the other $a
> and therefore the two array refs are not *functionally* equivalent. I
> want to know if the *data* are the same for a given test (which I like
> to think of as a snapshot in time).
So would i. Its just that i dont like it when "looks the same but is
not the same" is confused for "is the same".
> Whether or not the *behaviors* are
> the same is the reason I write more than one test. (Yes, I know that
> some might consider wether or not the references refer to the same area
> of memory as important. If so, don't use is_deeply. Perhaps we should
> have another test function?)
Well, yes we probably should have another function. Its just that it
should be what is_deeply() does now and the is_deeply() should be
fixed. But ive beaten that horse long enough to know its not gunna
happen :-)
>
> So, just for the sake of argument, imagine I write a class where I
> periodically returns array refs to the user. I do this by building
> them every time they're called. Later, I realize that my methods are
> deterministic so I start caching results and returning them instead of
> rebuilding the array each time. I'm expecting my test suite to still
> continue working but under this proposed idea, it could be a nightmare
> for me to debug. Heck, when I print out the arrays with Data::Dumper,
> I'll see the same values and be mystified why they're not equivalent.
Actually you will see a difference when you use Data::Dumper. At least
if i understand the scenario you mean.
use Data::Dumper;
my $y={};
my @x=($y,$y,$y);
my @z=({},{},{});
print Dumper([EMAIL PROTECTED],[EMAIL PROTECTED]);
__END__
$VAR1 = [
{},
$VAR1->[0],
$VAR1->[0]
];
$VAR2 = [
{},
{},
{}
];
I tend to think people would be more surprised (given the current
documentation of is_deeply()) that the dump would be different yet
is_deeply() would say they are the same.
In fact its probably a good idea to point out in the docs that
is_deeply() will very often disagree with is_deeply.
yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"