r64576 - in /branches/upstream/libset-intspan-perl/current: Changes IntSpan.pm MANIFEST META.yml t/ord.t t/span_ord.t

periapt-guest at users.alioth.debian.org periapt-guest at users.alioth.debian.org
Fri Nov 5 08:18:01 UTC 2010


Author: periapt-guest
Date: Fri Nov  5 08:17:28 2010
New Revision: 64576

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=64576
Log:
[svn-upgrade] new version libset-intspan-perl (1.15)

Added:
    branches/upstream/libset-intspan-perl/current/t/ord.t
    branches/upstream/libset-intspan-perl/current/t/span_ord.t
Modified:
    branches/upstream/libset-intspan-perl/current/Changes
    branches/upstream/libset-intspan-perl/current/IntSpan.pm
    branches/upstream/libset-intspan-perl/current/MANIFEST
    branches/upstream/libset-intspan-perl/current/META.yml

Modified: branches/upstream/libset-intspan-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/Changes?rev=64576&op=diff
==============================================================================
--- branches/upstream/libset-intspan-perl/current/Changes (original)
+++ branches/upstream/libset-intspan-perl/current/Changes Fri Nov  5 08:17:28 2010
@@ -1,4 +1,7 @@
 Revision history for Perl extension Set::IntSpan
+
+1.15  2010 Nov 04
+        - added span_ord() method
 
 1.14  2010 Jun 22
         - added ord() method

Modified: branches/upstream/libset-intspan-perl/current/IntSpan.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/IntSpan.pm?rev=64576&op=diff
==============================================================================
--- branches/upstream/libset-intspan-perl/current/IntSpan.pm (original)
+++ branches/upstream/libset-intspan-perl/current/IntSpan.pm Fri Nov  5 08:17:28 2010
@@ -6,7 +6,7 @@
 use base qw(Exporter);
 use Carp;
 
-our $VERSION   = '1.14';
+our $VERSION   = '1.15';
 our @EXPORT_OK = qw(grep_set map_set grep_spans map_spans);
 
 use overload
@@ -902,6 +902,13 @@
     $upper + 1
 }
 
+sub span_ord
+{
+    my($set, $n) = @_;
+
+    my $i = _bsearch($set->{edges}, $n);
+    ($set->{negInf} xor $i & 1) ? $i >> 1 : undef
+}
 
 sub min
 {
@@ -1411,8 +1418,6 @@
     undef
 }
 
