Skip Menu |

This queue is for tickets about the Set-Intersection CPAN distribution.

Report information
The Basics
Id: 101984
Status: resolved
Priority: 0/
Queue: Set-Intersection

People
Owner: Nobody in particular
Requestors: jkeenan [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Improve documentation; add descriptions for tests
While using search.cpan.org to locate distributions concerning "Intersection", I came across Set-Intersection (and was flattered to see that you reference my List-Compare). I'm attaching two patches which make no changes in the source code but which (a) improve the English-language style of some of the documentation; and (b) provide descriptions for most of the individual tests in t/*.t. If you're a github.com user, you could pick up from: https://github.com/jkeenan/set-intersection I hope you find that useful. Thank you very much. Jim Keenan (CPAN ID: JKEENAN)
On Fri Feb 06 20:13:48 2015, JKEENAN wrote: [snip] Show quoted text
> > I'm attaching two patches which make no changes in the source code but
Forgot the patches!
Subject: 0001-Add-metacpan.org-as-search-link-in-README-and-POD.patch
From 050bee0be6a795ab71d2840f5d4a69b15c242d9d Mon Sep 17 00:00:00 2001 From: James E Keenan <jkeenan@cpan.org> Date: Wed, 4 Feb 2015 21:52:05 -0500 Subject: [PATCH 1/2] Add metacpan.org as search link in README and POD. Increment version to 0.02_001 for development version. Improve POD formatting and English style. Capture the warning emitted when an array passed as an argument to get_intersection() contains an 'undef'; test for that warning. TODO: Add descriptions for tests. --- README | 106 ++++++++------- lib/Set/Intersection.pm | 352 ++++++++++++++++++++++++------------------------ t/10-errors.t | 32 +++-- 3 files changed, 251 insertions(+), 239 deletions(-) diff --git a/README b/README index 1a4e06f..ba8b40f 100644 --- a/README +++ b/README @@ -1,52 +1,54 @@ -Set-Intersection - -The README is used to introduce the module and provide instructions on -how to install the module, any machine dependencies it may have (for -example C compilers and installed libraries) and any other information -that should be provided before the module is installed. - -A README file is required for CPAN modules since CPAN extracts the README -file from a module distribution so that people browsing the archive -can use it to get an idea of the module's uses. It is usually a good idea -to provide version information here so that people can decide whether -fixes for the module are worth downloading. - - -INSTALLATION - -To install this module, run the following commands: - - perl Makefile.PL - make - make test - make install - -SUPPORT AND DOCUMENTATION - -After installing, you can find documentation for this module with the -perldoc command. - - perldoc Set::Intersection - -You can also look for information at: - - RT, CPAN's request tracker - http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-Intersection - - AnnoCPAN, Annotated CPAN documentation - http://annocpan.org/dist/Set-Intersection - - CPAN Ratings - http://cpanratings.perl.org/d/Set-Intersection - - Search CPAN - http://search.cpan.org/dist/Set-Intersection/ - - -COPYRIGHT AND LICENCE - -Copyright (C) 2009 turugina - -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. - +Set-Intersection + +The README is used to introduce the module and provide instructions on +how to install the module, any machine dependencies it may have (for +example C compilers and installed libraries) and any other information +that should be provided before the module is installed. + +A README file is required for CPAN modules since CPAN extracts the README +file from a module distribution so that people browsing the archive +can use it to get an idea of the module's uses. It is usually a good idea +to provide version information here so that people can decide whether +fixes for the module are worth downloading. + + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + +SUPPORT AND DOCUMENTATION + +After installing, you can find documentation for this module with the +perldoc command. + + perldoc Set::Intersection + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-Intersection + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/Set-Intersection + + CPAN Ratings + http://cpanratings.perl.org/d/Set-Intersection + + Search CPAN + http://search.cpan.org/dist/Set-Intersection/ + https://metacpan.org/pod/Set::Intersection + + +COPYRIGHT AND LICENCE + +Copyright (C) 2009 turugina + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + + diff --git a/lib/Set/Intersection.pm b/lib/Set/Intersection.pm index fda5964..1f14f9e 100644 --- a/lib/Set/Intersection.pm +++ b/lib/Set/Intersection.pm @@ -1,175 +1,177 @@ -package Set::Intersection; - -use warnings; -use strict; - -=head1 NAME - -Set::Intersection - provides an API to get intersection (of set theory) of ARRAYs. - -=head1 VERSION - -Version 0.01 - -=cut - -our $VERSION = '0.02'; - - -=head1 SYNOPSIS - - use Set::Intersection; - - my @arr1 = qw/3 1 4 1 5 9/; - my @arr2 = qw/1 7 3 2 0 5/; - my @intersection = get_intersection(\@arr1, \@arr2); - # got (1, 3, 5) in @intersection - -=head1 EXPORT - -get_intersection - -=cut - -require Exporter; -our @ISA = qw/Exporter/; - -our @EXPORT = qw/get_intersection/; - -=head1 FUNCTIONS - -=head2 get_intersection [\%options,] [\@ARRAY[, \@ARRAY[, ...]]] - -Returns intersection set (as LIST) of all ARRAYs. - -=over 1 - -=item The result LIST is uniqized and unordered. - -=item If no ARRAYs passed, the result LIST is empty. - -=item If only one ARRAY passed, the result LIST is same as the passed. (elements won't be uniqized nor order-changed) - -=item If you have undef in any LIST, you'll be warned. - -=back - -=over 1 - -=item %options - -=over 2 - -=item -preordered => BOOLEAN - -=over 3 - -=item To reduce calculation time, get_intersection sorts ARRAYs - by their length before calculating intersections. - -=item This option tells that order of ARRAYs are well done, - and calculation of intersection will be based on left most ARRAY. - -=back - -=back - -=back - -=cut - -my %_default_opts = ( - -preordered => 0, -); - -sub get_intersection -{ - my %opts; - if ( ref($_[0]) =~ m{^HASH} ) { - %opts = (%_default_opts, %{$_[0]}); - shift; - } - - my @arrs = @_; - return () if !@arrs; - return @{$arrs[0]} if @arrs == 1; - - @arrs = sort { @$a <=> @$b } @arrs if !$opts{-preordered}; - - my $head = shift @arrs; - - _intersection($head, @arrs); -} - -sub _intersection -{ - my ($head, @left) = @_; - - my %h = map { $_ => undef } @$head; - for my $l ( @left ) { - %h = map { $_ => undef } grep { exists $h{$_} } @$l; - } - keys %h; -} - -=head1 SEE ALSO - -List::Compare, Set::Object - -=head1 AUTHOR - -turugina, C<< <turugina at cpan.org> >> - -=head1 BUGS - -Please report any bugs or feature requests to C<bug-list-intersection at rt.cpan.org>, or through -the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Set-Intersection>. I will be notified, and then you'll -automatically be notified of progress on your bug as I make changes. - - - - -=head1 SUPPORT - -You can find documentation for this module with the perldoc command. - - perldoc Set::Intersection - - -You can also look for information at: - -=over 4 - -=item * RT: CPAN's request tracker - -L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-Intersection> - -=item * AnnoCPAN: Annotated CPAN documentation - -L<http://annocpan.org/dist/Set-Intersection> - -=item * CPAN Ratings - -L<http://cpanratings.perl.org/d/Set-Intersection> - -=item * Search CPAN - -L<http://search.cpan.org/dist/Set-Intersection/> - -=back - - -=head1 ACKNOWLEDGEMENTS - - -=head1 COPYRIGHT & LICENSE - -Copyright 2009 turugina, all rights reserved. - -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. - - -=cut - -1; # End of Set::Intersection +package Set::Intersection; + +use warnings; +use strict; + +=head1 NAME + +Set::Intersection - provides an API to get intersection (of set theory) of ARRAYs. + +=head1 VERSION + +Version 0.02_001 + +=cut + +our $VERSION = '0.02_001'; + + +=head1 SYNOPSIS + + use Set::Intersection; + + my @arr1 = qw/3 1 4 1 5 9/; + my @arr2 = qw/1 7 3 2 0 5/; + my @intersection = get_intersection(\@arr1, \@arr2); + # got (1, 3, 5) in @intersection + +=head1 EXPORT + +get_intersection + +=cut + +require Exporter; +our @ISA = qw/Exporter/; + +our @EXPORT = qw/get_intersection/; + +=head1 FUNCTIONS + +=head2 C<get_intersection()> + + get_intersection([\%options,] [\@ARRAY[, \@ARRAY[, ...]]]); + +Returns intersection set (as LIST) of all ARRAYs. + +=over 4 + +=item * + +The result LIST is uniqued and unordered. + +=item * + +If no ARRAYs are passed, the result LIST is empty. + +=item * + +If only one ARRAY is passed, the result LIST is same as that passed. (In this +case, elements won't be uniqued nor will the order bechanged.) + +=item * + +If you have C<undef> in any LIST, you'll be warned. + +=back + +=head3 C<%options> + + -preordered => BOOLEAN + +To reduce calculation time, C<get_intersection()> sorts ARRAYs +by their length before calculating intersections. + +This option tells that order of ARRAYs are well done, +and calculation of intersection will be based on left most ARRAY. + +=cut + +my %_default_opts = ( + -preordered => 0, +); + +sub get_intersection +{ + my %opts; + if ( ref($_[0]) =~ m{^HASH} ) { + %opts = (%_default_opts, %{$_[0]}); + shift; + } + + my @arrs = @_; + return () if !@arrs; + return @{$arrs[0]} if @arrs == 1; + + @arrs = sort { @$a <=> @$b } @arrs if !$opts{-preordered}; + + my $head = shift @arrs; + + _intersection($head, @arrs); +} + +sub _intersection +{ + my ($head, @left) = @_; + + my %h = map { $_ => undef } @$head; + for my $l ( @left ) { + %h = map { $_ => undef } grep { exists $h{$_} } @$l; + } + keys %h; +} + +=head1 SEE ALSO + +List::Compare, Set::Object + +=head1 AUTHOR + +turugina, C<< <turugina at cpan.org> >> + +=head1 BUGS + +Please report any bugs or feature requests to C<bug-list-intersection at rt.cpan.org>, or through +the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Set-Intersection>. I will be notified, and then you'll +automatically be notified of progress on your bug as I make changes. + + + + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Set::Intersection + +You can also look for information at: + +=over 4 + +=item * RT: CPAN's request tracker + +L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Set-Intersection> + +=item * AnnoCPAN: Annotated CPAN documentation + +L<http://annocpan.org/dist/Set-Intersection> + +=item * CPAN Ratings + +L<http://cpanratings.perl.org/d/Set-Intersection> + +=item * Search CPAN + +L<http://search.cpan.org/dist/Set-Intersection/> + +or + +L<https://metacpan.org/pod/Set::Intersection> + +=back + + +=head1 ACKNOWLEDGEMENTS + +=head1 COPYRIGHT & LICENSE + +Copyright 2009 turugina, all rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + + +=cut + +1; # End of Set::Intersection + diff --git a/t/10-errors.t b/t/10-errors.t index 6db6660..7f6de67 100644 --- a/t/10-errors.t +++ b/t/10-errors.t @@ -1,12 +1,20 @@ -use strict; - -use Test::More tests => 1; - -use Set::Intersection; - -use Data::Dumper; - -# use of undef in key of hash is warning ?? -eval { get_intersection([undef],[undef,undef]); }; -ok !$@; - +use strict; + +use Test::More tests => 2; + +use Set::Intersection; + +use Data::Dumper; + +# use of undef in key of hash is warning ?? +my $warn = ''; +local $SIG{__WARN__} = sub { $warn .= $_[0] }; +eval { get_intersection([undef],[undef,undef]); }; +#say STDERR "<$warn>"; +like($warn, + qr/Use of uninitialized value in list assignment/s, + "Got expected warning of 'undef' in arrays provided as arguments" +); +ok !$@; + + -- 1.9.1
Subject: 0002-Provide-descriptions-for-many-tests-lacking-them.patch
From 240d04020052b68767bbcb0c8ae1c0dfdbf5954d Mon Sep 17 00:00:00 2001 From: James E Keenan <jkeenan@cpan.org> Date: Fri, 6 Feb 2015 19:48:57 -0500 Subject: [PATCH 2/2] Provide descriptions for many tests lacking them. Use Unix file format in test files. --- t/00-load.t | 23 ++++++------ t/01-intersection.t | 103 ++++++++++++++++++++++++++++------------------------ t/02-options.t | 33 ++++++++++------- t/10-errors.t | 2 +- 4 files changed, 87 insertions(+), 74 deletions(-) mode change 100755 => 100644 t/00-load.t diff --git a/t/00-load.t b/t/00-load.t old mode 100755 new mode 100644 index b28fa6c..1c8bedf --- a/t/00-load.t +++ b/t/00-load.t @@ -1,11 +1,12 @@ -#!perl -T - -use Test::More tests => 2; - -BEGIN { - use_ok( 'Set::Intersection' ); -} - -ok $Set::Intersection::VERSION; - -diag( "Testing Set::Intersection $Set::Intersection::VERSION, Perl $], $^X" ); +#!perl -T + +use Test::More tests => 2; + +BEGIN { + use_ok( 'Set::Intersection' ); +} + +ok $Set::Intersection::VERSION; + +diag( "Testing Set::Intersection $Set::Intersection::VERSION, Perl $], $^X" ); + diff --git a/t/01-intersection.t b/t/01-intersection.t index a0fcc9d..6370e38 100644 --- a/t/01-intersection.t +++ b/t/01-intersection.t @@ -1,48 +1,55 @@ -use strict; -use Test::More tests => 18; - -use Set::Intersection; - -my @l1 = qw/3 1 4 1 5 9/; -my @l2 = qw/1 7 3 2 0 5/; - -my @r = get_intersection(\@l1, \@l2); -is scalar(@r), 3; -is join(',', sort @r), '1,3,5'; -is join(' ', @l1), '3 1 4 1 5 9'; -is join(' ', @l2), '1 7 3 2 0 5'; - -my @l3 = qw/2 4 3 6 2 0 6 7 9/; - -@r = get_intersection(\@l1, \@l2, \@l3); -is scalar(@r), 1; -is $r[0], 3; -is join(' ', @l1), '3 1 4 1 5 9'; -is join(' ', @l2), '1 7 3 2 0 5'; -is join(' ', @l3), '2 4 3 6 2 0 6 7 9'; - -my @l4 = qw/1 4 1 4 2/; - -@r = get_intersection(\@l1, \@l2, \@l3, \@l4); -ok !@r; - -@r = get_intersection([qw/1 3 5 7 9/], [qw/1 1 2 3 5 8 13/]); -is scalar(@r), 3; -is join(',', sort @r), '1,3,5'; - -@r = get_intersection([qw/there is more than one way to do it/], [qw/there is nothing to do/]); -is scalar(@r), 4; -is join(',', sort @r), 'do,is,there,to'; - -@r = get_intersection([],[]); -ok !@r; - -@r = get_intersection([],[1]); -ok !@r; - -@r = get_intersection(); -ok !@r; - -@r = get_intersection([qw/1 2 3 4 5/]); -is join(',', @r), '1,2,3,4,5'; - +use strict; +use Test::More tests => 18; + +use Set::Intersection; + +my @l1 = qw/3 1 4 1 5 9/; +my @l2 = qw/1 7 3 2 0 5/; + +my @r = get_intersection(\@l1, \@l2); +is scalar(@r), 3, + "Got expected number of elements in intersection of two sets"; +is join(',', sort @r), '1,3,5'; +is join(' ', @l1), '3 1 4 1 5 9'; +is join(' ', @l2), '1 7 3 2 0 5'; + +my @l3 = qw/2 4 3 6 2 0 6 7 9/; + +@r = get_intersection(\@l1, \@l2, \@l3); +is scalar(@r), 1, + "Got expected number of elements in intersection of three sets"; +is $r[0], 3; +is join(' ', @l1), '3 1 4 1 5 9'; +is join(' ', @l2), '1 7 3 2 0 5'; +is join(' ', @l3), '2 4 3 6 2 0 6 7 9'; + +my @l4 = qw/1 4 1 4 2/; + +@r = get_intersection(\@l1, \@l2, \@l3, \@l4); +ok !@r, + "No elements in intersection of four sets"; + +@r = get_intersection([qw/1 3 5 7 9/], [qw/1 1 2 3 5 8 13/]); +is scalar(@r), 3, + "Got expected number of elements in intersection of three sets"; +is join(',', sort @r), '1,3,5'; + +@r = get_intersection([qw/there is more than one way to do it/], [qw/there is nothing to do/]); +is scalar(@r), 4, + "Got expected number of elements in intersection of four sets of strings"; +is join(',', sort @r), 'do,is,there,to'; + +@r = get_intersection([],[]); +ok !@r, "No elements in intersection of two empty arrayrefs"; + +@r = get_intersection([],[1]); +ok !@r, "No elements in intersection of two arrayrefs where one is empty"; + +@r = get_intersection(); +ok !@r, "No elements in intersection when no arguments are provided"; + +@r = get_intersection([qw/1 2 3 4 5/]); +is join(',', @r), '1,2,3,4,5', + "Intersection holds all elements when only one list is provided as argument"; + + diff --git a/t/02-options.t b/t/02-options.t index c90573d..b20f90d 100644 --- a/t/02-options.t +++ b/t/02-options.t @@ -1,14 +1,19 @@ -use strict; - -use Test::More tests => 4; - -use Set::Intersection; - -my @r = get_intersection([1 .. 9], [map { $_ * 2 } 1 .. 3], [map { $_ * 3 } 1 .. 3]); -is scalar(@r), 1; -is $r[0], 6; - -@r = get_intersection({-preordered=>1}, [1 .. 9], [map { $_ * 2 } 1 .. 3], [map { $_ * 3 } 1 .. 3]); -is scalar(@r), 1; -is $r[0], 6; - +use strict; + +use Test::More tests => 4; + +use Set::Intersection; + +my @r = get_intersection([1 .. 9], [map { $_ * 2 } 1 .. 3], [map { $_ * 3 } 1 .. 3]); +is scalar(@r), 1, + "Got expected number of elements in intersection of three sets"; +is $r[0], 6, + "Got expected element in intersection of three sets"; + +@r = get_intersection({-preordered=>1}, [1 .. 9], [map { $_ * 2 } 1 .. 3], [map { $_ * 3 } 1 .. 3]); +is scalar(@r), 1, + "Use of -preordered option did not affect number of elements in intersection"; +is $r[0], 6, + "Use of -preordered option did not affect content of intersection"; + + diff --git a/t/10-errors.t b/t/10-errors.t index 7f6de67..7f399bf 100644 --- a/t/10-errors.t +++ b/t/10-errors.t @@ -15,6 +15,6 @@ like($warn, qr/Use of uninitialized value in list assignment/s, "Got expected warning of 'undef' in arrays provided as arguments" ); -ok !$@; +ok !$@, "No error"; -- 1.9.1
JKEENAN, Thank you for the patches. And sorry for my late reply. I accepted your patches and released Set::Intesection 0.04. (I also released 0.03 without patch #2, by mistake :( Thank you very much. turugina On 2015-02-06T20:13:48-05:00, JKEENAN wrote: Show quoted text
> While using search.cpan.org to locate distributions concerning > "Intersection", I came across Set-Intersection (and was flattered to > see that you reference my List-Compare). > > I'm attaching two patches which make no changes in the source code but > which (a) improve the English-language style of some of the > documentation; and (b) provide descriptions for most of the individual > tests in t/*.t. > > If you're a github.com user, you could pick up from: > https://github.com/jkeenan/set-intersection > > I hope you find that useful. > > Thank you very much. > Jim Keenan > (CPAN ID: JKEENAN)