develooper Front page | perl.module-authors | Postings from January 2010

Re: Comparing hashes

From:
mackenna
Date:
January 19, 2010 06:03
Subject:
Re: Comparing hashes
Message ID:
F8A3D0EC-E83E-4831-BC3D-7752CD220002@animalhead.com
Bruce Gray's reply indicates that your routine, that constructs the
array that you were comparing to the "gold" one, was populating the
array by using each(%hash).  Since the order in which entries are
returned is not consistent, you can't use a "known correct"
comparison.

It seems he even sent you a patch to use 'for (sort %hash)' instead.
If all forum responders were this helpful, all known computing
problems would be solved by now :-)

cmac

On Jan 18, 2010, at 8:01 AM, Geoffrey Leach wrote:

> Hmmmm ... that bruse on my forehead is getting larger ... :-)
>
> Thanks for the reply. And my appologies for getting confused about my
> own code.
>
> So let me restate the problem.
>
> In order to verify the correctness of internal data structures, the
> test in question:
>
> is_deeply( Getopt::Auto::_get_spec_ref(),
>     \@exspec, 'Spec gets built correctly' );
>
> uses is_deeply() to compare a 'gold' version of the array @exspec with
> the constructed instance, obtained by the (internal) function
> Getopt::Auto::_get_spec_ref().
>
> This succeeds (so far) on 5.10.x and all but one (so far) 5.8.x. I
> thinks there's a success on 5.11.x as well.
>
> What I meant by "having dealt with the problem" was that the problem
> exposed by the failing test, namely:
>
>   Failed test 'Spec gets built correctly'
>   at t/03-options_text.t line 107.
>     Structures begin differing at:
>          $got->[0][0] = '--foo'
>     $expected->[0][0] = '--tar'
>
> I my testing (5.10.x), when I saw a similar problem, I resolved it
> by organizing my 'gold' structure to match the computed version.
>
> Having gotten everything to work for 5.10.x, I was assuming that
> failures in 5.6.x had something to do with the internal organiation of
> the data structure (hence my reference to "unsupported feature"). The
> 5.8.1 failure came along later.
>
> Looks like I need to have another look at the generation.
>
> Thanks for the help.
>
> On 01/17/2010 05:33:33 PM, mackenna@animalhead.com wrote:
>>  From a quick glance at the first error, it involves using
>> is_deeply to compare arrays of arrays, not hashes.  So
>> it's not clear "how Perl organizes the hash" gets involved.
>>
>> You also have a failure on perl 5.8.1 that looks very similar,
>> so 5.6.2 is less of a suspect.
>>
>> You need to explain certain aspects of the problem more
>> completely to allow someone to help you, particularly:
>>
>> "what's generated at run time: it comes out different"
>> "dealt with this problem" (what problem?)
>> "getting it just right" (what's it?)
>> "using an unsupported feature" (which feature is that?)
>>
>>
>> On Jan 17, 2010, at 4:31 PM, Geoffrey Leach wrote:
>>
>>> I'm dealing with an error report from cpantesters for Getopt::Auto.
>>>
>>> The problem arrises out of using Test::More::is_deeply to compare a
>>> hash with what's generated at run time: it comes out different.
>>>
>>> I've delt with this problem in my own testing, and have spent some
>>> time
>>> getting it 'just right'. I suspect the problem arrises out of how
>> Perl
>>> organizes the hash. The version with the problem is perl-5.6.2.
>> Later
>>> versions pass. Given that I'm using an unsupported feature, things
>> may
>>> well come unglued in the future.
>>>
>>> So, are there any suggestions? Test::Deep? 'use Perl 5.8.0'?
>>>
>>> Thanks.
>>>
>>
>>
>
>
>




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About