Hi Dallaylaen,

Well, it may be because I am grumpy as always at this time of year, but to me it seems that you are trying to make things too shiny.

I prefer to use Lego bricks rather than modelling clay. As soon as you get your testing function just right, Murphy's Law says you will encounter data that doesn't fit. I would test your condition like this:

use strict; use warnings; use Test::More; my @data = ( { id => 1, start => 2, end => 3 }, { id => 2, start => 3, end => 4 }, { id => 3, start => 4, end => 5 }, # fail { id => 42, start => 6, end => 7 }, { id => 666, start => 7, end => 8 }, { id => 999, start => 8, end => 9 }, ); for ( 0 .. $#data - 1 ) { is( $data[ $_ + 1 ]->{'start'}, $data[ $_ ]->{'end'}, "$data[ $_ ] +->{'id'} sequence" ); } done_testing; __END__
Output:
1206160.pl .. 1/? # Failed test '3 sequence' # at 1206160.pl line 18. # got: '6' # expected: '5' # Looks like you failed 1 test of 5. 1206160.pl .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/5 subtests Test Summary Report ------------------- 1206160.pl (Wstat: 256 Tests: 5 Failed: 1) Failed test: 3 Non-zero exit status: 1 Files=1, Tests=5, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.04 cusr + 0.01 csys = 0.08 CPU) Result: FAIL

Or maybe like this .... Edit: as ikegami revealed the below is buggy. (emits a warning if number of list elements is not even):

se strict; use warnings; use Test::More; use List::Util 'pairfirst'; my @data = ( { id => 1, start => 2, end => 3 }, { id => 2, start => 3, end => 4 }, { id => 3, start => 4, end => 5 }, # fail { id => 42, start => 6, end => 7 }, { id => 666, start => 7, end => 8 }, { id => 999, start => 8, end => 9 }, ); my @failed = pairfirst { $a->{'end'} ne $b->{'start'} } @data; is( @failed, undef, 'sequencing' ) or diag sprintf 'ID %s and ID %s are not sequential', map { $_->{'id +'} } @failed; done_testing; __END__
Output:
prove 1206160.pl 1206160.pl .. 1/? # Failed test 'sequencing' # at 1206160.pl line 16. # got: '2' # expected: undef # ID 3 and ID 42 are not sequential # Looks like you failed 1 test of 1. 1206160.pl .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/1 subtests Test Summary Report ------------------- 1206160.pl (Wstat: 256 Tests: 1 Failed: 1) Failed test: 1 Non-zero exit status: 1 Files=1, Tests=1, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.06 cusr + 0.00 csys = 0.08 CPU) Result: FAIL

Hope this helps, and Happy Merry!


The way forward always starts with a minimal test.

In reply to Re: A proper name for is_sorted function that can check more than just sorting order? by 1nickt
in thread A proper name for is_sorted function that can check more than just sorting order? by Dallaylaen

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, details, 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, summary, 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.