in reply to A proper name for is_sorted function that can check more than just sorting order?
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:
Output: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__
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):
Output:
Hope this helps, and Happy Merry!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by ikegami (Patriarch) on Dec 25, 2017 at 20:50 UTC | |
by 1nickt (Canon) on Dec 26, 2017 at 00:57 UTC | |
Re^2: A proper name for is_sorted function that can check more than just sorting order?
by Dallaylaen (Chaplain) on Dec 28, 2017 at 10:58 UTC |