r1553 - in
packages/libmath-combinatorics-perl/branches/upstream/current:
. lib/Math t
Carlo Segre
segre-guest at costa.debian.org
Thu Dec 1 17:00:56 UTC 2005
Author: segre-guest
Date: 2005-12-01 17:00:56 +0000 (Thu, 01 Dec 2005)
New Revision: 1553
Added:
packages/libmath-combinatorics-perl/branches/upstream/current/t/02.t
packages/libmath-combinatorics-perl/branches/upstream/current/t/03.t
Modified:
packages/libmath-combinatorics-perl/branches/upstream/current/MANIFEST
packages/libmath-combinatorics-perl/branches/upstream/current/META.yml
packages/libmath-combinatorics-perl/branches/upstream/current/lib/Math/Combinatorics.pm
packages/libmath-combinatorics-perl/branches/upstream/current/t/01.t
Log:
Load /tmp/tmp.DoF7Og/libmath-combinatorics-perl-0.08 into
packages/libmath-combinatorics-perl/branches/upstream/current.
Modified: packages/libmath-combinatorics-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/MANIFEST 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/MANIFEST 2005-12-01 17:00:56 UTC (rev 1553)
@@ -4,4 +4,6 @@
README
lib/Math/Combinatorics.pm
t/01.t
+t/02.t
+t/03.t
META.yml Module meta-data (added by MakeMaker)
Modified: packages/libmath-combinatorics-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/META.yml 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/META.yml 2005-12-01 17:00:56 UTC (rev 1553)
@@ -1,10 +1,10 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Math-Combinatorics
-version: 0.07
+version: 0.08
version_from: lib/Math/Combinatorics.pm
installdirs: site
requires:
distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30
+generated_by: ExtUtils::MakeMaker version 6.17
Modified: packages/libmath-combinatorics-perl/branches/upstream/current/lib/Math/Combinatorics.pm
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/lib/Math/Combinatorics.pm 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/lib/Math/Combinatorics.pm 2005-12-01 17:00:56 UTC (rev 1553)
@@ -113,7 +113,7 @@
$o = Math::Combinatorics->new( count=>3 , data=>[qw(. -)] , frequency=>[3,3] );
while ( my @x = $o->next_multiset ) {
- my $p = Math::Combinatorics->new( data=>\@x );
+ my $p = Math::Combinatorics->new( data=>\@x , frequency=>[map{1} @x] );
while ( my @y = $p->next_string ) {
#do something
}
@@ -155,12 +155,14 @@
=head1 ACKNOWLEDGEMENTS
-Thanks to everyone for helping to make this a better module.
+A sincere thanks to everyone for helping to make this a better module. After initial
+development I've only had time to accept patches and improvements. Math::Combinatorics
+continues to be developed and improved by the community. Contributors of note include:
-For adding new features: Carlos Rica, David Coppit, Carlos Segre
+For adding new features: Carlos Rica, David Coppit, Carlos Segre, Lyon Lemmens
For bug reports: Ying Yang, Joerg Beyer, Marc Logghe, Yunheng Wang,
-Torsten Seemann, Gerrit Haase, Joern Behre
+Torsten Seemann, Gerrit Haase, Joern Behre, Lyon Lemmens, Federico Lucifredi
=head1 BUGS / TODO
@@ -204,7 +206,7 @@
our @ISA = qw(Exporter);
our @EXPORT = qw( combine derange factorial permute );
-our $VERSION = '0.07';
+our $VERSION = '0.08';
=head1 EXPORTED FUNCTIONS
@@ -399,13 +401,15 @@
#appropriate for object elements, perhaps
compare => sub { $_[0]->value <=> $_[1]->value }
- defaults to "sub { $_[0] cmp $_[1] }"
+ The default sort mechanism is based on references, and cannot be predicted.
+ Improvements for a more flexible compare() mechanism are most welcome.
=cut
sub new {
my($class,%arg) = @_;
my $self = bless {}, $class;
+
$self->{compare} = $arg{compare} || sub { $_[0] cmp $_[1] };
$self->{count} = $arg{count};
@@ -434,10 +438,21 @@
#warn join ' ', @{$arg{data}};
+ #OK, this is hokey, but I don't have time to fix it properly right now.
+ #We want to allow both user-specified sorting as well as our own
+ #reference-based internal sorting -- the latter only because unit tests
+ #are failing if we don't have it. Additionally, we don't want to require
+ #the triple derefernce necessary for comparison of the pristine data in
+ #the user-supplied compare coderef. The solution for now is to do an
+ #if/else. If you're staring at this please fix it!
my $compare = $self->{compare};
+ if ( defined $arg{compare} ) {
+ $self->{data} = [sort {&$compare($$$a,$$$b)} map {\$_} @{$arg{data}}];
+ }
+ else {
+ $self->{data} = [sort {&$compare($a,$b)} map {\$_} @{$arg{data}}];
+ }
- $self->{data} = [sort {&$compare($a,$b)} map {\$_} @{$arg{data}}];
-
#warn Dumper($self->{data});
$self->{cin} = 1;
Modified: packages/libmath-combinatorics-perl/branches/upstream/current/t/01.t
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/t/01.t 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/t/01.t 2005-12-01 17:00:56 UTC (rev 1553)
@@ -50,7 +50,7 @@
while(my(@combo) = $c->next_combination){
$f++;
}
-ok($f == 6);
+ok($f == 6, ">>> $f == 6 <<<");
@data = ([],[],[],[]);
$c = Math::Combinatorics->new(
@@ -61,7 +61,7 @@
while(my(@combo) = $c->next_combination){
$f++;
}
-ok($f == 6);
+ok($f == 6, ">>> $f == 6 <<<");
@data = (1..10);
$c = Math::Combinatorics->new(
@@ -72,7 +72,7 @@
while(my(@combo) = $c->next_combination){
$f++;
}
-ok($f == 45);
+ok($f == 45, ">>> $f == 45 <<<");
#####################
# combine()
@@ -80,10 +80,10 @@
@data = qw( a b c d );
@r = combine(2, at data);
-ok(scalar(@r) == 6);
+ok(scalar(@r) == 6, ">>> ".scalar(@r)." == 6 <<<");
@r = combine(3, at data);
-ok(scalar(@r) == 4);
+ok(scalar(@r) == 4, ">>> ".scalar(@r)." == 6 <<<");
#####################
# next_multiset
@@ -98,7 +98,7 @@
while(my(@combo) = $c->next_multiset){
$f++;
}
-ok($f == 6);
+ok($f == 6, ">>> $f == 6 <<<");
$c = Math::Combinatorics->new(
data => \@data,
@@ -109,7 +109,7 @@
while(my(@combo) = $c->next_multiset){
$f++;
}
-ok($f == 7);
+ok($f == 7, ">>> $f == 7 <<<");
#####################
# next_permutation()
Added: packages/libmath-combinatorics-perl/branches/upstream/current/t/02.t
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/t/02.t 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/t/02.t 2005-12-01 17:00:56 UTC (rev 1553)
@@ -0,0 +1,50 @@
+BEGIN {
+ use lib 'lib';
+ use strict;
+ use Test::More;
+
+ plan tests => 5;
+
+ use_ok('Data::Dumper');
+ use_ok('Math::Combinatorics');
+}
+
+my $c;
+my $f = 0;
+my @r;
+my @data;
+
+ at data = ( 'a', [], 'b', [] );
+$c = Math::Combinatorics->new(
+ data => \@data,
+ count => 2,
+ );
+$f = 0;
+while(my(@combo) = $c->next_combination){
+ #warn "combo $f is: ".join " ", @combo;
+ $f++;
+}
+ok($f == 6, ">>> $f == 6 <<<");
+
+ at data = ([],[],[],[]);
+$c = Math::Combinatorics->new(
+ data => \@data,
+ count => 2,
+ );
+$f = 0;
+while(my(@combo) = $c->next_combination){
+ $f++;
+}
+ok($f == 6, ">>> $f == 6 <<<");
+
+ at data = (1..10);
+$c = Math::Combinatorics->new(
+ data => \@data,
+ count => 2,
+ );
+$f = 0;
+while(my(@combo) = $c->next_combination){
+ $f++;
+}
+ok($f == 45, ">>> $f == 45 <<<");
+
Added: packages/libmath-combinatorics-perl/branches/upstream/current/t/03.t
===================================================================
--- packages/libmath-combinatorics-perl/branches/upstream/current/t/03.t 2005-11-29 03:19:29 UTC (rev 1552)
+++ packages/libmath-combinatorics-perl/branches/upstream/current/t/03.t 2005-12-01 17:00:56 UTC (rev 1553)
@@ -0,0 +1,93 @@
+BEGIN {
+ use lib 'lib';
+ use strict;
+ use Test::More;
+
+ plan tests => 3;
+
+ use_ok('Data::Dumper');
+ use_ok('Math::Combinatorics');
+}
+
+my @S = qw(d a c b);
+my @R = map {\$_} qw(d a c b);
+
+my $rsort = sub { my ($a,$b) = @_; return $b cmp $a };
+#my $rsort = sub { my ($a,$b) = @_; return $b cmp $a };
+
+my $set = Math::Combinatorics->new(
+ count => scalar(@S) ,
+ data => [ @S ] ,
+ compare => $rsort ,
+);
+$c = join '', $set->next_combination();
+is( $c, q{dcba}, q{expecting reverse ordered array} );
+
+__DATA__
+#! /usr/bin/perl
+
+use warnings;
+use strict;
+
+use lib q{.};
+use Math::Combinatorics qw<combine>;
+use Data::Dumper;
+
+use Test::More tests => 5;
+
+ # test with a regular array and with an array of references
+ #
+my @TEST_ARR = qw{d a c b};
+my @TEST_REF = \( qw{d a c b} );
+
+# Combine without passing a compare function, Combination should be sorted
+# by the internal compare function, which sorts alphabetically.
+#
+{
+ my $c = join q{}, @{ (combine(scalar @TEST_ARR, @TEST_ARR))[0] };
+ is( $c, q{abcd}, q{expecting ordered array} );
+}
+
+# Combine with passing a compare function as defined in the manual. I expect
+# it to die.
+#
+{
+ my $alphabetically = sub {
+ my $a = shift; die qq{REFARGS\n} if ref $a;
+ my $b = shift; die qq{REFARGS\n} if ref $b;
+ return $a cmp $b;
+ };
+ my $c = join q{}, eval {
+ my $set = Math::Combinatorics->new(
+ count => scalar @TEST_ARR ,
+ data => [ @TEST_ARR ] ,
+ compare => $alphabetically ,
+ );
+ $set->next_combination();
+ };
+ is( $@, q{}, q{expecting compare not to die} );
+ is( $c, q{abcd}, q{expecting ordered array} );
+}
+
+# do the same with a list of references
+#
+{
+ my $alphabetically = sub {
+ my $a = shift; die qq{NOREFARGS\n} unless q{SCALAR} eq ref $a;
+ my $b = shift; die qq{NOREFARGS\n} unless q{SCALAR} eq ref $a;
+ return $$a cmp $$b;
+ };
+
+ # we now have an array of refs, so we need a map {} in between
+ #
+ my $c = join q{}, map { $$_ } eval {
+ my $set = Math::Combinatorics->new(
+ count => scalar @TEST_REF ,
+ data => [ @TEST_REF ] ,
+ compare => $alphabetically ,
+ );
+ $set->next_combination();
+ };
+ is( $@, q{}, q{expecting compare not to die} );
+ is( $c, q{abcd}, q{expecting ordered array} );
+}
More information about the Pkg-perl-cvs-commits
mailing list