Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

OK, I think I understand now; I hadn’t realised that separate hashes within the one array could legitimately contain the same keys with different values.

I still think a generic procedure will work, it just needs a comprehensive sorting algorithm:

#! perl use strict; use warnings; use Test::More tests => 2; use Test::Deep; my @x = ( { key_3 => 'A', key_2 => 'CC', key_4 => 'E', key_5 => 0 }, { key_3 => 'A', key_2 => 'DD', key_4 => 'F' }, ); my @y = ( { key_3 => 'A', key_2 => 'DD', key_4 => 'F' }, { key_5 => 0, key_3 => 'A', key_2 => 'CC', key_4 => 'E' }, ); cmp_deeply( \@x, bag(@y), 'Deep' ); print '-' x 20, "\n"; is_deeply( my_sort(@x), my_sort(@y), 'More' ); sub my_sort { my $f = sub { my @keys_a = sort keys %$a; my @keys_b = sort keys %$b; return -1 if @keys_a < @keys_b; return 1 if @keys_a > @keys_b; my $result = 0; $result ||= $keys_a[$_] cmp $keys_b[$_] || $a->{$keys_a[$_]} cmp $b->{$keys_b[$_]} for 0 .. $#k +eys_a; return $result; }; return [ sort $f @_ ]; }

(For the basic idea, see perlfaq4#How-do-I-sort-an-array-by-anything.) Output:

14:38 >perl 1314a_SoPW.pl 1..2 ok 1 - Deep -------------------- ok 2 - More 14:38 >

Disclaimer: I’ve tested this only minimally; there may be corner cases I haven’t found. But I think this should allow you to return to using Test::More::is_deeply to get the benefit of its superior failure messages.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: Diagnostic messages in Test::Deep by Athanasius
in thread Diagnostic messages in Test::Deep by KeighleHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (6)
    As of 2020-10-26 10:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (251 votes). Check out past polls.

      Notices?