-
-
 sub slice
 {
     my($set, $from, $to) = @_;
@@ -1644,6 +1649,7 @@
   $n       = $set->at($i);
   $slice   = $set->slice($from, $to);
   $i       = $set->ord($n);
+  $i       = $set->span_ord($n);
 
 =head2 Operator overloads
 
@@ -2319,6 +2325,15 @@
 
 Dies if I<$set> is C<neg_inf>.
 
+=item I<$i> = I<$set>->C<span_ord>($n)
+
+Returns the index I<$i> of the span containing the integer I<$n>,
+or C<undef> if I<$n> if not an element of I<$set>.
+
+To recover the span continaing I<$n>, write
+
+  (I<$set>->C<spans>)[I<$i>]
+
 =back
 
 
@@ -2647,6 +2662,10 @@
 
 Marc Lehmann <schmorp at schmorp.de>
 
+=item *
+
+Andrew Olson <aolson at me.com>
+
 =back
 
 

Modified: branches/upstream/libset-intspan-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/MANIFEST?rev=64576&op=diff
==============================================================================
--- branches/upstream/libset-intspan-perl/current/MANIFEST (original)
+++ branches/upstream/libset-intspan-perl/current/MANIFEST Fri Nov  5 08:17:28 2010
@@ -12,10 +12,12 @@
 t/island.t
 t/iterator.t
 t/member.t
+t/ord.t
 t/overload.t
 t/real_set.t
 t/relation.t
 t/set_spec.t
+t/span_ord.t
 t/spans.t
 t/subclass.t
 t/unary.t

Modified: branches/upstream/libset-intspan-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/META.yml?rev=64576&op=diff
==============================================================================
--- branches/upstream/libset-intspan-perl/current/META.yml (original)
+++ branches/upstream/libset-intspan-perl/current/META.yml Fri Nov  5 08:17:28 2010
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Set-IntSpan
-version:            1.14
+version:            1.15
 abstract:           Manages sets of integers, newsrc style
 author:
     - Steven McDougall (swmcd at world.std.com)

Added: branches/upstream/libset-intspan-perl/current/t/ord.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/t/ord.t?rev=64576&op=file
==============================================================================
--- branches/upstream/libset-intspan-perl/current/t/ord.t (added)
+++ branches/upstream/libset-intspan-perl/current/t/ord.t Fri Nov  5 08:17:28 2010
@@ -1,0 +1,68 @@
+# -*- perl -*-
+
+use strict;
+use Set::IntSpan 1.14;
+
+my $N = 1;
+sub Not { print "not " }
+sub OK
+{
+    my($function, $test) = @_;
+
+    $test ||= [];
+    for (@$test) { defined $_ or $_ = '<undef>' }
+    my $expected = pop @$test;
+
+    print "ok $N $function: @$test\t-> $expected\n";
+
+    $N++;
+}
+
+my @Ord_die =
+(
+ [ '(-0',  42, '<die>' ],
+);
+
+my @Ord_test =
+(
+ [ '-'	  	    ,  0, undef ],
+ [ '0'	  	    ,  0, 0     ],
+ [ '1'	  	    ,  0, undef ],
+ [ '1'	  	    ,  2, undef ],
+ [ '1,3-5'	    ,  0, undef ],
+ [ '1,3-5'	    ,  1, 0     ],
+ [ '1,3-5'	    ,  2, undef ],
+ [ '1,3-5'	    ,  3, 1     ],
+ [ '1,3-5'	    ,  4, 2     ],
+ [ '1,3-5'	    ,  5, 3     ],
+ [ '1,3-5'	    ,  6, undef ],
+ [ '1-)'  	    ,  0, undef ],
+ [ '1-)'  	    ,  1, 0     ],
+ [ '1-)'  	    ,  8, 7     ],
+ [ '1-5,11-15,21-25', 21, 10    ],
+);
+
+print "1..", @Ord_die + @Ord_test, "\n";
+
+for my $test (@Ord_die)
+{
+    my($run_list, $n) = @$test;
+
+    eval { Set::IntSpan->new($run_list)->ord($n) };
+    $@ or Not; OK("ord", $test);
+}
+
+for my $test (@Ord_test)
+{
+    my($run_list, $n, $i) = @$test;
+
+    equal(Set::IntSpan->new($run_list)->ord($n), $i) or Not; OK("ord", $test);
+}
+
+sub equal
+{
+    my($a, $b) = @_;
+
+    not defined $a and not defined $b or
+        defined $a and     defined $b and $a == $b
+}

Added: branches/upstream/libset-intspan-perl/current/t/span_ord.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libset-intspan-perl/current/t/span_ord.t?rev=64576&op=file
==============================================================================
--- branches/upstream/libset-intspan-perl/current/t/span_ord.t (added)
+++ branches/upstream/libset-intspan-perl/current/t/span_ord.t Fri Nov  5 08:17:28 2010
@@ -1,0 +1,87 @@
+# -*- perl -*-
+
+use strict;
+use Set::IntSpan 1.14;
+
+my $N = 1;
+sub Not { print "not " }
+
+sub OK_ord
+{
+    my $test = shift;
+
+    my($runlist, $n, $ord_exp, $span_exp) = @$test;
+    $ord_exp = '<undef>' unless defined $ord_exp;
+    print "ok $N ord : $runlist $n\t-> $ord_exp\n";
+    $N++;
+}
+
+sub OK_span
+{
+    my $test = shift;
+
+    my($runlist, $n, $ord_exp, $span_exp) = @$test;
+    $span_exp = defined $span_exp ? join ', ', map { defined($_) ? $_ : '<undef>' } @$span_exp : '<undef>';
+    print "ok $N span: $runlist $n\t-> $span_exp\n";
+
+    $N++;
+}
+
+my @Span_ord_test =
+(
+ [ '-'	  	    	  ,  0, undef, undef	      ],
+ [ '(-)'  	    	  ,  0, 0    , [undef, undef] ],
+ [ '0'	  	    	  ,  0, 0    , [    0,     0] ],
+ [ '1'	  	    	  ,  0, undef, undef	      ],
+ [ '1'	  	    	  ,  1, 0    , [    1,     1] ],
+ [ '1'	  	    	  ,  2, undef, undef	      ],
+ [ '1,3-5'	    	  ,  0, undef, undef	      ],
+ [ '1,3-5'	    	  ,  1, 0    , [    1,     1] ],
+ [ '1,3-5'	    	  ,  2, undef, undef	      ],
+ [ '1,3-5'	    	  ,  3, 1    , [    3,     5] ],
+ [ '1,3-5'	    	  ,  4, 1    , [    3,     5] ],
+ [ '1,3-5'	    	  ,  5, 1    , [    3,     5] ],
+ [ '1,3-5'	    	  ,  6, undef, undef	      ],
+ [ '1-)'  	    	  ,  0, undef, undef	      ],
+ [ '1-)'  	    	  ,  1, 0    , [    1, undef] ],
+ [ '1-)'  	    	  ,  2, 0    , [    1, undef] ],
+ [ '(-1'  	    	  ,  0, 0    , [undef,     1] ],
+ [ '(-1'  	    	  ,  1, 0    , [undef,     1] ],
+ [ '(-1'  	    	  ,  2, undef, undef	      ],
+ [ '1-5,11-15,21-25'	  , 21, 2    , [   21,    25] ],
+ [ '(-5,11-15,21-25'	  , 21, 2    , [   21,    25] ],
+ [ '1-5,11-15,21-25,30-40', 21, 2    , [   21,    25] ],
+ [ '(-5,11-15,21-25,30-)' , 21, 2    , [   21,    25] ],
+ [ '(-5,11-15,21-25,30-)' , 20, undef, undef	      ],
+);
+
+print "1..",  2 * @Span_ord_test, "\n";
+
+for my $test (@Span_ord_test)
+{
+    my($run_list, $n, $ord_exp, $span_exp) = @$test;
+
+    my $set = new Set::IntSpan $run_list;
+    my $ord_act = $set->span_ord($n);
+    identical_n($ord_act, $ord_exp) or Not; OK_ord($test);
+
+    my $span_act = defined $ord_act ? ($set->spans)[$ord_act] : undef;
+    identical_span($span_act, $span_exp) or Not; OK_span($test);
+}
+
+sub identical_n
+{
+    my($a, $b) = @_;
+
+    not defined $a and not defined $b or
+        defined $a and     defined $b and $a == $b
+}
+
+sub identical_span
+{
+    my($a, $b) = @_;
+
+    not defined $a and not defined $b or
+	defined $a and     defined $b and
+	    identical_n($a->[0], $b->[0]) and identical_n($a->[1], $b->[1])
+}




More information about the Pkg-perl-cvs-commits mailing list